Skip to content

Commit 708fff8

Browse files
authored
Add more language server scopes (#107)
These allow us to restrict code completions into specific contexts: - For Elixir files, Tailwind and Emmet will now give completions inside HEEx templates only, save for one caveat - Tailwind is still scoped into strings so that completions don't break if Elixir interpolation is used inside the class attribute of an HTML tag - For EEx/HEEx files, ElixirLS, Expert, Next LS, and Lexical will now give completions inside Elixir expressions only - should fix #91 Additionally, this reworks the function override that was being used by HEEx into an identifier override that should cover slot names as well - with this change `@` will now be treated as a word character, just like Elixir
1 parent 77ced9e commit 708fff8

7 files changed

Lines changed: 83 additions & 14 deletions

File tree

.tsqueryrc.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@
100100
"char": "Captures char literals",
101101
"comment": "Captures block comments",
102102
"comment.inclusive": "Captures line comments",
103-
"function": "Captures function identifiers",
104-
"identifier": "Captures all identifiers (i.e. variables, functions, atoms, keywords, and attributes)",
103+
"elixir": "Captures Elixir expressions",
104+
"heex": "Captures HEEx templates",
105+
"identifier": "Captures all identifiers (i.e. variables, functions, atoms, keywords, and module attributes)",
105106
"quoted_atom": "Captures quoted atoms",
106107
"sigil_curly": "Captures sigils using curly bracket delimiters",
107-
"sigil_round": "Captures sigils using parenthesis delimiters",
108+
"sigil_round": "Captures sigils using round bracket delimiters",
108109
"sigil_square": "Captures sigils using square bracket delimiters",
109-
"sigil_string": "Captures sigils using string delimiters",
110+
"sigil_quote": "Captures sigils using quote mark delimiters",
110111
"string": "Captures strings"
111112
},
112113
"redactions": {

languages/eex/config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ brackets = [
1414
{ start = "!--", end = " --", close = true, newline = false, not_in = ["comment"] },
1515
]
1616
tab_size = 2
17+
scope_opt_in_language_servers = [
18+
"elixir-ls",
19+
"expert",
20+
"next-ls",
21+
"lexical",
22+
]
23+
24+
[overrides.elixir]
25+
opt_into_language_servers = [
26+
"elixir-ls",
27+
"expert",
28+
"next-ls",
29+
"lexical",
30+
]

languages/eex/overrides.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; Comments
12
[
23
(comment
34
"<%!--"
@@ -6,3 +7,6 @@
67
"<%#"
78
"%>")
89
] @comment
10+
11+
; Elixir expressions
12+
(directive) @elixir

languages/elixir/config.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,39 @@ brackets = [
1212
"comment",
1313
"string",
1414
"quoted_atom",
15-
"sigil_string",
15+
"sigil_quote",
1616
] },
1717
{ start = "\"", end = "\"", close = true, newline = false, not_in = [
1818
"comment",
1919
"string",
2020
"quoted_atom",
21-
"sigil_string",
21+
"sigil_quote",
2222
] },
2323
{ start = "'''", end = "\n'''", close = true, newline = true, not_in = [
2424
"comment",
2525
"string",
2626
"quoted_atom",
27-
"sigil_string",
27+
"sigil_quote",
2828
] },
2929
{ start = "'", end = "'", close = true, newline = false, not_in = [
3030
"comment",
3131
"string",
3232
"quoted_atom",
33-
"sigil_string",
33+
"sigil_quote",
3434
] },
3535
]
3636
tab_size = 2
3737
decrease_indent_pattern = '^\s*(after|catch|else|rescue)$'
38-
scope_opt_in_language_servers = ["tailwindcss-language-server"]
38+
scope_opt_in_language_servers = [
39+
"tailwindcss-language-server",
40+
"emmet-language-server",
41+
]
42+
43+
[overrides.heex]
44+
opt_into_language_servers = [
45+
"tailwindcss-language-server",
46+
"emmet-language-server",
47+
]
3948

4049
[overrides.string]
4150
completion_query_characters = ["-"]

languages/elixir/overrides.scm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
; Comments
12
(comment) @comment.inclusive
23

4+
; Strings
35
[
46
(string)
57
(charlist)
68
] @string
79

10+
; Quoted atoms
811
[
912
(quoted_atom)
1013
(quoted_keyword)
1114
] @quoted_atom
1215

16+
; Identifiers, atoms, and module attributes
1317
[
1418
(identifier)
1519
(atom)
@@ -18,24 +22,30 @@
1822
operator: "@")
1923
] @identifier
2024

25+
; Chars (e.g. `?\n`, `?\s`)
2126
(char) @char
2227

28+
; Parameter placeholders when capturing anonymous functions
2329
(unary_operator
2430
operator: "&"
2531
operand: (integer)) @capture
2632

33+
; Sigils using curly bracket delimiters
2734
(sigil
2835
quoted_start: "{"
2936
quoted_end: "}") @sigil_curly
3037

38+
; Sigils using square bracket delimiters
3139
(sigil
3240
quoted_start: "["
3341
quoted_end: "]") @sigil_square
3442

43+
; Sigils using round bracket delimiters
3544
(sigil
3645
quoted_start: "("
3746
quoted_end: ")") @sigil_round
3847

48+
; Sigils using quote mark delimiters
3949
[
4050
(sigil
4151
quoted_start: "\"\"\""
@@ -49,4 +59,9 @@
4959
(sigil
5060
quoted_start: "'"
5161
quoted_end: "'")
52-
] @sigil_string
62+
] @sigil_quote
63+
64+
; HEEx templates
65+
(sigil
66+
(sigil_name) @_sigil_name
67+
(#eq? @_sigil_name "H")) @heex

languages/heex/config.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,25 @@ brackets = [
1515
{ start = "!--", end = " --", close = true, newline = false, not_in = ["comment", "string"] },
1616
]
1717
tab_size = 2
18-
scope_opt_in_language_servers = ["tailwindcss-language-server"]
18+
scope_opt_in_language_servers = [
19+
"elixir-ls",
20+
"expert",
21+
"next-ls",
22+
"lexical",
23+
"tailwindcss-language-server",
24+
]
25+
26+
[overrides.elixir]
27+
opt_into_language_servers = [
28+
"elixir-ls",
29+
"expert",
30+
"next-ls",
31+
"lexical",
32+
]
1933

2034
[overrides.string]
2135
completion_query_characters = ["-"]
2236
opt_into_language_servers = ["tailwindcss-language-server"]
2337

24-
[overrides.function]
25-
word_characters = ["!", "?"]
38+
[overrides.identifier]
39+
word_characters = ["!", "?", "@"]

languages/heex/overrides.scm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
; Comments
12
(comment) @comment
23

4+
; HEEx attribute values
35
[
46
(attribute_value)
57
(quoted_attribute_value)
68
] @string
79

8-
(function) @function
10+
; Function and slot identifiers
11+
[
12+
(function)
13+
(slot_name)
14+
] @identifier
15+
16+
; Elixir expressions
17+
[
18+
(expression)
19+
(directive)
20+
] @elixir

0 commit comments

Comments
 (0)