Skip to content

Commit

Permalink
feat(go): Scope goto statements
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 16, 2024
1 parent 308e28f commit 4133575
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ Language scopes:
- go: `go` blocks
- switch: `switch` blocks
- labeled: Labeled statements
- goto: `goto` statements
- struct-tags: Struct tags

--go-query <TREE-SITTER-QUERY>
Expand Down
3 changes: 3 additions & 0 deletions src/scoping/langs/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub enum PreparedGoQuery {
Switch,
/// Labeled statements.
Labeled,
/// `goto` statements.
Goto,
/// Struct tags.
StructTags,
}
Expand Down Expand Up @@ -105,6 +107,7 @@ impl From<PreparedGoQuery> for TSQuery {
PreparedGoQuery::Go => "(go_statement) @go",
PreparedGoQuery::Switch => "(expression_switch_statement) @switch",
PreparedGoQuery::Labeled => "(labeled_statement) @labeled",
PreparedGoQuery::Goto => "(goto_statement) @goto",
PreparedGoQuery::StructTags => "(field_declaration tag: (raw_string_literal) @tag)",
},
)
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ impl InScopeLinePart {
include_str!("go/base.go"),
Go::new(CodeQuery::Prepared(PreparedGoQuery::Labeled)),
)]
#[case(
"base.go_goto",
include_str!("go/base.go"),
Go::new(CodeQuery::Prepared(PreparedGoQuery::Goto)),
)]
#[case(
"base.go_struct-tags",
include_str!("go/base.go"),
Expand Down
7 changes: 7 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.go_goto.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 292
l: "\t\tgoto Loop\n"
m: " ^^^^^^^^^ "

0 comments on commit 4133575

Please sign in to comment.