Skip to content

Commit

Permalink
feat: Scope import names (Go)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Dec 18, 2023
1 parent cda850d commit 9b76ce6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/scoping/langs/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum PremadeGoQuery {
Comments,
/// Strings (interpreted and raw; excluding struct tags).
Strings,
/// Imports.
Imports,
/// Struct tags.
StructTags,
}
Expand All @@ -43,6 +45,9 @@ impl From<PremadeGoQuery> for TSQuery {
@string"
)
}
PremadeGoQuery::Imports => {
r"(import_spec path: (interpreted_string_literal) @path)"
}
PremadeGoQuery::StructTags => "(field_declaration tag: (raw_string_literal) @tag)",
},
)
Expand Down
11 changes: 11 additions & 0 deletions tests/langs/go/in/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "fm__T__t"
import (
"__T__fmt"
"mat__T__h"
)
import (
f "fmt__T__"
m "math"
)
import _ "some/__T__package"
import "github__T__.com/user/project/subpackage"
1 change: 1 addition & 0 deletions tests/langs/go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{get_input_output, nuke_target};
#[rstest]
#[case("comments.go", GoQuery::Premade(PremadeGoQuery::Comments))]
#[case("strings.go", GoQuery::Premade(PremadeGoQuery::Strings))]
#[case("imports.go", GoQuery::Premade(PremadeGoQuery::Imports))]
#[case("struct-tags.go", GoQuery::Premade(PremadeGoQuery::StructTags))]
fn test_go_nuke(#[case] file: &str, #[case] query: GoQuery) {
let lang = Go::new(query);
Expand Down
11 changes: 11 additions & 0 deletions tests/langs/go/out/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "fmt"
import (
"fmt"
"math"
)
import (
f "fmt"
m "math"
)
import _ "some/package"
import "github.com/user/project/subpackage"

0 comments on commit 9b76ce6

Please sign in to comment.