From 04040c61c7c0c6da77dd87426c68f0afb8344b97 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 31 May 2020 23:32:08 +0200 Subject: [PATCH 1/4] Add highlights.scm for Go --- README.md | 2 +- queries/go/highlights.scm | 136 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 queries/go/highlights.scm diff --git a/README.md b/README.md index 970eee60a..6379273ac 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/queries/go/highlights.scm b/queries/go/highlights.scm new file mode 100644 index 000000000..ed046e6d0 --- /dev/null +++ b/queries/go/highlights.scm @@ -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 From 452447694a0b8d76e08573ee74aceae8a9934cec Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 31 May 2020 23:50:04 +0200 Subject: [PATCH 2/4] Add go locals.scm --- queries/go/locals.scm | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 queries/go/locals.scm diff --git a/queries/go/locals.scm b/queries/go/locals.scm new file mode 100644 index 000000000..297474f8d --- /dev/null +++ b/queries/go/locals.scm @@ -0,0 +1,43 @@ +( + (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 + +;; Scopes + +(source_file) @scope +(function_declaration) @scope +(if_statement) @scope +(block) @scope +(expression_switch_statement) @scope +(for_statement) @scope +(method_declaration) @scope From 5a096cb3f110712426f171701fe7ff21d34dba84 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 31 May 2020 23:59:54 +0200 Subject: [PATCH 3/4] Add call references for Go --- queries/go/locals.scm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/queries/go/locals.scm b/queries/go/locals.scm index 297474f8d..f9d0af3b1 100644 --- a/queries/go/locals.scm +++ b/queries/go/locals.scm @@ -32,6 +32,23 @@ (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 From 8436f2b90b3dbd1a1fdb60f015a5d521880bf2ef Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 7 Jun 2020 12:38:57 +0200 Subject: [PATCH 4/4] Update CONTRIBUTING.md for @doc --- CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea31f573e..5a8c74ee6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`