Skip to content

Commit d1ef7fe

Browse files
committed
Fix module declaration token type
1 parent 2b12abd commit d1ef7fe

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

SEMANTIC_HIGHLIGHTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Semantic highlighting
22

33
The Ruby LSP supports semantic highlighting. This feature informs editors about the right token types for each part of
4-
the code to allow for richer and accurate highlighting. The strategy taken by the Ruby LSP is to only return tokens for
4+
the code to allow for rich and accurate highlighting. The strategy taken by the Ruby LSP is to only return tokens for
55
syntax that is ambiguous in Ruby (as opposed to all existing tokens) to optimize for performance.
66

77
An example of ambiguous syntax in Ruby are local variables and method calls. If you look at this line in isolation:
@@ -12,9 +12,9 @@ it is not possible to tell if `foo` is a local variable or a method call. It dep
1212
something before or not. This is one scenario where semantic highlighting removes the ambiguity for themes, returning
1313
the correct token type by statically analyzing the code.
1414

15-
To enhance a theme's Ruby syntax highlighting using the Ruby LSP, check the inform below. You may also want to check out
16-
the [Spinel theme](https://github.com/Shopify/vscode-shopify-ruby/blob/main/themes/dark_spinel.json) as an example,
17-
which uses all of the Ruby LSP's semantic highlighting information.
15+
To enhance a theme's Ruby syntax highlighting using the Ruby LSP, check the information below. You may also want to
16+
check out the [Spinel theme](https://github.com/Shopify/vscode-shopify-ruby/blob/main/themes/dark_spinel.json) as an
17+
example, which uses all of the Ruby LSP's semantic highlighting information.
1818

1919
## Token types
2020

lib/ruby_lsp/requests/semantic_highlighting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def visit_class(node)
347347
def visit_module(node)
348348
return super unless visible?(node, @range)
349349

350-
add_token(node.constant.location, :class, [:declaration])
350+
add_token(node.constant.location, :namespace, [:declaration])
351351
visit(node.bodystmt)
352352
end
353353

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"params": [],
3+
"result": [
4+
{
5+
"delta_line": 0,
6+
"delta_start_char": 7,
7+
"length": 3,
8+
"token_type": 0,
9+
"token_modifiers": 1
10+
},
11+
{
12+
"delta_line": 3,
13+
"delta_start_char": 0,
14+
"length": 3,
15+
"token_type": 0,
16+
"token_modifiers": 0
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)