New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight fixes #241
base: main
Are you sure you want to change the base?
Highlight fixes #241
Changes from all commits
b3edafc
ec237f2
3abe8b4
7a47330
186c562
cc4eeb3
eabca3a
088898e
2353fb3
d5be63f
68e2310
e43ea99
03b9e65
ae86960
411a36f
85b87d3
c82c32a
4f7a49f
a9b3dde
4f84ef6
68f4846
2f58542
9a7e362
8461c77
779f4fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,43 @@ | |
(list_pattern) | ||
] @type | ||
|
||
((type_identifier) @type.builtin | ||
(#any-of? @type.builtin | ||
"int" "char" "string" "float" "bool" "unit")) | ||
|
||
|
||
((unit) @constant.builtin | ||
(#set! "priority" 105)) | ||
|
||
[ | ||
(variant_identifier) | ||
(polyvar_identifier) | ||
] @constant | ||
] @constructor | ||
|
||
(record_type_field (property_identifier) @property) | ||
(record_field (property_identifier) @property) | ||
(object (field (property_identifier) @property)) | ||
(object_type (field (property_identifier) @property)) | ||
(member_expression (property_identifier) @property) | ||
(module_identifier) @namespace | ||
(module_identifier) @module | ||
|
||
(member_expression (property_identifier) @variable.member) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was |
||
|
||
(record_pattern | ||
(value_identifier) @variable.member) | ||
|
||
(value_identifier_path | ||
(module_identifier) | ||
(value_identifier) @variable.member) | ||
|
||
(labeled_argument | ||
label: (value_identifier) @property) | ||
|
||
|
||
; Parameters | ||
;---------------- | ||
|
||
(list_pattern (value_identifier) @parameter) | ||
(spread_pattern (value_identifier) @parameter) | ||
(list_pattern (value_identifier) @variable.parameter) | ||
(spread_pattern (value_identifier) @variable.parameter) | ||
|
||
; String literals | ||
;---------------- | ||
|
@@ -40,11 +60,8 @@ | |
(template_string) | ||
] @string | ||
|
||
(template_substitution | ||
"${" @punctuation.bracket | ||
"}" @punctuation.bracket) @embedded | ||
|
||
(character) @string.special | ||
(character) @character | ||
(escape_sequence) @string.escape | ||
|
||
; Other literals | ||
|
@@ -56,8 +73,8 @@ | |
] @constant.builtin | ||
|
||
(number) @number | ||
(polyvar) @constant | ||
(polyvar_string) @constant | ||
(polyvar) @constructor | ||
(polyvar_string) @constructor | ||
|
||
; Functions | ||
;---------- | ||
|
@@ -66,21 +83,45 @@ | |
[ | ||
(parameter (value_identifier)) | ||
(labeled_parameter (value_identifier)) | ||
] @parameter | ||
] @variable.parameter | ||
|
||
; single parameter with no parens | ||
(function parameter: (value_identifier) @parameter) | ||
(function parameter: (value_identifier) @variable.parameter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and other similar changes conform to to Neovim's new tags with fallbacks. Meaning, if a certain theme specifies a color for |
||
|
||
; first-level descructuring (required for nvim-tree-sitter as it only matches direct | ||
; children and the above patterns do not match destructuring patterns in NeoVim) | ||
(parameter (tuple_pattern (tuple_item_pattern (value_identifier) @parameter))) | ||
(parameter (array_pattern (value_identifier) @parameter)) | ||
(parameter (record_pattern (value_identifier) @parameter)) | ||
(parameter (tuple_pattern (tuple_item_pattern (value_identifier) @variable.parameter))) | ||
(parameter (array_pattern (value_identifier) @variable.parameter)) | ||
(parameter (record_pattern (value_identifier) @variable.parameter)) | ||
|
||
; function identifier in let binding | ||
(let_binding | ||
pattern: (value_identifier) @function | ||
body: (function)) | ||
|
||
; function calls | ||
|
||
(call_expression | ||
function: (value_identifier_path | ||
_ | ||
(value_identifier) @function.call)) | ||
|
||
(call_expression | ||
function: (value_identifier) @function.call) | ||
|
||
; highlight the right-hand side of a pipe operator as a function call | ||
(pipe_expression | ||
_ | ||
[(value_identifier_path | ||
_ | ||
(value_identifier) @function.call) | ||
(value_identifier) @function.call]) | ||
|
||
|
||
; Meta | ||
;----- | ||
|
||
(decorator_identifier) @annotation | ||
(decorator_identifier) @attribute | ||
|
||
(extension_identifier) @keyword | ||
("%") @keyword | ||
|
@@ -89,27 +130,37 @@ | |
;----- | ||
|
||
(subscript_expression index: (string) @property) | ||
(polyvar_type_pattern "#" @constant) | ||
(polyvar_type_pattern "#" @constructor) | ||
|
||
[ | ||
"include" | ||
"open" | ||
] @keyword.import | ||
|
||
|
||
[ | ||
"as" | ||
"private" | ||
"mutable" | ||
"rec" | ||
] @keyword.modifier | ||
|
||
[ | ||
("include") | ||
("open") | ||
] @include | ||
"type" | ||
] @keyword.type | ||
|
||
[ | ||
"and" | ||
"with" | ||
] @keyword.operator | ||
|
||
[ | ||
"as" | ||
"export" | ||
"external" | ||
"let" | ||
"module" | ||
"mutable" | ||
"private" | ||
"rec" | ||
"type" | ||
"and" | ||
"assert" | ||
"await" | ||
"with" | ||
"lazy" | ||
"constraint" | ||
] @keyword | ||
|
@@ -123,25 +174,25 @@ | |
"else" | ||
"switch" | ||
"when" | ||
] @conditional | ||
] @keyword.conditional | ||
|
||
[ | ||
"exception" | ||
"try" | ||
"catch" | ||
] @exception | ||
] @keyword.exception | ||
|
||
(call_expression | ||
function: (value_identifier) @exception | ||
(#eq? @exception "raise")) | ||
function: (value_identifier) @keyword.exception | ||
(#eq? @keyword.exception "raise")) | ||
|
||
[ | ||
"for" | ||
"in" | ||
"to" | ||
"downto" | ||
"while" | ||
] @repeat | ||
] @keyword.repeat | ||
|
||
[ | ||
"." | ||
|
@@ -174,6 +225,7 @@ | |
"|>" | ||
":>" | ||
"+=" | ||
"=>" | ||
(uncurry) | ||
] @operator | ||
|
||
|
@@ -190,6 +242,10 @@ | |
"]" | ||
] @punctuation.bracket | ||
|
||
(template_substitution | ||
"${" @punctuation.special | ||
"}" @punctuation.special) @embedded | ||
|
||
(polyvar_type | ||
[ | ||
"[" | ||
|
@@ -201,12 +257,11 @@ | |
[ | ||
"~" | ||
"?" | ||
"=>" | ||
".." | ||
"..." | ||
] @punctuation.special | ||
|
||
(ternary_expression ["?" ":"] @operator) | ||
(ternary_expression ["?" ":"] @keyword.conditional.ternary) | ||
|
||
; JSX | ||
;---------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@name | ||
//<- annotation | ||
//<- attribute | ||
|
||
@@name | ||
//<- annotation | ||
//<- attribute |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
|
||
/**/ #polyvar | ||
// ^ constant | ||
// ^ constant | ||
// ^ constructor | ||
// ^ constructor | ||
|
||
/**/ #"polyvar" | ||
// ^ constant | ||
// ^ constant | ||
// ^ constant | ||
// ^ constructor | ||
// ^ constructor | ||
// ^ constructor | ||
|
||
/**/ #\"polyvar" | ||
// ^ constant | ||
// ^ constant | ||
// ^ constant | ||
// ^ constant | ||
// ^ constructor | ||
// ^ constructor | ||
// ^ constructor | ||
// ^ constructor | ||
|
||
/**/ #77 | ||
// ^ constant | ||
// ^ constant | ||
// ^ constructor | ||
// ^ constructor | ||
|
||
/**/ 'R' | ||
// ^ string.special | ||
// ^ string.special | ||
// ^ character | ||
// ^ character | ||
|
||
/**/ '\\' | ||
// ^ string.escape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not everyone might agree on this one, since variants, specially polyvars without parameters, are used as "constants". This thinking is common when making JS bindings, since polyvars compile to strings.
However, from a language perspective, I find it more correct to think of them as constructors. This is also how the ocaml parser highlights them.