Merge pull request #69 from theHamsta/go-highlights

Go highlights
This commit is contained in:
Thomas Vigouroux 2020-06-07 13:58:38 +02:00 committed by GitHub
commit 85645f5720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 204 additions and 1 deletions

View file

@ -94,6 +94,13 @@ are optional and will not have any effect for now.
`macro`
`type`
`field`
`doc` for documentation adjecent to a definition. E.g.
```scheme
(comment)* @definition.doc
(method_declaration
name: (field_identifier) @definition.method)
```
`@scope`

View file

@ -155,7 +155,7 @@ List of currently supported languages:
- [x] lua (maintained by @vigoux)
- [x] ruby (maintained by @TravonteD)
- [x] c (maintained by @vigoux)
- [ ] go
- [x] go (maintained by @theHamsta)
- [ ] cpp
- [ ] rust
- [x] python (maintained by @theHamsta)

136
queries/go/highlights.scm Normal file
View file

@ -0,0 +1,136 @@
;; Forked from tree-sitter-go
;; Copyright (c) 2014 Max Brunsfeld (The MIT License)
;;
; Function calls
(call_expression
function: (identifier) @function)
(call_expression
function: (selector_expression
field: (field_identifier) @method))
; Function definitions
(function_declaration
name: (identifier) @function)
(method_declaration
name: (field_identifier) @method)
; Identifiers
(type_identifier) @type
(field_identifier) @property
(identifier) @variable
(parameter_declaration (identifier) @parameter)
(variadic_parameter_declaration (identifier) @parameter)
((identifier) @constant
(#eq? @constant "_"))
((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]+$"))
; Operators
"--" @operator
"-" @operator
"-=" @operator
":=" @operator
"!" @operator
"!=" @operator
"..." @operator
"*" @operator
"*" @operator
"*=" @operator
"/" @operator
"/=" @operator
"&" @operator
"&&" @operator
"&=" @operator
"%" @operator
"%=" @operator
"^" @operator
"^=" @operator
"+" @operator
"++" @operator
"+=" @operator
"<-" @operator
"<" @operator
"<<" @operator
"<<=" @operator
"<=" @operator
"=" @operator
"==" @operator
">" @operator
">=" @operator
">>" @operator
">>=" @operator
"|" @operator
"|=" @operator
"||" @operator
; Keywords
"break" @keyword
"case" @conditional
"chan" @keyword
"const" @keyword
"continue" @keyword
"default" @keyword
"defer" @keyword
"else" @conditional
"fallthrough" @keyword
"for" @repeat
"func" @keyword
"go" @keyword
"goto" @keyword
"if" @conditional
"import" @include
"interface" @keyword
"map" @keyword
"package" @include
"range" @keyword
"return" @keyword
"select" @keyword
"struct" @keyword
"switch" @conditional
"type" @keyword
"var" @keyword
; Delimiters
"." @punctuation.delimiter
"," @punctuation.delimiter
":" @punctuation.delimiter
";" @punctuation.delimiter
"(" @punctuation.bracket
")" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
; Literals
(interpreted_string_literal) @string
(raw_string_literal) @string
(rune_literal) @string
(escape_sequence) @escape
(int_literal) @number
(float_literal) @float
(imaginary_literal) @number
(true) @boolean
(false) @boolean
(nil) @constant.builtin
(comment) @comment
(ERROR) @error

60
queries/go/locals.scm Normal file
View file

@ -0,0 +1,60 @@
(
(comment)* @definition.doc
(function_declaration
name: (identifier) @definition.function) ;@function
(#strip! @definition.doc "^//\\s*") ; <- does nothing at the moment
)
(
(comment)* @definition.doc
(method_declaration
name: (field_identifier) @definition.method); @method
(#strip! @definition.doc "^//\\s*") ; <- does nothing at the moment
)
(short_var_declaration
left: (expression_list
(identifier) @definition.var))
(var_spec
name: (identifier) @definition.var)
(parameter_declaration (identifier) @definition.var)
(variadic_parameter_declaration (identifier) @definition.var)
(type_declaration
(type_spec
name: (type_identifier) @definition.type))
;; reference
(identifier) @reference
(type_identifier) @reference
(field_identifier) @reference
;; Call references
(call_expression
function: (identifier) @reference.call) @call
(call_expression
function: (selector_expression
field: (field_identifier) @reference.call)) @call
(call_expression
function: (parenthesized_expression
(identifier) @reference.call)) @call
(call_expression
function: (parenthesized_expression
(selector_expression
field: (field_identifier) @reference.call))) @call
;; Scopes
(source_file) @scope
(function_declaration) @scope
(if_statement) @scope
(block) @scope
(expression_switch_statement) @scope
(for_statement) @scope
(method_declaration) @scope