diff options
| -rw-r--r-- | lockfile.json | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 4 | ||||
| -rw-r--r-- | queries/v/highlights.scm | 368 | ||||
| -rw-r--r-- | queries/v/indents.scm | 3 | ||||
| -rw-r--r-- | queries/v/injections.scm | 6 | ||||
| -rw-r--r-- | queries/v/locals.scm | 19 |
6 files changed, 227 insertions, 175 deletions
diff --git a/lockfile.json b/lockfile.json index 29b5c4312..12a8d0823 100644 --- a/lockfile.json +++ b/lockfile.json @@ -543,7 +543,7 @@ "revision": "14e47600afef0affffcbfbe1543381b1ac8fbc5c" }, "v": { - "revision": "f1b3a99285a58c6f5fe8add47877cde664b75a60" + "revision": "e14fdf6e661b10edccc744102e4ccf0b187aa8ad" }, "vala": { "revision": "8f690bfa639f2b83d1fb938ed3dd98a7ba453e8b" diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 5e3c1efa3..4b5fbbd3b 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1600,12 +1600,12 @@ list.uxntal = { list.v = { install_info = { - url = "https://github.com/vlang/vls", + url = "https://github.com/v-analyzer/v-analyzer", files = { "src/parser.c", "src/scanner.c" }, location = "tree_sitter_v", }, filetype = "vlang", - maintainers = { "@kkharji" }, + maintainers = { "@kkharji", "@amaanq" }, } list.vala = { diff --git a/queries/v/highlights.scm b/queries/v/highlights.scm index 379b525e8..0fb3074fa 100644 --- a/queries/v/highlights.scm +++ b/queries/v/highlights.scm @@ -1,196 +1,174 @@ -;; reference https://github.com/vlang/vls -;; rev: c3e9874fa6c3b38beaa50d53aff4967403e251a4 +; Includes -;; Identifiers ------------------- -(import_path) @namespace -(module_identifier) @variable.builtin -(identifier) @variable -(interpreted_string_literal) @string -(string_interpolation) @none +[ + "import" + "module" +] @include -; TODO: Have different highlight to make then standout + highlight }{$ as special -; ((string_interpolation -; (identifier) @constant -; "$" @punctuation.special -; "${" @punctuation.special -; "}" @punctuation.special)) +; Keywords -[(type_identifier) (array_type) (pointer_type)] @type +[ + "asm" + "assert" + "const" + "defer" + "enum" + "goto" + "interface" + "struct" + "sql" + "type" + "union" + "unsafe" +] @keyword -(field_identifier) @property +[ + "as" + "in" + "!in" + "or" + "is" + "!is" +] @keyword.operator -(builtin_type) @type.builtin +[ + "match" + "if" + "$if" + "else" + "$else" + "select" +] @conditional -(parameter_declaration - name: (identifier) @parameter) +[ + "for" + "$for" + "continue" + "break" +] @repeat -(const_spec - name: (identifier) @constant) +"fn" @keyword.function -((((selector_expression field: (identifier) @property)) @_parent - (#not-has-parent? @_parent call_expression special_call_expression))) +"return" @keyword.return -((identifier) @variable.builtin - (#any-of? @variable.builtin "err" "macos" "linux" "windows")) +[ + "__global" + "shared" + "static" + "const" +] @storageclass -(attribute_declaration) @attribute -;; C: TODO: fixme make `C`.exten highlighted as variable.builtin -; ((binded_identifier) @content -; (#offset! @content 0 3 0 -1) -; (#match? @content "^C$")) +[ + "pub" + "mut" +] @type.qualifier -;; Function calls ---------------- -(call_expression - function: (identifier) @function.call) +[ + "go" + "spawn" + "lock" + "rlock" +] @keyword.coroutine -(((_ - function: (selector_expression field: (identifier) @function.call) - arguments: (_) @_args) - (#not-has-type? @_args arguments_list))) +; Variables -((call_expression - function: (binded_identifier name: (identifier) @function) - @function.call)) +(identifier) @variable +; Namespace -;; Function definitions --------- -(function_declaration - name: (identifier) @function) +(module_clause + (identifier) @namespace) -(function_declaration - receiver: (parameter_list) - name: (identifier) @method) +(import_path + (import_name) @namespace) -((function_declaration - (binded_identifier name: (identifier) @function) - @function)) +(import_alias + (import_name) @namespace) -;; Keywords +; Literals -[ - "import" - "module" -] @include +[ (true) (false) ] @boolean -[ - "match" - "if" - "$if" - "else" - "$else" -] @conditional +(interpreted_string_literal) @string -[ - "for" @repeat - "$for" -] @repeat +(string_interpolation) @none -[ - "as" - "in" - "!in" - "or" - "is" - "!is" -] @keyword.operator +; Types -[ - "asm" - "assert" - "const" - "defer" - "enum" - "go" - "goto" - "interface" - "lock" - "mut" - "pub" - "rlock" - "struct" - "type" - "unsafe" -] - ;; Either not supported or will be dropped - ;"atomic" - ;"break" - ; "continue" - ;"shared" - ;"static" - ;"union" -@keyword +(struct_declaration + name: (identifier) @type) -"fn" @keyword.function -"return" @keyword.return +(enum_declaration + name: (identifier) @type) -; "import" @include ;; note: comment out b/c of import_path @namespace +(interface_declaration + name: (identifier) @type) -[ (true) (false) ] @boolean +(type_declaration + name: (identifier) @type) +(type_reference_expression (identifier) @type) +; Labels -;; Conditionals ---------------- -[ "else" "if"] @conditional +(label_reference) @label -;; Operators ---------------- -[ "." "," ":" ";"] @punctuation.delimiter +; Fields -[ "(" ")" "{" "}" "[" "]"] @punctuation.bracket +(selector_expression field: (reference_expression (identifier) @field)) -(array) @punctuation.bracket +(field_name) @field -[ - "++" - "--" +(struct_field_declaration + name: (identifier) @field) + +; Parameters + +(parameter_declaration + name: (identifier) @parameter) + +(receiver + name: (identifier) @parameter) - "+" - "-" - "*" - "/" - "%" +; Constants - "~" - "&" - "|" - "^" +((identifier) @constant + (#has-ancestor? @constant compile_time_if_expression)) - "!" - "&&" - "||" - "!=" +(enum_fetch + (reference_expression) @constant) - "<<" - ">>" +(enum_field_definition + (identifier) @constant) - "<" - ">" - "<=" - ">=" +(const_definition + name: (identifier) @constant) - "+=" - "-=" - "*=" - "/=" - "&=" - "|=" - "^=" - "<<=" - ">>=" +((identifier) @variable.builtin + (#any-of? @variable.builtin "err" "macos" "linux" "windows")) - "=" - ":=" - "==" +; Attributes - "?" - "<-" - "$" - ".." - "..."] -@operator +(attribute) @attribute + +; Functions + +(function_declaration + name: (identifier) @function) + +(function_declaration + receiver: (receiver) + name: (identifier) @method) + +(call_expression + name: (selector_expression + field: (reference_expression) @method.call)) + +(call_expression + name: (reference_expression) @function.call) -;; Builtin Functions, maybe redundant with (builtin_type) ((identifier) @function.builtin - (#any-of? @function.builtin + (#any-of? @function.builtin "eprint" "eprintln" "error" @@ -389,25 +367,101 @@ "vstrlen_char" "winapi_lasterr_str")) +; Operators + +[ + "++" + "--" + + "+" + "-" + "*" + "/" + "%" + + "~" + "&" + "|" + "^" + + "!" + "&&" + "||" + "!=" + + "<<" + ">>" + + "<" + ">" + "<=" + ">=" + + "+=" + "-=" + "*=" + "/=" + "&=" + "|=" + "^=" + "<<=" + ">>=" + + "=" + ":=" + "==" + + "?" + "<-" + "$" + ".." + "..." +] @operator + +; Punctuation -;; Literals +[ "." "," ":" ";" ] @punctuation.delimiter + +[ "(" ")" "{" "}" "[" "]" ] @punctuation.bracket + +; Literals (int_literal) @number -(rune_literal) @string +(float_literal) @float + +[ + (c_string_literal) + (raw_string_literal) + (interpreted_string_literal) + (string_interpolation) + (rune_literal) +] @string -(raw_string_literal) @string +(string_interpolation + (braced_interpolation_opening) @punctuation.bracket + (interpolated_expression) @none + (braced_interpolation_closing) @punctuation.bracket) (escape_sequence) @string.escape -(float_literal) @float +[ + (true) + (false) +] @boolean -[(true) (false)] @boolean +(nil) @constant.builtin -(ERROR) @error +(none) @variable.builtin + +; Comments (comment) @comment @spell (_ (comment)+ @comment.documentation - [(function_declaration) (type_declaration) (const_spec) (enum_declaration)]) + [(function_declaration) (type_declaration) (enum_declaration)]) + +; Errors + +(ERROR) @error diff --git a/queries/v/indents.scm b/queries/v/indents.scm index afcf6d8c6..a806b35ed 100644 --- a/queries/v/indents.scm +++ b/queries/v/indents.scm @@ -1,10 +1,9 @@ [(import_declaration) (const_declaration) (type_declaration) - (literal_value) (type_initializer) (block) - (map) + (map_init_expression) (call_expression) (parameter_list)] @indent.begin diff --git a/queries/v/injections.scm b/queries/v/injections.scm index 11f02639e..b39a5ef44 100644 --- a/queries/v/injections.scm +++ b/queries/v/injections.scm @@ -6,8 +6,8 @@ ;; regex for the methods defined in `re` module ((call_expression - function: (selector_expression - field: (identifier) @_re) + name: (selector_expression + field: (reference_expression (identifier) @_re)) arguments: (argument_list - (raw_string_literal) @regex (#offset! @regex 0 2 0 -1))) + (argument (literal (raw_string_literal) @regex (#offset! @regex 0 2 0 -1))))) (#any-of? @_re "regex_base" "regex_opt" "compile_opt")) diff --git a/queries/v/locals.scm b/queries/v/locals.scm index 0d1b64c17..f0e08403a 100644 --- a/queries/v/locals.scm +++ b/queries/v/locals.scm @@ -1,25 +1,24 @@ ((function_declaration name: (identifier) @definition.function)) ;@function -(short_var_declaration - left: (expression_list - (identifier) @definition.var)) +(var_declaration + var_list: (expression_list + (reference_expression + (identifier) @definition.var))) ((function_declaration - name: (binded_identifier - name: (identifier) @definition.function))) + name: (identifier) @definition.function)) -(const_declaration (const_spec (identifier) @definition.var)) +(const_declaration (const_definition name: (identifier) @definition.var)) (identifier) @reference -(type_identifier) @reference -((call_expression function: (identifier) @reference) +((call_expression name: (reference_expression (identifier)) @reference) (#set! reference.kind "call")) ((call_expression - function: (selector_expression - field: (identifier) @definition.function)) + name: (selector_expression + field: (reference_expression (identifier) @definition.function))) (#set! reference.kind "call")) (source_file) @scope |
