ruby-lsp 0.23.16 → 0.23.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +16 -19
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +0 -3
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +9 -19
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +37 -68
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +6 -9
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +1 -10
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +4 -4
- data/lib/ruby_indexer/test/index_test.rb +7 -0
- data/lib/ruby_indexer/test/method_test.rb +7 -7
- data/lib/ruby_indexer/test/prefix_tree_test.rb +8 -8
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +4 -3
- data/lib/ruby_indexer/test/test_case.rb +7 -1
- data/lib/ruby_lsp/client_capabilities.rb +6 -1
- data/lib/ruby_lsp/document.rb +7 -11
- data/lib/ruby_lsp/erb_document.rb +3 -6
- data/lib/ruby_lsp/internal.rb +6 -1
- data/lib/ruby_lsp/listeners/completion.rb +8 -8
- data/lib/ruby_lsp/listeners/definition.rb +7 -7
- data/lib/ruby_lsp/listeners/document_link.rb +7 -10
- data/lib/ruby_lsp/listeners/hover.rb +18 -14
- data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
- data/lib/ruby_lsp/listeners/spec_style.rb +11 -11
- data/lib/ruby_lsp/listeners/test_discovery.rb +1 -1
- data/lib/ruby_lsp/listeners/test_style.rb +10 -5
- data/lib/ruby_lsp/rbs_document.rb +3 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +44 -39
- data/lib/ruby_lsp/requests/code_lens.rb +16 -4
- data/lib/ruby_lsp/requests/completion.rb +2 -2
- data/lib/ruby_lsp/requests/definition.rb +3 -6
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/document_link.rb +1 -1
- data/lib/ruby_lsp/requests/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +0 -2
- data/lib/ruby_lsp/requests/hover.rb +2 -5
- data/lib/ruby_lsp/requests/inlay_hints.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +1 -16
- data/lib/ruby_lsp/requests/rename.rb +1 -4
- data/lib/ruby_lsp/requests/request.rb +3 -2
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/signature_help.rb +1 -1
- data/lib/ruby_lsp/requests/support/annotation.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +0 -5
- data/lib/ruby_lsp/requests/support/test_item.rb +7 -1
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +1 -4
- data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -3
- data/lib/ruby_lsp/response_builders/hover.rb +1 -4
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +1 -2
- data/lib/ruby_lsp/response_builders/signature_help.rb +1 -2
- data/lib/ruby_lsp/response_builders/test_collection.rb +29 -3
- data/lib/ruby_lsp/ruby_document.rb +3 -36
- data/lib/ruby_lsp/server.rb +76 -22
- data/lib/ruby_lsp/store.rb +6 -6
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +47 -10
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +6 -23
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +5 -17
- data/lib/ruby_lsp/utils.rb +43 -0
- metadata +1 -1
@@ -13,14 +13,9 @@ module RubyLsp
|
|
13
13
|
NEW_METHOD_NAME = "new_method"
|
14
14
|
|
15
15
|
class CodeActionError < StandardError; end
|
16
|
-
|
17
|
-
class
|
18
|
-
|
19
|
-
EmptySelection = new
|
20
|
-
InvalidTargetRange = new
|
21
|
-
UnknownCodeAction = new
|
22
|
-
end
|
23
|
-
end
|
16
|
+
class EmptySelectionError < CodeActionError; end
|
17
|
+
class InvalidTargetRangeError < CodeActionError; end
|
18
|
+
class UnknownCodeActionError < CodeActionError; end
|
24
19
|
|
25
20
|
#: (RubyDocument document, GlobalState global_state, Hash[Symbol, untyped] code_action) -> void
|
26
21
|
def initialize(document, global_state, code_action)
|
@@ -31,9 +26,9 @@ module RubyLsp
|
|
31
26
|
end
|
32
27
|
|
33
28
|
# @override
|
34
|
-
#: -> (Interface::CodeAction
|
29
|
+
#: -> (Interface::CodeAction)
|
35
30
|
def perform
|
36
|
-
|
31
|
+
raise EmptySelectionError, "Invalid selection for refactor" if @document.source.empty?
|
37
32
|
|
38
33
|
case @code_action[:title]
|
39
34
|
when CodeActions::EXTRACT_TO_VARIABLE_TITLE
|
@@ -47,26 +42,30 @@ module RubyLsp
|
|
47
42
|
CodeActions::CREATE_ATTRIBUTE_ACCESSOR
|
48
43
|
create_attribute_accessor
|
49
44
|
else
|
50
|
-
|
45
|
+
raise UnknownCodeActionError, "Unknown code action: #{@code_action[:title]}"
|
51
46
|
end
|
52
47
|
end
|
53
48
|
|
54
49
|
private
|
55
50
|
|
56
|
-
#: -> (Interface::CodeAction
|
51
|
+
#: -> (Interface::CodeAction)
|
57
52
|
def switch_block_style
|
58
53
|
source_range = @code_action.dig(:data, :range)
|
59
|
-
|
54
|
+
raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
|
60
55
|
|
61
56
|
target = @document.locate_first_within_range(
|
62
57
|
@code_action.dig(:data, :range),
|
63
58
|
node_types: [Prism::CallNode],
|
64
59
|
)
|
65
60
|
|
66
|
-
|
61
|
+
unless target.is_a?(Prism::CallNode)
|
62
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
63
|
+
end
|
67
64
|
|
68
65
|
node = target.block
|
69
|
-
|
66
|
+
unless node.is_a?(Prism::BlockNode)
|
67
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
68
|
+
end
|
70
69
|
|
71
70
|
indentation = " " * target.location.start_column unless node.opening_loc.slice == "do"
|
72
71
|
|
@@ -91,10 +90,10 @@ module RubyLsp
|
|
91
90
|
)
|
92
91
|
end
|
93
92
|
|
94
|
-
#: -> (Interface::CodeAction
|
93
|
+
#: -> (Interface::CodeAction)
|
95
94
|
def refactor_variable
|
96
95
|
source_range = @code_action.dig(:data, :range)
|
97
|
-
|
96
|
+
raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
|
98
97
|
|
99
98
|
start_index, end_index = @document.find_index_by_position(source_range[:start], source_range[:end])
|
100
99
|
extracted_source = @document.source[start_index...end_index] #: as !nil
|
@@ -111,7 +110,9 @@ module RubyLsp
|
|
111
110
|
|
112
111
|
closest_statements = node_context.node
|
113
112
|
parent_statements = node_context.parent
|
114
|
-
|
113
|
+
if closest_statements.nil? || closest_statements.child_nodes.compact.empty?
|
114
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
115
|
+
end
|
115
116
|
|
116
117
|
# Find the node with the end line closest to the requested position, so that we can place the refactor
|
117
118
|
# immediately after that closest node
|
@@ -120,7 +121,9 @@ module RubyLsp
|
|
120
121
|
distance <= 0 ? Float::INFINITY : distance
|
121
122
|
end #: as !nil
|
122
123
|
|
123
|
-
|
124
|
+
if closest_node.is_a?(Prism::MissingNode)
|
125
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
126
|
+
end
|
124
127
|
|
125
128
|
closest_node_loc = closest_node.location
|
126
129
|
# If the parent expression is a single line block, then we have to extract it inside of the one-line block
|
@@ -151,7 +154,9 @@ module RubyLsp
|
|
151
154
|
lines = @document.source.lines
|
152
155
|
|
153
156
|
indentation_line = lines[indentation_line_number]
|
154
|
-
|
157
|
+
unless indentation_line
|
158
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
159
|
+
end
|
155
160
|
|
156
161
|
indentation = indentation_line[/\A */] #: as !nil
|
157
162
|
.size
|
@@ -162,7 +167,9 @@ module RubyLsp
|
|
162
167
|
}
|
163
168
|
|
164
169
|
line = lines[target_line]
|
165
|
-
|
170
|
+
unless line
|
171
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
172
|
+
end
|
166
173
|
|
167
174
|
variable_source = if line.strip.empty?
|
168
175
|
"\n#{" " * indentation}#{NEW_VARIABLE_NAME} = #{extracted_source}"
|
@@ -190,10 +197,10 @@ module RubyLsp
|
|
190
197
|
)
|
191
198
|
end
|
192
199
|
|
193
|
-
#: -> (Interface::CodeAction
|
200
|
+
#: -> (Interface::CodeAction)
|
194
201
|
def refactor_method
|
195
202
|
source_range = @code_action.dig(:data, :range)
|
196
|
-
|
203
|
+
raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
|
197
204
|
|
198
205
|
start_index, end_index = @document.find_index_by_position(source_range[:start], source_range[:end])
|
199
206
|
extracted_source = @document.source[start_index...end_index] #: as !nil
|
@@ -206,11 +213,15 @@ module RubyLsp
|
|
206
213
|
code_units_cache: @document.code_units_cache,
|
207
214
|
)
|
208
215
|
closest_node = node_context.node
|
209
|
-
|
216
|
+
unless closest_node
|
217
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
218
|
+
end
|
210
219
|
|
211
220
|
target_range = if closest_node.is_a?(Prism::DefNode)
|
212
221
|
end_keyword_loc = closest_node.end_keyword_loc
|
213
|
-
|
222
|
+
unless end_keyword_loc
|
223
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
224
|
+
end
|
214
225
|
|
215
226
|
end_line = end_keyword_loc.end_line - 1
|
216
227
|
character = end_keyword_loc.end_column
|
@@ -331,7 +342,7 @@ module RubyLsp
|
|
331
342
|
indentation ? body_content.gsub(";", "\n") : "#{body_content.gsub("\n", ";")} "
|
332
343
|
end
|
333
344
|
|
334
|
-
#: -> (Interface::CodeAction
|
345
|
+
#: -> (Interface::CodeAction)
|
335
346
|
def create_attribute_accessor
|
336
347
|
source_range = @code_action.dig(:data, :range)
|
337
348
|
|
@@ -349,20 +360,12 @@ module RubyLsp
|
|
349
360
|
)
|
350
361
|
node = node_context.node
|
351
362
|
|
352
|
-
|
363
|
+
unless CodeActions::INSTANCE_VARIABLE_NODES.include?(node.class)
|
364
|
+
raise EmptySelectionError, "Invalid selection for refactor"
|
365
|
+
end
|
353
366
|
end
|
354
367
|
|
355
|
-
node =
|
356
|
-
node,
|
357
|
-
T.any(
|
358
|
-
Prism::InstanceVariableAndWriteNode,
|
359
|
-
Prism::InstanceVariableOperatorWriteNode,
|
360
|
-
Prism::InstanceVariableOrWriteNode,
|
361
|
-
Prism::InstanceVariableReadNode,
|
362
|
-
Prism::InstanceVariableTargetNode,
|
363
|
-
Prism::InstanceVariableWriteNode,
|
364
|
-
),
|
365
|
-
)
|
368
|
+
node = node #: as Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode # rubocop:disable Layout/LineLength
|
366
369
|
|
367
370
|
node_context = @document.locate_node(
|
368
371
|
{
|
@@ -376,7 +379,9 @@ module RubyLsp
|
|
376
379
|
],
|
377
380
|
)
|
378
381
|
closest_node = node_context.node
|
379
|
-
|
382
|
+
if closest_node.nil?
|
383
|
+
raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
|
384
|
+
end
|
380
385
|
|
381
386
|
attribute_name = node.name[1..]
|
382
387
|
indentation = " " * (closest_node.location.start_column + 2)
|
@@ -14,26 +14,38 @@ module RubyLsp
|
|
14
14
|
class << self
|
15
15
|
#: -> Interface::CodeLensOptions
|
16
16
|
def provider
|
17
|
-
Interface::CodeLensOptions.new(resolve_provider:
|
17
|
+
Interface::CodeLensOptions.new(resolve_provider: true)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
#: (GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
22
22
|
def initialize(global_state, uri, dispatcher)
|
23
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
23
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
24
24
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens]
|
25
25
|
super()
|
26
|
-
|
26
|
+
|
27
|
+
@test_builder = ResponseBuilders::TestCollection.new #: ResponseBuilders::TestCollection
|
28
|
+
|
29
|
+
if global_state.enabled_feature?(:fullTestDiscovery)
|
30
|
+
Listeners::TestStyle.new(@test_builder, global_state, dispatcher, uri)
|
31
|
+
Listeners::SpecStyle.new(@test_builder, global_state, dispatcher, uri)
|
32
|
+
else
|
33
|
+
Listeners::CodeLens.new(@response_builder, global_state, uri, dispatcher)
|
34
|
+
end
|
27
35
|
|
28
36
|
Addon.addons.each do |addon|
|
29
37
|
addon.create_code_lens_listener(@response_builder, uri, dispatcher)
|
38
|
+
|
39
|
+
if global_state.enabled_feature?(:fullTestDiscovery)
|
40
|
+
addon.create_discover_tests_listener(@test_builder, dispatcher, uri)
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
33
45
|
# @override
|
34
46
|
#: -> Array[Interface::CodeLens]
|
35
47
|
def perform
|
36
|
-
@response_builder.response
|
48
|
+
@response_builder.response + @test_builder.code_lens
|
37
49
|
end
|
38
50
|
end
|
39
51
|
end
|
@@ -21,7 +21,7 @@ module RubyLsp
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] params,
|
24
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] params, SorbetLevel sorbet_level, Prism::Dispatcher dispatcher) -> void
|
25
25
|
def initialize(document, global_state, params, sorbet_level, dispatcher)
|
26
26
|
super()
|
27
27
|
@target = nil #: Prism::Node?
|
@@ -60,7 +60,7 @@ module RubyLsp
|
|
60
60
|
],
|
61
61
|
code_units_cache: document.code_units_cache,
|
62
62
|
)
|
63
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
63
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
64
64
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem]
|
65
65
|
|
66
66
|
Listeners::Completion.new(
|
@@ -9,14 +9,11 @@ module RubyLsp
|
|
9
9
|
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_definition) jumps to the
|
10
10
|
# definition of the symbol under the cursor.
|
11
11
|
class Definition < Request
|
12
|
-
|
13
|
-
|
14
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
|
12
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
|
15
13
|
def initialize(document, global_state, position, dispatcher, sorbet_level)
|
16
14
|
super()
|
17
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
18
|
-
|
19
|
-
].new #: ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)]
|
15
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
16
|
+
.new #: ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)]
|
20
17
|
@dispatcher = dispatcher
|
21
18
|
|
22
19
|
char_position, _ = document.find_index_by_position(position)
|
@@ -25,7 +25,7 @@ module RubyLsp
|
|
25
25
|
code_units_cache: document.code_units_cache,
|
26
26
|
)
|
27
27
|
|
28
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
28
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
29
29
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight]
|
30
30
|
Listeners::DocumentHighlight.new(
|
31
31
|
@response_builder,
|
@@ -19,7 +19,7 @@ module RubyLsp
|
|
19
19
|
#: (URI::Generic uri, Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
|
20
20
|
def initialize(uri, comments, dispatcher)
|
21
21
|
super()
|
22
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
22
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
23
23
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentLink]
|
24
24
|
Listeners::DocumentLink.new(@response_builder, uri, comments, dispatcher)
|
25
25
|
end
|
@@ -18,7 +18,7 @@ module RubyLsp
|
|
18
18
|
#: (Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
|
19
19
|
def initialize(comments, dispatcher)
|
20
20
|
super()
|
21
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
21
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
22
22
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange]
|
23
23
|
@listener = Listeners::FoldingRanges.new(@response_builder, comments, dispatcher) #: Listeners::FoldingRanges
|
24
24
|
end
|
@@ -8,8 +8,6 @@ module RubyLsp
|
|
8
8
|
# that navigates to the relevant file for the current document.
|
9
9
|
# Currently, it supports source code file <> test file navigation.
|
10
10
|
class GoToRelevantFile < Request
|
11
|
-
extend T::Sig
|
12
|
-
|
13
11
|
TEST_KEYWORDS = ["test", "spec", "integration_test"]
|
14
12
|
|
15
13
|
TEST_PREFIX_PATTERN = /^(#{TEST_KEYWORDS.join("_|")}_)/
|
@@ -7,9 +7,8 @@ module RubyLsp
|
|
7
7
|
module Requests
|
8
8
|
# The [hover request](https://microsoft.github.io/language-server-protocol/specification#textDocument_hover)
|
9
9
|
# displays the documentation for the symbol currently under the cursor.
|
10
|
+
#: [ResponseType = Interface::Hover?]
|
10
11
|
class Hover < Request
|
11
|
-
extend T::Generic
|
12
|
-
|
13
12
|
class << self
|
14
13
|
#: -> Interface::HoverOptions
|
15
14
|
def provider
|
@@ -17,9 +16,7 @@ module RubyLsp
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
|
19
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
|
23
20
|
def initialize(document, global_state, position, dispatcher, sorbet_level)
|
24
21
|
super()
|
25
22
|
|
@@ -20,7 +20,7 @@ module RubyLsp
|
|
20
20
|
def initialize(document, hints_configuration, dispatcher)
|
21
21
|
super()
|
22
22
|
|
23
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
23
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
24
24
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint]
|
25
25
|
Listeners::InlayHints.new(@response_builder, hints_configuration, dispatcher)
|
26
26
|
end
|
@@ -55,22 +55,7 @@ module RubyLsp
|
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
|
-
target =
|
59
|
-
target,
|
60
|
-
T.any(
|
61
|
-
Prism::ConstantReadNode,
|
62
|
-
Prism::ConstantPathNode,
|
63
|
-
Prism::ConstantPathTargetNode,
|
64
|
-
Prism::InstanceVariableAndWriteNode,
|
65
|
-
Prism::InstanceVariableOperatorWriteNode,
|
66
|
-
Prism::InstanceVariableOrWriteNode,
|
67
|
-
Prism::InstanceVariableReadNode,
|
68
|
-
Prism::InstanceVariableTargetNode,
|
69
|
-
Prism::InstanceVariableWriteNode,
|
70
|
-
Prism::CallNode,
|
71
|
-
Prism::DefNode,
|
72
|
-
),
|
73
|
-
)
|
58
|
+
target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode | Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode | Prism::CallNode | Prism::DefNode, # rubocop:disable Layout/LineLength
|
74
59
|
|
75
60
|
reference_target = create_reference_target(target, node_context)
|
76
61
|
return @locations unless reference_target
|
@@ -51,10 +51,7 @@ module RubyLsp
|
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
54
|
-
target =
|
55
|
-
target,
|
56
|
-
T.any(Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode),
|
57
|
-
)
|
54
|
+
target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode
|
58
55
|
|
59
56
|
name = RubyIndexer::Index.constant_name(target)
|
60
57
|
return unless name
|
@@ -4,7 +4,7 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
6
|
class Request
|
7
|
-
extend T::
|
7
|
+
extend T::Helpers
|
8
8
|
extend T::Sig
|
9
9
|
|
10
10
|
class InvalidFormatter < StandardError; end
|
@@ -60,7 +60,8 @@ module RubyLsp
|
|
60
60
|
return target unless parent.is_a?(Prism::ConstantPathNode)
|
61
61
|
|
62
62
|
target = parent #: Prism::Node
|
63
|
-
parent =
|
63
|
+
parent = target #: as Prism::ConstantPathNode
|
64
|
+
.parent #: Prism::Node?
|
64
65
|
|
65
66
|
while parent && cover?(parent.location, position)
|
66
67
|
target = parent
|
@@ -74,7 +74,7 @@ module RubyLsp
|
|
74
74
|
@result_id = 0 #: Integer
|
75
75
|
@mutex = Mutex.new #: Mutex
|
76
76
|
|
77
|
-
#: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range:
|
77
|
+
#: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range: Range[Integer]?) -> void
|
78
78
|
def initialize(global_state, dispatcher, document, previous_result_id, range: nil)
|
79
79
|
super()
|
80
80
|
|
@@ -19,7 +19,7 @@ module RubyLsp
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher,
|
22
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
|
23
23
|
def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
|
24
24
|
super()
|
25
25
|
|
@@ -5,7 +5,7 @@ module RubyLsp
|
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
7
|
class Annotation
|
8
|
-
#: (arity: (Integer |
|
8
|
+
#: (arity: (Integer | Range[Integer]), ?receiver: bool) -> void
|
9
9
|
def initialize(arity:, receiver: false)
|
10
10
|
@arity = arity
|
11
11
|
@receiver = receiver
|
@@ -159,11 +159,6 @@ module RubyLsp
|
|
159
159
|
Constant::SymbolKind::FIELD
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
163
|
-
#: (RubyDocument::SorbetLevel sorbet_level) -> bool
|
164
|
-
def sorbet_level_true_or_higher?(sorbet_level)
|
165
|
-
sorbet_level == RubyDocument::SorbetLevel::True || sorbet_level == RubyDocument::SorbetLevel::Strict
|
166
|
-
end
|
167
162
|
end
|
168
163
|
end
|
169
164
|
end
|
@@ -13,7 +13,13 @@ module RubyLsp
|
|
13
13
|
#: String
|
14
14
|
attr_reader :id, :label
|
15
15
|
|
16
|
-
#:
|
16
|
+
#: URI::Generic
|
17
|
+
attr_reader :uri
|
18
|
+
|
19
|
+
#: Interface::Range
|
20
|
+
attr_reader :range
|
21
|
+
|
22
|
+
#: (String id, String label, URI::Generic uri, Interface::Range range, framework: Symbol) -> void
|
17
23
|
def initialize(id, label, uri, range, framework:)
|
18
24
|
@id = id
|
19
25
|
@label = label
|
@@ -3,9 +3,8 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
|
+
#: [ResponseType = Array[Interface::DocumentSymbol]]
|
6
7
|
class DocumentSymbol < ResponseBuilder
|
7
|
-
ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }
|
8
|
-
|
9
8
|
class SymbolHierarchyRoot
|
10
9
|
#: Array[Interface::DocumentSymbol]
|
11
10
|
attr_reader :children
|
@@ -32,7 +31,7 @@ module RubyLsp
|
|
32
31
|
#: -> Interface::DocumentSymbol?
|
33
32
|
def pop
|
34
33
|
if @stack.size > 1
|
35
|
-
|
34
|
+
@stack.pop #: as Interface::DocumentSymbol
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
|
+
#: [ResponseType = Interface::SemanticTokens]
|
6
7
|
class SemanticHighlighting < ResponseBuilder
|
7
8
|
class UndefinedTokenType < StandardError; end
|
8
9
|
|
@@ -45,8 +46,6 @@ module RubyLsp
|
|
45
46
|
default_library: 9,
|
46
47
|
}.freeze #: Hash[Symbol, Integer]
|
47
48
|
|
48
|
-
ResponseType = type_member { { fixed: Interface::SemanticTokens } }
|
49
|
-
|
50
49
|
#: ((^(Integer arg0) -> Integer | Prism::CodeUnitsCache) code_units_cache) -> void
|
51
50
|
def initialize(code_units_cache)
|
52
51
|
super()
|
@@ -3,15 +3,16 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
|
+
#: [ResponseType = Requests::Support::TestItem]
|
6
7
|
class TestCollection < ResponseBuilder
|
7
|
-
|
8
|
-
|
9
|
-
ResponseType = type_member { { fixed: Requests::Support::TestItem } }
|
8
|
+
#: Array[Interface::CodeLens]
|
9
|
+
attr_reader :code_lens
|
10
10
|
|
11
11
|
#: -> void
|
12
12
|
def initialize
|
13
13
|
super
|
14
14
|
@items = {} #: Hash[String, ResponseType]
|
15
|
+
@code_lens = [] #: Array[Interface::CodeLens]
|
15
16
|
end
|
16
17
|
|
17
18
|
#: (ResponseType item) -> void
|
@@ -19,6 +20,31 @@ module RubyLsp
|
|
19
20
|
@items[item.id] = item
|
20
21
|
end
|
21
22
|
|
23
|
+
#: (ResponseType item) -> void
|
24
|
+
def add_code_lens(item)
|
25
|
+
arguments = [item.uri.to_standardized_path, item.id]
|
26
|
+
start = item.range.start
|
27
|
+
range = Interface::Range.new(
|
28
|
+
start: start,
|
29
|
+
end: Interface::Position.new(line: start.line, character: start.character + 1),
|
30
|
+
)
|
31
|
+
|
32
|
+
@code_lens << Interface::CodeLens.new(
|
33
|
+
range: range,
|
34
|
+
data: { arguments: arguments, kind: "run_test" },
|
35
|
+
)
|
36
|
+
|
37
|
+
@code_lens << Interface::CodeLens.new(
|
38
|
+
range: range,
|
39
|
+
data: { arguments: arguments, kind: "run_test_in_terminal" },
|
40
|
+
)
|
41
|
+
|
42
|
+
@code_lens << Interface::CodeLens.new(
|
43
|
+
range: range,
|
44
|
+
data: { arguments: arguments, kind: "debug_test" },
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
22
48
|
#: (String id) -> ResponseType?
|
23
49
|
def [](id)
|
24
50
|
@items[id]
|