From a80700663ebb433a438059077ebfd03966fc2a00 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 4 Jul 2022 14:29:41 -0400 Subject: [PATCH 1/2] Include all token types in semantic highlighting legend --- lib/ruby_lsp/handler.rb | 2 +- .../requests/semantic_highlighting.rb | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/ruby_lsp/handler.rb b/lib/ruby_lsp/handler.rb index 5f18b1528..e46d2c226 100644 --- a/lib/ruby_lsp/handler.rb +++ b/lib/ruby_lsp/handler.rb @@ -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, diff --git a/lib/ruby_lsp/requests/semantic_highlighting.rb b/lib/ruby_lsp/requests/semantic_highlighting.rb index 4d313978e..e24838e9e 100644 --- a/lib/ruby_lsp/requests/semantic_highlighting.rb +++ b/lib/ruby_lsp/requests/semantic_highlighting.rb @@ -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, @@ -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 ) ) From b9b563328a338141c2c07a8bfeb3adf284a0f156 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 4 Jul 2022 14:29:55 -0400 Subject: [PATCH 2/2] Update tests with the new token type index --- .../semantic_highlighting/aref_field.exp | 6 +++--- .../semantic_highlighting/aref_variable.exp | 6 +++--- .../semantic_highlighting/call_invocation.exp | 2 +- ...call_invocation_with_variable_receiver.exp | 8 ++++---- ...n_with_variable_receiver_and_arguments.exp | 12 +++++------ .../semantic_highlighting/command_call.exp | 8 ++++---- .../command_invocation.exp | 2 +- .../command_invocation_variable.exp | 4 ++-- .../semantic_highlighting/const.exp | 12 +++++------ .../semantic_highlighting/def_endless.exp | 2 +- .../semantic_highlighting/defs.exp | 6 +++--- .../fcall_invocation.exp | 4 ++-- .../fcall_invocation_variable_arguments.exp | 8 ++++---- .../semantic_highlighting/local_variables.exp | 6 +++--- .../semantic_highlighting/method_params.exp | 20 +++++++++---------- .../multi_assignment.exp | 10 +++++----- .../semantic_highlighting/sclass.exp | 4 ++-- .../special_ruby_methods.exp | 16 +++++++-------- .../var_aref_variable.exp | 6 +++--- .../var_field_variable.exp | 18 ++++++++--------- .../vcall_invocation.exp | 4 ++-- test/integration_test.rb | 2 +- 22 files changed, 83 insertions(+), 83 deletions(-) diff --git a/test/expectations/semantic_highlighting/aref_field.exp b/test/expectations/semantic_highlighting/aref_field.exp index ad0f7619a..fd2462914 100644 --- a/test/expectations/semantic_highlighting/aref_field.exp +++ b/test/expectations/semantic_highlighting/aref_field.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/aref_variable.exp b/test/expectations/semantic_highlighting/aref_variable.exp index ad0f7619a..fd2462914 100644 --- a/test/expectations/semantic_highlighting/aref_variable.exp +++ b/test/expectations/semantic_highlighting/aref_variable.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/call_invocation.exp b/test/expectations/semantic_highlighting/call_invocation.exp index d7b0e9ce1..37904018e 100644 --- a/test/expectations/semantic_highlighting/call_invocation.exp +++ b/test/expectations/semantic_highlighting/call_invocation.exp @@ -4,7 +4,7 @@ "delta_line": 0, "delta_start_char": 8, "length": 6, - "token_type": 1, + "token_type": 13, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver.exp b/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver.exp index 23c582629..a9af1e79c 100644 --- a/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver.exp +++ b/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver_and_arguments.exp b/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver_and_arguments.exp index 27505747c..ad4f2ba4c 100644 --- a/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver_and_arguments.exp +++ b/test/expectations/semantic_highlighting/call_invocation_with_variable_receiver_and_arguments.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/command_call.exp b/test/expectations/semantic_highlighting/command_call.exp index 8c70a15b5..b925f698f 100644 --- a/test/expectations/semantic_highlighting/command_call.exp +++ b/test/expectations/semantic_highlighting/command_call.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/command_invocation.exp b/test/expectations/semantic_highlighting/command_invocation.exp index 06542277c..0b9a74bc6 100644 --- a/test/expectations/semantic_highlighting/command_invocation.exp +++ b/test/expectations/semantic_highlighting/command_invocation.exp @@ -4,7 +4,7 @@ "delta_line": 1, "delta_start_char": 0, "length": 3, - "token_type": 1, + "token_type": 13, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/command_invocation_variable.exp b/test/expectations/semantic_highlighting/command_invocation_variable.exp index 264dd820d..8c3d0186f 100644 --- a/test/expectations/semantic_highlighting/command_invocation_variable.exp +++ b/test/expectations/semantic_highlighting/command_invocation_variable.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/const.exp b/test/expectations/semantic_highlighting/const.exp index f0bdf6b17..14c3573ba 100644 --- a/test/expectations/semantic_highlighting/const.exp +++ b/test/expectations/semantic_highlighting/const.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/def_endless.exp b/test/expectations/semantic_highlighting/def_endless.exp index 440da56d5..c0038b40a 100644 --- a/test/expectations/semantic_highlighting/def_endless.exp +++ b/test/expectations/semantic_highlighting/def_endless.exp @@ -4,7 +4,7 @@ "delta_line": 2, "delta_start_char": 4, "length": 3, - "token_type": 1, + "token_type": 13, "token_modifiers": 1 } ] diff --git a/test/expectations/semantic_highlighting/defs.exp b/test/expectations/semantic_highlighting/defs.exp index 6b133fdf1..b4e75a55c 100644 --- a/test/expectations/semantic_highlighting/defs.exp +++ b/test/expectations/semantic_highlighting/defs.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/fcall_invocation.exp b/test/expectations/semantic_highlighting/fcall_invocation.exp index bed37ad3a..e16a7f103 100644 --- a/test/expectations/semantic_highlighting/fcall_invocation.exp +++ b/test/expectations/semantic_highlighting/fcall_invocation.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/fcall_invocation_variable_arguments.exp b/test/expectations/semantic_highlighting/fcall_invocation_variable_arguments.exp index 04f5bbf7d..45ccbfff7 100644 --- a/test/expectations/semantic_highlighting/fcall_invocation_variable_arguments.exp +++ b/test/expectations/semantic_highlighting/fcall_invocation_variable_arguments.exp @@ -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 } ] diff --git a/test/expectations/semantic_highlighting/local_variables.exp b/test/expectations/semantic_highlighting/local_variables.exp index 4b3e5bf1a..ea8471c26 100644 --- a/test/expectations/semantic_highlighting/local_variables.exp +++ b/test/expectations/semantic_highlighting/local_variables.exp @@ -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": 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 } ] diff --git a/test/expectations/semantic_highlighting/method_params.exp b/test/expectations/semantic_highlighting/method_params.exp index 2be62231b..6716a5eae 100644 --- a/test/expectations/semantic_highlighting/method_params.exp +++ b/test/expectations/semantic_highlighting/method_params.exp @@ -4,70 +4,70 @@ "delta_line": 0, "delta_start_char": 4, "length": 3, - "token_type": 1, + "token_type": 13, "token_modifiers": 1 }, { "delta_line": 0, "delta_start_char": 21, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 8, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 1, "delta_start_char": 7, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 3, "length": 3, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/multi_assignment.exp b/test/expectations/semantic_highlighting/multi_assignment.exp index 73d3ed91b..2f9af3c42 100644 --- a/test/expectations/semantic_highlighting/multi_assignment.exp +++ b/test/expectations/semantic_highlighting/multi_assignment.exp @@ -4,35 +4,35 @@ "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": 0, "delta_start_char": 3, "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 }, { "delta_line": 1, "delta_start_char": 2, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/sclass.exp b/test/expectations/semantic_highlighting/sclass.exp index d7761eff1..e6ce03177 100644 --- a/test/expectations/semantic_highlighting/sclass.exp +++ b/test/expectations/semantic_highlighting/sclass.exp @@ -4,14 +4,14 @@ "delta_line": 0, "delta_start_char": 6, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "delta_line": 1, "delta_start_char": 11, "length": 4, - "token_type": 0, + "token_type": 8, "token_modifiers": 512 } ] diff --git a/test/expectations/semantic_highlighting/special_ruby_methods.exp b/test/expectations/semantic_highlighting/special_ruby_methods.exp index b86fbef57..845d18e9f 100644 --- a/test/expectations/semantic_highlighting/special_ruby_methods.exp +++ b/test/expectations/semantic_highlighting/special_ruby_methods.exp @@ -4,56 +4,56 @@ "delta_line": 5, "delta_start_char": 6, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "delta_line": 1, "delta_start_char": 10, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "delta_line": 4, "delta_start_char": 2, "length": 6, - "token_type": 1, + "token_type": 13, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 7, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "delta_line": 4, "delta_start_char": 6, "length": 3, - "token_type": 1, + "token_type": 13, "token_modifiers": 1 }, { "delta_line": 1, "delta_start_char": 4, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 4, "length": 3, - "token_type": 1, + "token_type": 13, "token_modifiers": 0 }, { "delta_line": 1, "delta_start_char": 4, "length": 11, - "token_type": 1, + "token_type": 13, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/var_aref_variable.exp b/test/expectations/semantic_highlighting/var_aref_variable.exp index ea16cd21d..88009e0b0 100644 --- a/test/expectations/semantic_highlighting/var_aref_variable.exp +++ b/test/expectations/semantic_highlighting/var_aref_variable.exp @@ -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": 5, "delta_start_char": 0, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/var_field_variable.exp b/test/expectations/semantic_highlighting/var_field_variable.exp index 739e18882..611f07d44 100644 --- a/test/expectations/semantic_highlighting/var_field_variable.exp +++ b/test/expectations/semantic_highlighting/var_field_variable.exp @@ -4,63 +4,63 @@ "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": 0, "delta_start_char": 4, "length": 3, - "token_type": 2, + "token_type": 0, "token_modifiers": 0 }, { "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 }, { "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 }, { "delta_line": 1, "delta_start_char": 2, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 }, { "delta_line": 0, "delta_start_char": 4, "length": 1, - "token_type": 0, + "token_type": 8, "token_modifiers": 0 } ] diff --git a/test/expectations/semantic_highlighting/vcall_invocation.exp b/test/expectations/semantic_highlighting/vcall_invocation.exp index bed37ad3a..e16a7f103 100644 --- a/test/expectations/semantic_highlighting/vcall_invocation.exp +++ b/test/expectations/semantic_highlighting/vcall_invocation.exp @@ -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 } ] diff --git a/test/integration_test.rb b/test/integration_test.rb index 0cb32005a..03cdf0681 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -78,7 +78,7 @@ def test_semantic_highlighting assert_telemetry("textDocument/didOpen") response = make_request("textDocument/semanticTokens/full", { textDocument: { uri: "file://#{__FILE__}" } }) - assert_equal([0, 6, 3, 2, 0], response[:result][:data]) + assert_equal([0, 6, 3, 0, 0], response[:result][:data]) end def test_formatting