Skip to content

Commit

Permalink
Update highlights for golang (helix-editor#6204)
Browse files Browse the repository at this point in the history
- update tree-sitter-go
- refine keywords
- set package as namespace
- add label
  • Loading branch information
erasin authored and Sagnik Bhattacharya committed Mar 21, 2023
1 parent 97a3267 commit a1f1c3b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ args = { mode = "local", processId = "{0}" }

[[grammar]]
name = "go"
source = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "05900faa3cdb5d2d8c8bd5e77ee698487e0a8611" }
source = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "64457ea6b73ef5422ed1687178d4545c3e91334a" }

[[language]]
name = "gomod"
Expand Down
75 changes: 54 additions & 21 deletions runtime/queries/go/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
(method_declaration
name: (field_identifier) @function.method)

(method_spec
name: (field_identifier) @function.method)

; Identifiers

((identifier) @constant (match? @constant "^[A-Z][A-Z\\d_]+$"))
Expand All @@ -32,10 +35,19 @@
(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_identifier) @type
(type_spec
name: (type_identifier) @constructor)
(field_identifier) @variable.other.member
(identifier) @variable
(package_identifier) @variable
(package_identifier) @namespace

(parameter_declaration (identifier) @variable.parameter)
(variadic_parameter_declaration (identifier) @variable.parameter)

(label_name) @label

(const_spec
name: (identifier) @constant)

; Operators

Expand Down Expand Up @@ -82,36 +94,57 @@
; Keywords

[
"break"
"case"
"chan"
"const"
"continue"
"default"
"defer"
"type"
] @keyword

[
"if"
"else"
"fallthrough"
"switch"
"select"
"case"
] @keyword.control.conditional

[
"for"
"func"
"go"
"goto"
"if"
"interface"
"map"
"range"
"return"
"select"
"struct"
"switch"
"type"
"var"
] @keyword
] @keyword.control.repeat

[
"import"
"package"
] @keyword.control.import

[
"return"
"continue"
"break"
"fallthrough"
] @keyword.control.return

[
"func"
] @keyword.function

[
"var"
"chan"
"interface"
"map"
"struct"
] @keyword.storage.type

[
"const"
] @keyword.storage.modifier

[
"defer"
"goto"
"go"
] @function.macro

; Delimiters

[
Expand Down

0 comments on commit a1f1c3b

Please sign in to comment.