diff --git a/languages.toml b/languages.toml index 75442307..26cd76fd 100644 --- a/languages.toml +++ b/languages.toml @@ -915,7 +915,7 @@ args = { mode = "core", program = "{0}", coreFilePath = "{1}" } [[grammar]] name = "go" -source = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "12fe553fdaaa7449f764bc876fd777704d4fb752" } +source = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "2346a3ab1bb3857b48b29d779a1ef9799a248cd7" } [[language]] name = "gomod" diff --git a/runtime/queries/go/highlights.scm b/runtime/queries/go/highlights.scm index 0be296cf..e2344bca 100644 --- a/runtime/queries/go/highlights.scm +++ b/runtime/queries/go/highlights.scm @@ -10,9 +10,6 @@ (const_spec name: (identifier) @constant) -(type_spec - name: (type_identifier) @constructor) - (keyed_element . (literal_element (identifier) @variable.other.member)) (field_declaration name: (field_identifier) @variable.other.member) @@ -49,6 +46,12 @@ ((type_identifier) @type.builtin (#match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$")) +; Type definition names: `type Foo struct{}`, `type Bar = Baz`. +(type_spec + name: (type_identifier) @type.definition) +(type_alias + name: (type_identifier) @type.definition) + ; Function definitions (function_declaration @@ -60,6 +63,13 @@ (method_elem name: (field_identifier) @function.method) +; Blank identifier `_` (Go's discard) — dim as unused. +; It parses as (blank_identifier) in imports and as (identifier) elsewhere +; (`_ = x`, `a, _ := f()`, `for _, v := range`). +(blank_identifier) @comment.unused +((identifier) @comment.unused + (#eq? @comment.unused "_")) + ; Operators [ diff --git a/runtime/queries/go/indents.scm b/runtime/queries/go/indents.scm index a6b962e2..ff8b5313 100644 --- a/runtime/queries/go/indents.scm +++ b/runtime/queries/go/indents.scm @@ -12,9 +12,12 @@ (type_case) (communication_case) (argument_list) + (parameter_list) (field_declaration_list) (block) (var_declaration) + (selector_expression) + (binary_expression) ] @indent [ @@ -44,3 +47,9 @@ (ERROR "{") @indent @extend (ERROR "(") @indent (ERROR "[") @indent + +; Labels (`Loop:`, `done:`) are de-indented one level by gofmt. +; Capturing the label_name (a child, not an ancestor of the labeled body) +; outdents only the label line. +(labeled_statement + (label_name) @outdent) diff --git a/runtime/queries/go/textobjects.scm b/runtime/queries/go/textobjects.scm index 06c412ee..9c70cc53 100644 --- a/runtime/queries/go/textobjects.scm +++ b/runtime/queries/go/textobjects.scm @@ -2,7 +2,7 @@ body: (block)? @function.inside) @function.around (func_literal - (_)? @function.inside) @function.around + body: (block)? @function.inside) @function.around (method_declaration body: (block)? @function.inside) @function.around @@ -27,7 +27,8 @@ (comment)+ @comment.around +; Go test/benchmark/example/fuzz functions (all live in _test.go). ((function_declaration name: (identifier) @_name body: (block)? @test.inside) @test.around - (#match? @_name "^Test")) + (#match? @_name "^(Test|Benchmark|Example|Fuzz)"))