Skip to content

Commit 98ae036

Browse files
committed
Fix highlights query for reversed precedence
1 parent 40faafd commit 98ae036

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

queries/highlights.scm

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
; Punctuation
2+
[
3+
"("
4+
")"
5+
"["
6+
"]"
7+
"{"
8+
"}"
9+
"<<"
10+
">>"
11+
] @punctuation.bracket
12+
[
13+
"."
14+
","
15+
;; Controversial -- maybe some are operators?
16+
":"
17+
"#"
18+
"="
19+
"->"
20+
".."
21+
"-"
22+
"<-"
23+
] @punctuation.delimiter
24+
25+
; Variables
26+
(identifier) @variable
27+
(discard) @comment.unused
28+
129
; Comments
230
(module_comment) @comment
331
(statement_comment) @comment
@@ -7,17 +35,21 @@
735
(constant
836
name: (identifier) @constant)
937

38+
; "Properties"
39+
; Assumed to be intended to refer to a name for a field; something that comes
40+
; before ":" or after "."
41+
; e.g. record field names, tuple indices, names for named arguments, etc
42+
(label) @property
43+
(tuple_access
44+
index: (integer) @property)
45+
1046
; Modules
1147
(module) @module
1248
(import alias: (identifier) @module)
1349
(remote_type_identifier
1450
module: (identifier) @module)
1551
(remote_constructor_name
1652
module: (identifier) @module)
17-
((field_access
18-
record: (identifier) @module
19-
field: (label) @function)
20-
(#is-not? local))
2153

2254
; Functions
2355
(unqualified_import (identifier) @function)
@@ -37,13 +69,15 @@
3769
right: (identifier) @function)
3870
(#is-not? local))
3971

40-
; "Properties"
41-
; Assumed to be intended to refer to a name for a field; something that comes
42-
; before ":" or after "."
43-
; e.g. record field names, tuple indices, names for named arguments, etc
44-
(label) @property
45-
(tuple_access
46-
index: (integer) @property)
72+
; TODO: `#is-not? local` applies to entire patterns but ideally it would accept
73+
; a capture to check as a local. This needs to be suggested upstream. Until this
74+
; is a part of the CLI's highlighter we can't distinguish between function calls
75+
; on modules and accesses of record fields.
76+
(function_call function: (field_access field: (label) @function)) ; Ideally this pattern would be removed,
77+
((field_access
78+
record: (identifier) @module)
79+
; field: (label) @function) ; this line would be uncommented,
80+
(#is-not? local)) ; and this line would be `(#is-not? local @module)`.
4781

4882
; Attributes
4983
(attribute
@@ -61,10 +95,10 @@
6195

6296
; Literals
6397
(string) @string
98+
(escape_sequence) @string.escape
6499
((escape_sequence) @warning
65100
; Deprecated in v0.33.0-rc2:
66101
(#eq? @warning "\\e"))
67-
(escape_sequence) @string.escape
68102
(bit_string_segment_option) @function.builtin
69103
(integer) @number
70104
(float) @number
@@ -73,11 +107,7 @@
73107
; TODO: when tree-sitter supports `#any-of?` in the Rust bindings,
74108
; refactor this to use `#any-of?` rather than `#match?`
75109
((identifier) @error
76-
(#match? @error "^(auto|delegate|derive|else|implement|macro|test)$"))
77-
78-
; Variables
79-
(identifier) @variable
80-
(discard) @comment.unused
110+
(#any-of? @error "auto" "delegate" "derive" "else" "implement" "macro" "test"))
81111

82112
; Keywords
83113
[
@@ -105,27 +135,3 @@
105135
operator: _ @operator)
106136
(boolean_negation "!" @operator)
107137
(integer_negation "-" @operator)
108-
109-
; Punctuation
110-
[
111-
"("
112-
")"
113-
"["
114-
"]"
115-
"{"
116-
"}"
117-
"<<"
118-
">>"
119-
] @punctuation.bracket
120-
[
121-
"."
122-
","
123-
;; Controversial -- maybe some are operators?
124-
":"
125-
"#"
126-
"="
127-
"->"
128-
".."
129-
"-"
130-
"<-"
131-
] @punctuation.delimiter

test/highlight/functions.gleam

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import gleam/string
2+
13
pub fn replace(
24
// <- keyword
35
// <- keyword
@@ -46,10 +48,10 @@ fn record_with_fun_field(record) {
4648
// ^ constructor
4749
foo.baz(41)
4850
// <- variable
49-
// ^ property
51+
// ^ function
5052
record.foobar("hello")
5153
// ^ variable.parameter
52-
// ^ property
54+
// ^ function
5355
string.replace("hello", "l", "o")
5456
// ^ module
5557
// ^ function

0 commit comments

Comments
 (0)