mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
fix(highlights): Add TSNamespace highlight
Start adding highlights for
- C++
- Rust (including other scoped_identifier/scoped_type_identifier fixes)
- JS (only namespace_import)
Addresses #516
This commit is contained in:
parent
f5ac2b4a1a
commit
45397ebbd9
8 changed files with 46 additions and 12 deletions
|
|
@ -140,7 +140,7 @@ are optional and will not have any effect for now.
|
||||||
|
|
||||||
@type
|
@type
|
||||||
@type.builtin
|
@type.builtin
|
||||||
@structure
|
@namespace for identifiers referring to namespaces
|
||||||
@attribute for e.g. Python decorators
|
@attribute for e.g. Python decorators
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -570,9 +570,9 @@ For types.
|
||||||
*hl-TSTypeBuiltin*
|
*hl-TSTypeBuiltin*
|
||||||
For builtin types (you guessed it, right ?).
|
For builtin types (you guessed it, right ?).
|
||||||
|
|
||||||
`TSStructure`
|
`TSNamespace`
|
||||||
*hl-TSStructure*
|
*hl-TSNamespace*
|
||||||
This is left as an exercise for the reader.
|
For identifiers referring to modules and namespaces.
|
||||||
|
|
||||||
`TSInclude`
|
`TSInclude`
|
||||||
*hl-TSInclude*
|
*hl-TSInclude*
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ hlmap["boolean"] = "TSBoolean"
|
||||||
hlmap["float"] = "TSFloat"
|
hlmap["float"] = "TSFloat"
|
||||||
hlmap["annotation"] = "TSAnnotation"
|
hlmap["annotation"] = "TSAnnotation"
|
||||||
hlmap["attribute"] = "TSAttribute"
|
hlmap["attribute"] = "TSAttribute"
|
||||||
|
hlmap["namespace"] = "TSNamespace"
|
||||||
|
|
||||||
-- Functions
|
-- Functions
|
||||||
hlmap["function"] = "TSFunction"
|
hlmap["function"] = "TSFunction"
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ highlight default link TSProperty Identifier
|
||||||
highlight default link TSConstructor Special
|
highlight default link TSConstructor Special
|
||||||
highlight default link TSAnnotation PreProc
|
highlight default link TSAnnotation PreProc
|
||||||
highlight default link TSAttribute PreProc
|
highlight default link TSAttribute PreProc
|
||||||
|
highlight default link TSNamespace Include
|
||||||
|
|
||||||
highlight default link TSConditional Conditional
|
highlight default link TSConditional Conditional
|
||||||
highlight default link TSRepeat Repeat
|
highlight default link TSRepeat Repeat
|
||||||
|
|
@ -53,7 +54,6 @@ highlight default link TSException Exception
|
||||||
|
|
||||||
highlight default link TSType Type
|
highlight default link TSType Type
|
||||||
highlight default link TSTypeBuiltin Type
|
highlight default link TSTypeBuiltin Type
|
||||||
highlight default link TSStructure Structure
|
|
||||||
highlight default link TSInclude Include
|
highlight default link TSInclude Include
|
||||||
|
|
||||||
highlight default link TSVariable TSNone
|
highlight default link TSVariable TSNone
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,16 @@
|
||||||
name: (scoped_identifier
|
name: (scoped_identifier
|
||||||
name: (identifier) @function))
|
name: (identifier) @function))
|
||||||
|
|
||||||
(namespace_identifier) @constant
|
|
||||||
|
|
||||||
((identifier) @type (#match? @type "^[A-Z]"))
|
((identifier) @type (#match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
(namespace_identifier) @namespace
|
||||||
((namespace_identifier) @type
|
((namespace_identifier) @type
|
||||||
(#match? @type "^[A-Z]"))
|
(#match? @type "^[A-Z]"))
|
||||||
((namespace_identifier) @constant
|
((namespace_identifier) @constant
|
||||||
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
(namespace_definition
|
||||||
|
name: (identifier) @namespace)
|
||||||
|
|
||||||
(destructor_name
|
(destructor_name
|
||||||
name: (_) @function)
|
name: (_) @function)
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,11 @@
|
||||||
(rest_parameter
|
(rest_parameter
|
||||||
(identifier) @parameter))
|
(identifier) @parameter))
|
||||||
|
|
||||||
|
; Variables
|
||||||
|
;----------
|
||||||
|
(namespace_import
|
||||||
|
(identifier) @namespace)
|
||||||
|
|
||||||
; Literals
|
; Literals
|
||||||
;---------
|
;---------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
; Modules
|
; Modules
|
||||||
;--------
|
;--------
|
||||||
|
|
||||||
[(module_name) (module_type_name)] @structure
|
[(module_name) (module_type_name)] @namespace
|
||||||
|
|
||||||
; Types
|
; Types
|
||||||
;------
|
;------
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,15 @@
|
||||||
(type_identifier) @type
|
(type_identifier) @type
|
||||||
(primitive_type) @type.builtin
|
(primitive_type) @type.builtin
|
||||||
(field_identifier) @field
|
(field_identifier) @field
|
||||||
|
(mod_item
|
||||||
|
name: (identifier) @namespace)
|
||||||
|
|
||||||
; Function calls
|
; Function calls
|
||||||
(call_expression
|
(call_expression
|
||||||
function: (identifier) @function)
|
function: (identifier) @function)
|
||||||
|
(call_expression
|
||||||
|
function: (scoped_identifier
|
||||||
|
(identifier) @function .))
|
||||||
(call_expression
|
(call_expression
|
||||||
function: (field_expression
|
function: (field_expression
|
||||||
field: (field_identifier) @function))
|
field: (field_identifier) @function))
|
||||||
|
|
@ -36,6 +40,16 @@
|
||||||
(#match? @constant "^[A-Z]"))
|
(#match? @constant "^[A-Z]"))
|
||||||
|
|
||||||
; Assume that uppercase names in paths are types
|
; 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
|
((scoped_identifier
|
||||||
path: (identifier) @type)
|
path: (identifier) @type)
|
||||||
(#match? @type "^[A-Z]"))
|
(#match? @type "^[A-Z]"))
|
||||||
|
|
@ -43,6 +57,13 @@
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(#match? @type "^[A-Z]"))
|
(#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_list (identifier) @type (#match? @type "^[A-Z]"))
|
||||||
(use_as_clause alias: (identifier) @type (#match? @type "^[A-Z]"))
|
(use_as_clause alias: (identifier) @type (#match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
|
@ -60,8 +81,10 @@
|
||||||
(#eq? @type "derive"))
|
(#eq? @type "derive"))
|
||||||
|
|
||||||
(macro_invocation
|
(macro_invocation
|
||||||
macro: (identifier) @function.macro
|
macro: (identifier) @function.macro)
|
||||||
"!" @function.macro)
|
(macro_invocation
|
||||||
|
macro: (scoped_identifier
|
||||||
|
(identifier) @function.macro .))
|
||||||
|
|
||||||
; Function definitions
|
; Function definitions
|
||||||
|
|
||||||
|
|
@ -99,6 +122,11 @@
|
||||||
|
|
||||||
(self) @variable.builtin
|
(self) @variable.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
"use"
|
||||||
|
"mod"
|
||||||
|
] @include
|
||||||
|
|
||||||
[
|
[
|
||||||
"break"
|
"break"
|
||||||
"const"
|
"const"
|
||||||
|
|
@ -111,7 +139,6 @@
|
||||||
"let"
|
"let"
|
||||||
"macro_rules!"
|
"macro_rules!"
|
||||||
"match"
|
"match"
|
||||||
"mod"
|
|
||||||
"move"
|
"move"
|
||||||
"pub"
|
"pub"
|
||||||
"ref"
|
"ref"
|
||||||
|
|
@ -124,7 +151,6 @@
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"async"
|
"async"
|
||||||
"await"
|
"await"
|
||||||
"use"
|
|
||||||
"where"
|
"where"
|
||||||
(mutable_specifier)
|
(mutable_specifier)
|
||||||
(super)
|
(super)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue