Skip to content

Commit

Permalink
feat(go): Scope select blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 16, 2024
1 parent 76a91b8 commit ddbf9d9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ Language scopes:
- free-func: Free `func` definitions (`func SomeFunc()`)
- type-params: Type parameters (generics)
- defer: `defer` blocks
- select: `select` blocks
- 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 @@ -45,6 +45,8 @@ pub enum PreparedGoQuery {
TypeParams,
/// `defer` blocks.
Defer,
/// `select` blocks.
Select,
/// Struct tags.
StructTags,
}
Expand Down Expand Up @@ -93,6 +95,7 @@ impl From<PreparedGoQuery> for TSQuery {
PreparedGoQuery::FreeFunc => "(function_declaration) @free_func",
PreparedGoQuery::TypeParams => "(type_parameter_declaration) @type_params",
PreparedGoQuery::Defer => "(defer_statement) @defer",
PreparedGoQuery::Select => "(select_statement) @select",
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 @@ -517,6 +517,11 @@ impl InScopeLinePart {
include_str!("go/base.go"),
Go::new(CodeQuery::Prepared(PreparedGoQuery::Defer)),
)]
#[case(
"base.go_select",
include_str!("go/base.go"),
Go::new(CodeQuery::Prepared(PreparedGoQuery::Select)),
)]
#[case(
"base.go_struct-tags",
include_str!("go/base.go"),
Expand Down
40 changes: 40 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.go_select.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 154
l: "\tselect {\n"
m: " ^^^^^^^^^^"
- n: 155
l: "\tcase tc := <-testChannel:\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 156
l: "\t\tt.Logf(\"Received test case: %s\", tc.Name)\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 157
l: "\tcase <-time.After(1 * time.Second):\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 158
l: "\t\tt.Error(\"Timeout waiting for test case\")\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 159
l: "\t}\n"
m: "^^^ "
- n: 237
l: "\tselect {\n"
m: " ^^^^^^^^^^"
- n: 238
l: "\tcase <-time.After(5 * time.Second):\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 239
l: "\t\treturn nil\n"
m: ^^^^^^^^^^^^^^^^
- n: 240
l: "\tcase <-ctx.Done():\n"
m: ^^^^^^^^^^^^^^^^^^^^^^
- n: 241
l: "\t\treturn ctx.Err()\n"
m: ^^^^^^^^^^^^^^^^^^^^^^
- n: 242
l: "\t}\n"
m: "^^^ "

0 comments on commit ddbf9d9

Please sign in to comment.