Skip to content

Commit

Permalink
Merge pull request #182 from Shopify/vs/include_all_token_types_in_le…
Browse files Browse the repository at this point in the history
…gend

Include all token types in legend
  • Loading branch information
vinistock authored Jul 5, 2022
2 parents d5299ae + b9b5633 commit 75c2d1b
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 90 deletions.
2 changes: 1 addition & 1 deletion lib/ruby_lsp/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def respond_with_capabilities(enabled_features)
Interface::SemanticTokensRegistrationOptions.new(
document_selector: { scheme: "file", language: "ruby" },
legend: Interface::SemanticTokensLegend.new(
token_types: Requests::SemanticHighlighting::TOKEN_TYPES,
token_types: Requests::SemanticHighlighting::TOKEN_TYPES.keys,
token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys
),
range: false,
Expand Down
32 changes: 26 additions & 6 deletions lib/ruby_lsp/requests/semantic_highlighting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@ module Requests
class SemanticHighlighting < BaseRequest
extend T::Sig

TOKEN_TYPES = T.let([
:variable,
:method,
:namespace,
].freeze, T::Array[Symbol])
TOKEN_TYPES = T.let({
namespace: 0,
type: 1,
class: 2,
enum: 3,
interface: 4,
struct: 5,
typeParameter: 6,
parameter: 7,
variable: 8,
property: 9,
enumMember: 10,
event: 11,
function: 12,
method: 13,
macro: 14,
keyword: 15,
modifier: 16,
comment: 17,
string: 18,
number: 19,
regexp: 20,
operator: 21,
decorator: 22,
}.freeze, T::Hash[Symbol, Integer])

TOKEN_MODIFIERS = T.let({
declaration: 0,
Expand Down Expand Up @@ -195,7 +215,7 @@ def add_token(location, type, modifiers = [])
SemanticToken.new(
location: location,
length: length,
type: T.must(TOKEN_TYPES.index(type)),
type: T.must(TOKEN_TYPES[type]),
modifier: modifiers_indices
)
)
Expand Down
6 changes: 3 additions & 3 deletions test/expectations/semantic_highlighting/aref_field.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 9,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 1,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 1,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/expectations/semantic_highlighting/aref_variable.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 9,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 1,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 1,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"delta_line": 0,
"delta_start_char": 8,
"length": 6,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 11,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 4,
"length": 6,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 11,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 5,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 4,
"length": 6,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 7,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
8 changes: 4 additions & 4 deletions test/expectations/semantic_highlighting/command_call.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"delta_line": 0,
"delta_start_char": 0,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 0,
"length": 6,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 7,
"length": 10,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 11,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"delta_line": 1,
"delta_start_char": 0,
"length": 3,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"delta_line": 0,
"delta_start_char": 0,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 5,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
12 changes: 6 additions & 6 deletions test/expectations/semantic_highlighting/const.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@
"delta_line": 0,
"delta_start_char": 0,
"length": 2,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 2,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 0,
"length": 3,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 5,
"length": 2,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 5,
"length": 2,
"token_type": 2,
"token_type": 0,
"token_modifiers": 0
}
]
Expand Down
2 changes: 1 addition & 1 deletion test/expectations/semantic_highlighting/def_endless.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"delta_line": 2,
"delta_start_char": 4,
"length": 3,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/expectations/semantic_highlighting/defs.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 4,
"token_type": 0,
"token_type": 8,
"token_modifiers": 512
},
{
"delta_line": 0,
"delta_start_char": 5,
"length": 3,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 1,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
4 changes: 2 additions & 2 deletions test/expectations/semantic_highlighting/fcall_invocation.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 11,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 10,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"delta_line": 0,
"delta_start_char": 4,
"length": 11,
"token_type": 1,
"token_type": 13,
"token_modifiers": 1
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
},
{
"delta_line": 1,
"delta_start_char": 2,
"length": 10,
"token_type": 1,
"token_type": 13,
"token_modifiers": 0
},
{
"delta_line": 0,
"delta_start_char": 11,
"length": 3,
"token_type": 0,
"token_type": 8,
"token_modifiers": 0
}
]
Expand Down
Loading

0 comments on commit 75c2d1b

Please sign in to comment.