Skip to content
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

Reverse query precedence ordering #9458

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,15 +2475,17 @@ impl<'a> Iterator for HighlightIter<'a> {
}
}

// Once a highlighting pattern is found for the current node, skip over
// any later highlighting patterns that also match this node. Captures
// Use the last capture found for the current node, skipping over any
// highlight patterns that also match this node. Captures
// for a given node are ordered by pattern index, so these subsequent
// captures are guaranteed to be for highlighting, not injections or
// local variables.
while let Some((next_match, next_capture_index)) = captures.peek() {
let next_capture = next_match.captures[*next_capture_index];
if next_capture.node == capture.node {
captures.next();
match_.remove();
capture = next_capture;
match_ = captures.next().unwrap().0;
} else {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ indent = { tab-width = 4, unit = " " }

[[grammar]]
name = "julia"
source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "8fb38abff74652c4faddbf04d2d5bbbc6b4bae25" }
source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "e84f10db8eeb8b9807786bfc658808edaa1b4fa2" }

[[language]]
name = "java"
Expand Down
9 changes: 5 additions & 4 deletions runtime/queries/awk/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@
(number) @constant.numeric
(string) @string

(func_call name: (identifier) @function)
(func_def name: (identifier) @function)

(field_ref (_) @variable)
[
(identifier)
(field_ref)
] @variable

(func_call name: (identifier) @function)
(func_def name: (identifier) @function)

(field_ref (_) @variable)

(ns_qualified_name "::" @operator)
(ns_qualified_name (namespace) @namespace)
10 changes: 8 additions & 2 deletions runtime/queries/bash/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

(command_name) @function

(variable_name) @variable.other.member
(variable_name) @variable

((variable_name) @constant
(#match? @constant "^[A-Z][A-Z_0-9]*$"))

[
"if"
Expand Down Expand Up @@ -43,6 +46,9 @@

(comment) @comment

((word) @constant.builtin.boolean
(#any-of? @constant.builtin.boolean "true" "false"))

(function_definition name: (word) @function)

(file_descriptor) @constant.numeric.integer
Expand All @@ -51,7 +57,7 @@
(command_substitution)
(process_substitution)
(expansion)
]@embedded
] @embedded

[
"$"
Expand Down
23 changes: 12 additions & 11 deletions runtime/queries/c/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

(identifier) @variable

((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))

"sizeof" @keyword

[
Expand Down Expand Up @@ -109,6 +115,12 @@
(char_literal) @constant.character
(escape_sequence) @constant.character.escape

(field_identifier) @variable.other.member
(statement_identifier) @label
(type_identifier) @type
(primitive_type) @type.builtin
(sized_type_specifier) @type.builtin

(call_expression
function: (identifier) @function)
(call_expression
Expand All @@ -128,15 +140,4 @@
(attribute
name: (identifier) @attribute)

(field_identifier) @variable.other.member
(statement_identifier) @label
(type_identifier) @type
(primitive_type) @type.builtin
(sized_type_specifier) @type.builtin

((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))

(identifier) @variable

(comment) @comment
11 changes: 7 additions & 4 deletions runtime/queries/capnp/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
; Preproc

(unique_id) @keyword.directive
(top_level_annotation_body) @keyword.directive
[
(unique_id)
(top_level_annotation_body)
] @keyword.directive

; Includes

[
"import"
"$import"
"embed"
"using"
] @keyword.control.import

(import_path) @string
Expand Down Expand Up @@ -84,10 +87,10 @@
"union"
] @keyword.storage.type

"extends" @keyword

[
"extends"
"namespace"
"using"
(annotation_target)
] @special

Expand Down
18 changes: 9 additions & 9 deletions runtime/queries/cel/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
"in"
] @keyword

; Function calls

(call_expression
function: (identifier) @function)

(member_call_expression
function: (identifier) @function)

; Identifiers

(identifier) @variable.other.member

(select_expression
operand: (identifier) @type)

(select_expression
operand: (select_expression
member: (identifier) @type))

(identifier) @variable.other.member
; Function calls

(call_expression
function: (identifier) @function)

(member_call_expression
function: (identifier) @function)

; Literals

Expand Down
16 changes: 8 additions & 8 deletions runtime/queries/clojure/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

(comment) @comment

;; other symbols
(sym_lit) @variable

;; other calls
(list_lit
.
(sym_lit) @function)

;; metadata experiment
(meta_lit
marker: "^" @punctuation)
Expand Down Expand Up @@ -61,20 +69,12 @@
((sym_lit) @operator
(#match? @operator "^%"))

;; other calls
(list_lit
.
(sym_lit) @function)

;; interop-ish
(list_lit
.
(sym_lit) @function.method
(#match? @function.method "^\\."))

;; other symbols
(sym_lit) @variable

;; quote
(quoting_lit) @constant.character.escape

Expand Down
4 changes: 2 additions & 2 deletions runtime/queries/cpp/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; inherits: c

; Functions

; These casts are parsed as function calls, but are not.
Expand Down Expand Up @@ -132,5 +134,3 @@
; Strings

(raw_string_literal) @string

; inherits: c
20 changes: 14 additions & 6 deletions runtime/queries/cue/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(package_clause "package" @keyword.control.import)

(package_identifier) @variable
(package_identifier) @namespace

(import_declaration "import" @keyword.control.import)

Expand All @@ -25,7 +25,7 @@
"/"
] @operator

(unary_expression "*" @operator.default)
(unary_expression "*" @operator)

(unary_expression "=~" @operator.regexp)

Expand Down Expand Up @@ -95,16 +95,24 @@

(interpolation "\\(" @punctuation.bracket (_) ")" @punctuation.bracket) @variable.other.member

(field (label (identifier) @variable.other.member))
(identifier) @variable

; Types
(primitive_type) @type.builtin

(
(identifier) @keyword.storage.type
(#match? @keyword.storage.type "^#")
)

(field (label alias: (identifier) @label))
[
(slice_type)
(pointer_type)
] @type ; In attributes

(let_clause left: (identifier) @label)

(field (label (identifier) @variable.other.member))

(field (label alias: (identifier) @label))

(attribute (identifier) @tag)
(attribute (identifier) @attribute)
4 changes: 2 additions & 2 deletions runtime/queries/devicetree/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@

(integer_literal) @constant.numeric.integer

(identifier) @variable

(call_expression
function: (identifier) @function)

(labeled_item
label: (identifier) @label)

(identifier) @variable

(unit_address) @tag

(reference) @constant
Expand Down
12 changes: 12 additions & 0 deletions runtime/queries/dockerfile/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@

(double_quoted_string) @string

[
(heredoc_marker)
(heredoc_end)
] @label

((heredoc_block
(heredoc_line) @string)
(#set! "priority" 90))

(expansion
[
"$"
Expand All @@ -52,3 +61,6 @@
(param)
(mount_param)
] @constant

(expose_instruction
(expose_port) @constant.numeric.integer)
10 changes: 5 additions & 5 deletions runtime/queries/dot/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(identifier) @variable

(keyword) @keyword
(string_literal) @string
(number_literal) @constant.numeric
Expand Down Expand Up @@ -33,11 +35,9 @@
(identifier) @constant)
)

[
(comment)
(preproc)
] @comment
(comment) @comment

(preproc) @keyword.directive

(ERROR) @error

(identifier) @variable
Loading
Loading