Skip to content

Commit

Permalink
Fix module declaration token type
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed May 4, 2023
1 parent 2b12abd commit d1ef7fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions SEMANTIC_HIGHLIGHTING.md
@@ -1,7 +1,7 @@
# Semantic highlighting

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

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

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

## Token types

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/requests/semantic_highlighting.rb
Expand Up @@ -347,7 +347,7 @@ def visit_class(node)
def visit_module(node)
return super unless visible?(node, @range)

add_token(node.constant.location, :class, [:declaration])
add_token(node.constant.location, :namespace, [:declaration])
visit(node.bodystmt)
end

Expand Down
@@ -0,0 +1,19 @@
{
"params": [],
"result": [
{
"delta_line": 0,
"delta_start_char": 7,
"length": 3,
"token_type": 0,
"token_modifiers": 1
},
{
"delta_line": 3,
"delta_start_char": 0,
"length": 3,
"token_type": 0,
"token_modifiers": 0
}
]
}

0 comments on commit d1ef7fe

Please sign in to comment.