feat(highlight): migrate to tree-house with Helix queries
Replace tree-sitter-highlight dep with tree-house crate from Helix editor. Add ropey dependency required by tree-house. Reorganize query files from Helix's runtime/queries/ for all 14 supported languages: - bash, c, css, go, html, javascript, json, markdown, nix, python, rust, toml, typescript, yaml - Include ecma, _javascript, _typescript base dirs for JS/TS inheritance - Copy highlights.scm, injections.scm, locals.scm where available This commit establishes the foundation; highlight.rs implementation will follow in subsequent commits.
This commit is contained in:
236
queries/go/highlights.scm
Normal file
236
queries/go/highlights.scm
Normal file
@@ -0,0 +1,236 @@
|
||||
|
||||
; Identifiers
|
||||
|
||||
(field_identifier) @variable.other.member
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
(package_identifier) @namespace
|
||||
|
||||
(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)
|
||||
|
||||
(parameter_declaration (identifier) @variable.parameter)
|
||||
(variadic_parameter_declaration (identifier) @variable.parameter)
|
||||
|
||||
(label_name) @label
|
||||
|
||||
(const_spec
|
||||
name: (identifier) @constant)
|
||||
|
||||
; Function calls
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
|
||||
(call_expression
|
||||
function: (selector_expression
|
||||
field: (field_identifier) @function.method))
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function.builtin
|
||||
(#match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover|min|max|clear)$"))
|
||||
|
||||
; Types
|
||||
|
||||
(type_identifier) @type
|
||||
|
||||
(type_parameter_list
|
||||
(type_parameter_declaration
|
||||
name: (identifier) @type.parameter))
|
||||
|
||||
((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)$"))
|
||||
|
||||
; Function definitions
|
||||
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
|
||||
(method_declaration
|
||||
name: (field_identifier) @function.method)
|
||||
|
||||
(method_elem
|
||||
name: (field_identifier) @function.method)
|
||||
|
||||
; Operators
|
||||
|
||||
[
|
||||
"--"
|
||||
"-"
|
||||
"-="
|
||||
":="
|
||||
"!"
|
||||
"!="
|
||||
"..."
|
||||
"*"
|
||||
"*"
|
||||
"*="
|
||||
"/"
|
||||
"/="
|
||||
"&"
|
||||
"&&"
|
||||
"&="
|
||||
"%"
|
||||
"%="
|
||||
"^"
|
||||
"^="
|
||||
"+"
|
||||
"++"
|
||||
"+="
|
||||
"<-"
|
||||
"<"
|
||||
"<<"
|
||||
"<<="
|
||||
"<="
|
||||
"="
|
||||
"=="
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
"|"
|
||||
"|="
|
||||
"||"
|
||||
"&^"
|
||||
"&^="
|
||||
"~"
|
||||
] @operator
|
||||
|
||||
; Keywords
|
||||
|
||||
[
|
||||
"default"
|
||||
"type"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"defer"
|
||||
"go"
|
||||
"goto"
|
||||
] @keyword.control
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
"select"
|
||||
"case"
|
||||
] @keyword.control.conditional
|
||||
|
||||
[
|
||||
"for"
|
||||
"range"
|
||||
] @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
|
||||
|
||||
; Delimiters
|
||||
|
||||
[
|
||||
":"
|
||||
"."
|
||||
","
|
||||
";"
|
||||
] @punctuation.delimiter
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
; Literals
|
||||
|
||||
[
|
||||
(interpreted_string_literal)
|
||||
(raw_string_literal)
|
||||
] @string
|
||||
|
||||
(rune_literal) @constant.character
|
||||
|
||||
(escape_sequence) @constant.character.escape
|
||||
|
||||
[
|
||||
(int_literal)
|
||||
] @constant.numeric.integer
|
||||
|
||||
[
|
||||
(float_literal)
|
||||
(imaginary_literal)
|
||||
] @constant.numeric.float
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
] @constant.builtin.boolean
|
||||
|
||||
[
|
||||
(nil)
|
||||
(iota)
|
||||
] @constant.builtin
|
||||
|
||||
; Comments
|
||||
|
||||
(comment) @comment
|
||||
|
||||
; Doc Comments
|
||||
(source_file
|
||||
.
|
||||
(comment)+ @comment.block.documentation)
|
||||
|
||||
(source_file
|
||||
(comment)+ @comment.block.documentation
|
||||
.
|
||||
(const_declaration))
|
||||
|
||||
(source_file
|
||||
(comment)+ @comment.block.documentation
|
||||
.
|
||||
(function_declaration))
|
||||
|
||||
(source_file
|
||||
(comment)+ @comment.block.documentation
|
||||
.
|
||||
(type_declaration))
|
||||
|
||||
(source_file
|
||||
(comment)+ @comment.block.documentation
|
||||
.
|
||||
(var_declaration))
|
||||
92
queries/go/injections.scm
Normal file
92
queries/go/injections.scm
Normal file
@@ -0,0 +1,92 @@
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; Inject markdown into documentation comments
|
||||
;
|
||||
; Go's comments are documentation comments when they are directly followed
|
||||
; by one of Go's statements (e.g. `type`, `func`, `const`)
|
||||
;
|
||||
; This is only a partial implementation, which covers only
|
||||
; block comments. For line comments (which are more common),
|
||||
; upstream changes to the grammar are required.
|
||||
(
|
||||
(comment) @injection.content . (comment)* . [
|
||||
(package_clause) ; `package`
|
||||
(type_declaration) ; `type`
|
||||
(function_declaration) ; `func`
|
||||
(method_declaration) ; `func`
|
||||
(var_declaration) ; `var`
|
||||
(const_declaration) ; `const`
|
||||
; var (
|
||||
; A = 1
|
||||
; B = 2
|
||||
; )
|
||||
(const_spec)
|
||||
; const (
|
||||
; A = 1
|
||||
; B = 2
|
||||
; )
|
||||
(var_spec)
|
||||
]
|
||||
(#set! injection.language "markdown"))
|
||||
|
||||
((comment) @injection.content
|
||||
(#match? @injection.content "^//go:generate")
|
||||
(#set! injection.language "bash"))
|
||||
|
||||
(call_expression
|
||||
(selector_expression) @_function
|
||||
(#any-of? @_function "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" "regexp.MustCompile" "regexp.MustCompilePOSIX")
|
||||
(argument_list
|
||||
.
|
||||
[
|
||||
(raw_string_literal)
|
||||
(interpreted_string_literal)
|
||||
] @injection.content
|
||||
(#set! injection.language "regex")))
|
||||
|
||||
; https://pkg.go.dev/fmt#Printf
|
||||
; https://pkg.go.dev/fmt#Sprintf
|
||||
; https://pkg.go.dev/fmt#Scanf
|
||||
; https://pkg.go.dev/fmt#Errorf
|
||||
((call_expression
|
||||
function: (selector_expression
|
||||
operand: (identifier) @_module
|
||||
field: (field_identifier) @_func)
|
||||
arguments: (argument_list
|
||||
. (interpreted_string_literal) @injection.content))
|
||||
(#eq? @_module "fmt")
|
||||
(#any-of? @_func "Printf" "Sprintf" "Scanf" "Errorf")
|
||||
(#set! injection.language "go-format-string"))
|
||||
|
||||
; https://pkg.go.dev/fmt#Fprintf
|
||||
; https://pkg.go.dev/fmt#Fscanf
|
||||
; https://pkg.go.dev/fmt#Sscanf
|
||||
((call_expression
|
||||
function: (selector_expression
|
||||
operand: (identifier) @_module
|
||||
field: (field_identifier) @_func)
|
||||
arguments: (argument_list
|
||||
; [(identifier) (interpreted_string_literal)]
|
||||
(_)
|
||||
; (identifier)
|
||||
.
|
||||
(interpreted_string_literal) @injection.content))
|
||||
(#eq? @_module "fmt")
|
||||
(#any-of? @_func "Fprintf" "Fscanf" "Sscanf")
|
||||
(#set! injection.language "go-format-string"))
|
||||
|
||||
; https://pkg.go.dev/log#Printf
|
||||
; https://pkg.go.dev/log#Fatalf
|
||||
; https://pkg.go.dev/log#Panicf
|
||||
; https://pkg.go.dev/log#Logger.Printf
|
||||
; https://pkg.go.dev/log#Logger.Fatalf
|
||||
; https://pkg.go.dev/log#Logger.Panicf
|
||||
((call_expression
|
||||
function: (selector_expression
|
||||
operand: (identifier)
|
||||
field: (field_identifier) @_func)
|
||||
arguments: (argument_list
|
||||
. (interpreted_string_literal) @injection.content))
|
||||
(#any-of? @_func "Printf" "Fatalf" "Panicf")
|
||||
(#set! injection.language "go-format-string"))
|
||||
25
queries/go/locals.scm
Normal file
25
queries/go/locals.scm
Normal file
@@ -0,0 +1,25 @@
|
||||
; Scopes
|
||||
|
||||
[
|
||||
(function_declaration)
|
||||
(method_declaration)
|
||||
(type_declaration)
|
||||
(block)
|
||||
] @local.scope
|
||||
|
||||
; Definitions
|
||||
|
||||
(parameter_declaration (identifier) @local.definition.variable.parameter)
|
||||
(variadic_parameter_declaration (identifier) @local.definition.variable.parameter)
|
||||
|
||||
(const_declaration
|
||||
(const_spec
|
||||
name: (identifier) @local.definition.constant))
|
||||
|
||||
; References
|
||||
|
||||
(identifier) @local.reference
|
||||
|
||||
; Field names in struct literals are identifier rather than field_identifier,
|
||||
; these cannot be locals.
|
||||
(keyed_element . (literal_element (identifier) @variable.other.member))
|
||||
Reference in New Issue
Block a user