diff options
| -rw-r--r-- | CONTRIBUTING.md | 2 | ||||
| -rw-r--r-- | doc/nvim-treesitter.txt | 6 | ||||
| -rw-r--r-- | lua/nvim-treesitter/highlight.lua | 1 | ||||
| -rw-r--r-- | plugin/nvim-treesitter.vim | 2 | ||||
| -rw-r--r-- | queries/cpp/highlights.scm | 4 | ||||
| -rw-r--r-- | queries/javascript/highlights.scm | 5 | ||||
| -rw-r--r-- | queries/ocaml/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/rust/highlights.scm | 36 |
8 files changed, 46 insertions, 12 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b0949fa99..9006308db 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -140,7 +140,7 @@ are optional and will not have any effect for now. @type @type.builtin -@structure +@namespace for identifiers referring to namespaces @attribute for e.g. Python decorators ``` diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 3d7fc04cb..1bf5ef310 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -570,9 +570,9 @@ For types. *hl-TSTypeBuiltin* For builtin types (you guessed it, right ?). -`TSStructure` - *hl-TSStructure* -This is left as an exercise for the reader. +`TSNamespace` + *hl-TSNamespace* +For identifiers referring to modules and namespaces. `TSInclude` *hl-TSInclude* diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua index 4dde5a8c1..22e50bd54 100644 --- a/lua/nvim-treesitter/highlight.lua +++ b/lua/nvim-treesitter/highlight.lua @@ -30,6 +30,7 @@ hlmap["boolean"] = "TSBoolean" hlmap["float"] = "TSFloat" hlmap["annotation"] = "TSAnnotation" hlmap["attribute"] = "TSAttribute" +hlmap["namespace"] = "TSNamespace" -- Functions hlmap["function"] = "TSFunction" diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim index 4ac0ca9d1..4eae5627d 100644 --- a/plugin/nvim-treesitter.vim +++ b/plugin/nvim-treesitter.vim @@ -41,6 +41,7 @@ highlight default link TSProperty Identifier highlight default link TSConstructor Special highlight default link TSAnnotation PreProc highlight default link TSAttribute PreProc +highlight default link TSNamespace Include highlight default link TSConditional Conditional highlight default link TSRepeat Repeat @@ -53,7 +54,6 @@ highlight default link TSException Exception highlight default link TSType Type highlight default link TSTypeBuiltin Type -highlight default link TSStructure Structure highlight default link TSInclude Include highlight default link TSVariable TSNone diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index c026d54bf..30c4b75d2 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -28,14 +28,16 @@ name: (scoped_identifier name: (identifier) @function)) -(namespace_identifier) @constant ((identifier) @type (#match? @type "^[A-Z]")) +(namespace_identifier) @namespace ((namespace_identifier) @type (#match? @type "^[A-Z]")) ((namespace_identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) +(namespace_definition + name: (identifier) @namespace) (destructor_name name: (_) @function) diff --git a/queries/javascript/highlights.scm b/queries/javascript/highlights.scm index d83228c37..de505366a 100644 --- a/queries/javascript/highlights.scm +++ b/queries/javascript/highlights.scm @@ -90,6 +90,11 @@ (rest_parameter (identifier) @parameter)) +; Variables +;---------- +(namespace_import + (identifier) @namespace) + ; Literals ;--------- diff --git a/queries/ocaml/highlights.scm b/queries/ocaml/highlights.scm index 4e44c6dc1..3d43aabf6 100644 --- a/queries/ocaml/highlights.scm +++ b/queries/ocaml/highlights.scm @@ -1,7 +1,7 @@ ; Modules ;-------- -[(module_name) (module_type_name)] @structure +[(module_name) (module_type_name)] @namespace ; Types ;------ diff --git a/queries/rust/highlights.scm b/queries/rust/highlights.scm index 01994555f..fa81ffbc7 100644 --- a/queries/rust/highlights.scm +++ b/queries/rust/highlights.scm @@ -13,12 +13,16 @@ (type_identifier) @type (primitive_type) @type.builtin (field_identifier) @field - +(mod_item + name: (identifier) @namespace) ; Function calls (call_expression function: (identifier) @function) (call_expression + function: (scoped_identifier + (identifier) @function .)) +(call_expression function: (field_expression field: (field_identifier) @function)) @@ -36,6 +40,16 @@ (#match? @constant "^[A-Z]")) ; Assume that uppercase names in paths are types +(scoped_identifier + path: (identifier) @namespace) +(scoped_identifier + (scoped_identifier + name: (identifier) @namespace)) +(scoped_type_identifier + path: (identifier) @namespace) +(scoped_type_identifier + (scoped_identifier + name: (identifier) @namespace)) ((scoped_identifier path: (identifier) @type) (#match? @type "^[A-Z]")) @@ -43,6 +57,13 @@ name: (identifier) @type) (#match? @type "^[A-Z]")) +(crate) @namespace +(scoped_use_list + path: (identifier) @namespace) +(scoped_use_list + path: (scoped_identifier + (identifier) @namespace)) +(use_list (scoped_identifier (identifier) @namespace . (_))) (use_list (identifier) @type (#match? @type "^[A-Z]")) (use_as_clause alias: (identifier) @type (#match? @type "^[A-Z]")) @@ -60,8 +81,10 @@ (#eq? @type "derive")) (macro_invocation - macro: (identifier) @function.macro - "!" @function.macro) + macro: (identifier) @function.macro) +(macro_invocation + macro: (scoped_identifier + (identifier) @function.macro .)) ; Function definitions @@ -100,6 +123,11 @@ (self) @variable.builtin [ + "use" + "mod" +] @include + +[ "break" "const" "default" @@ -111,7 +139,6 @@ "let" "macro_rules!" "match" -"mod" "move" "pub" "ref" @@ -124,7 +151,6 @@ "unsafe" "async" "await" -"use" "where" (mutable_specifier) (super) |
