ruby-lsp 0.23.23 → 0.24.0
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/exe/ruby-lsp-launcher +7 -2
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +7 -1
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +1 -4
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +6 -18
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +16 -5
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +12 -8
- data/lib/ruby_indexer/test/index_test.rb +24 -0
- data/lib/ruby_indexer/test/instance_variables_test.rb +24 -0
- data/lib/ruby_indexer/test/method_test.rb +17 -0
- data/lib/ruby_indexer/test/reference_finder_test.rb +79 -14
- data/lib/ruby_lsp/addon.rb +9 -9
- data/lib/ruby_lsp/base_server.rb +5 -7
- data/lib/ruby_lsp/document.rb +36 -25
- data/lib/ruby_lsp/erb_document.rb +8 -3
- data/lib/ruby_lsp/listeners/completion.rb +9 -1
- data/lib/ruby_lsp/listeners/spec_style.rb +7 -8
- data/lib/ruby_lsp/listeners/test_discovery.rb +18 -15
- data/lib/ruby_lsp/listeners/test_style.rb +7 -8
- data/lib/ruby_lsp/requests/code_action_resolve.rb +2 -2
- data/lib/ruby_lsp/requests/completion.rb +1 -1
- data/lib/ruby_lsp/requests/definition.rb +1 -1
- data/lib/ruby_lsp/requests/discover_tests.rb +2 -2
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/hover.rb +1 -1
- data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +6 -2
- data/lib/ruby_lsp/requests/rename.rb +8 -6
- data/lib/ruby_lsp/requests/request.rb +3 -6
- data/lib/ruby_lsp/requests/selection_ranges.rb +1 -1
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -1
- data/lib/ruby_lsp/requests/signature_help.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +1 -3
- data/lib/ruby_lsp/requests/support/formatter.rb +8 -13
- data/lib/ruby_lsp/response_builders/response_builder.rb +3 -5
- data/lib/ruby_lsp/ruby_document.rb +9 -4
- data/lib/ruby_lsp/server.rb +9 -30
- data/lib/ruby_lsp/setup_bundler.rb +3 -3
- data/lib/ruby_lsp/test_helper.rb +1 -4
- data/lib/ruby_lsp/utils.rb +3 -6
- metadata +1 -1
@@ -516,6 +516,14 @@ module RubyLsp
|
|
516
516
|
|
517
517
|
entry_name = entry.name
|
518
518
|
owner_name = entry.owner&.name
|
519
|
+
new_text = entry_name
|
520
|
+
|
521
|
+
if entry_name.end_with?("=")
|
522
|
+
method_name = entry_name.delete_suffix("=")
|
523
|
+
|
524
|
+
# For writer methods, format as assignment and prefix "self." when no receiver is specified
|
525
|
+
new_text = node.receiver.nil? ? "self.#{method_name} = " : "#{method_name} = "
|
526
|
+
end
|
519
527
|
|
520
528
|
label_details = Interface::CompletionItemLabelDetails.new(
|
521
529
|
description: entry.file_name,
|
@@ -525,7 +533,7 @@ module RubyLsp
|
|
525
533
|
label: entry_name,
|
526
534
|
filter_text: entry_name,
|
527
535
|
label_details: label_details,
|
528
|
-
text_edit: Interface::TextEdit.new(range: range, new_text:
|
536
|
+
text_edit: Interface::TextEdit.new(range: range, new_text: new_text),
|
529
537
|
kind: Constant::CompletionItemKind::METHOD,
|
530
538
|
data: {
|
531
539
|
owner_name: owner_name,
|
@@ -19,21 +19,20 @@ module RubyLsp
|
|
19
19
|
|
20
20
|
#: (ResponseBuilders::TestCollection, GlobalState, Prism::Dispatcher, URI::Generic) -> void
|
21
21
|
def initialize(response_builder, global_state, dispatcher, uri)
|
22
|
-
super
|
22
|
+
super(response_builder, global_state, uri)
|
23
23
|
|
24
24
|
@spec_group_id_stack = [] #: Array[Group?]
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
# Common handlers registered in parent class
|
26
|
+
register_events(
|
27
|
+
dispatcher,
|
29
28
|
:on_class_node_enter,
|
30
|
-
:on_call_node_enter,
|
29
|
+
:on_call_node_enter,
|
31
30
|
:on_call_node_leave,
|
32
31
|
)
|
33
32
|
end
|
34
33
|
|
35
34
|
#: (Prism::ClassNode) -> void
|
36
|
-
def on_class_node_enter(node)
|
35
|
+
def on_class_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
37
36
|
with_test_ancestor_tracking(node) do |name, ancestors|
|
38
37
|
@spec_group_id_stack << (ancestors.include?("Minitest::Spec") ? ClassGroup.new(name) : nil)
|
39
38
|
end
|
@@ -58,7 +57,7 @@ module RubyLsp
|
|
58
57
|
end
|
59
58
|
|
60
59
|
#: (Prism::CallNode) -> void
|
61
|
-
def on_call_node_enter(node)
|
60
|
+
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
62
61
|
return unless in_spec_context?
|
63
62
|
|
64
63
|
case node.name
|
@@ -70,7 +69,7 @@ module RubyLsp
|
|
70
69
|
end
|
71
70
|
|
72
71
|
#: (Prism::CallNode) -> void
|
73
|
-
def on_call_node_leave(node)
|
72
|
+
def on_call_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
74
73
|
return unless node.name == :describe && !node.receiver
|
75
74
|
|
76
75
|
current_group = @spec_group_id_stack.last
|
@@ -3,32 +3,23 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Listeners
|
6
|
+
# @abstract
|
6
7
|
class TestDiscovery
|
7
|
-
extend T::Helpers
|
8
|
-
abstract!
|
9
|
-
|
10
8
|
include Requests::Support::Common
|
11
9
|
|
12
10
|
DYNAMIC_REFERENCE_MARKER = "<dynamic_reference>"
|
13
11
|
|
14
|
-
#: (ResponseBuilders::TestCollection response_builder, GlobalState global_state,
|
15
|
-
def initialize(response_builder, global_state,
|
12
|
+
#: (ResponseBuilders::TestCollection response_builder, GlobalState global_state, URI::Generic uri) -> void
|
13
|
+
def initialize(response_builder, global_state, uri)
|
16
14
|
@response_builder = response_builder
|
17
15
|
@uri = uri
|
18
16
|
@index = global_state.index #: RubyIndexer::Index
|
19
17
|
@visibility_stack = [:public] #: Array[Symbol]
|
20
18
|
@nesting = [] #: Array[String]
|
21
|
-
|
22
|
-
dispatcher.register(
|
23
|
-
self,
|
24
|
-
:on_class_node_leave,
|
25
|
-
:on_module_node_enter,
|
26
|
-
:on_module_node_leave,
|
27
|
-
)
|
28
19
|
end
|
29
20
|
|
30
21
|
#: (Prism::ModuleNode node) -> void
|
31
|
-
def on_module_node_enter(node)
|
22
|
+
def on_module_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
32
23
|
@visibility_stack << :public
|
33
24
|
|
34
25
|
name = constant_name(node.constant_path)
|
@@ -38,19 +29,31 @@ module RubyLsp
|
|
38
29
|
end
|
39
30
|
|
40
31
|
#: (Prism::ModuleNode node) -> void
|
41
|
-
def on_module_node_leave(node)
|
32
|
+
def on_module_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
42
33
|
@visibility_stack.pop
|
43
34
|
@nesting.pop
|
44
35
|
end
|
45
36
|
|
46
37
|
#: (Prism::ClassNode node) -> void
|
47
|
-
def on_class_node_leave(node)
|
38
|
+
def on_class_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
48
39
|
@visibility_stack.pop
|
49
40
|
@nesting.pop
|
50
41
|
end
|
51
42
|
|
52
43
|
private
|
53
44
|
|
45
|
+
#: (Prism::Dispatcher, *Symbol) -> void
|
46
|
+
def register_events(dispatcher, *events)
|
47
|
+
unique_events = events.dup.push(
|
48
|
+
:on_class_node_leave,
|
49
|
+
:on_module_node_enter,
|
50
|
+
:on_module_node_leave,
|
51
|
+
)
|
52
|
+
|
53
|
+
unique_events.uniq!
|
54
|
+
dispatcher.register(self, *unique_events)
|
55
|
+
end
|
56
|
+
|
54
57
|
#: (String? name) -> String
|
55
58
|
def calc_fully_qualified_name(name)
|
56
59
|
RubyIndexer::Index.actual_nesting(@nesting, name).join("::")
|
@@ -153,14 +153,13 @@ module RubyLsp
|
|
153
153
|
|
154
154
|
#: (ResponseBuilders::TestCollection, GlobalState, Prism::Dispatcher, URI::Generic) -> void
|
155
155
|
def initialize(response_builder, global_state, dispatcher, uri)
|
156
|
-
super
|
156
|
+
super(response_builder, global_state, uri)
|
157
157
|
|
158
158
|
@framework = :minitest #: Symbol
|
159
159
|
@parent_stack = [@response_builder] #: Array[(Requests::Support::TestItem | ResponseBuilders::TestCollection)?]
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
# Common handlers registered in parent class
|
161
|
+
register_events(
|
162
|
+
dispatcher,
|
164
163
|
:on_class_node_enter,
|
165
164
|
:on_def_node_enter,
|
166
165
|
:on_call_node_enter,
|
@@ -169,7 +168,7 @@ module RubyLsp
|
|
169
168
|
end
|
170
169
|
|
171
170
|
#: (Prism::ClassNode node) -> void
|
172
|
-
def on_class_node_enter(node)
|
171
|
+
def on_class_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
173
172
|
with_test_ancestor_tracking(node) do |name, ancestors|
|
174
173
|
@framework = :test_unit if ancestors.include?("Test::Unit::TestCase")
|
175
174
|
|
@@ -210,7 +209,7 @@ module RubyLsp
|
|
210
209
|
end
|
211
210
|
|
212
211
|
#: (Prism::DefNode node) -> void
|
213
|
-
def on_def_node_enter(node)
|
212
|
+
def on_def_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
214
213
|
return if @visibility_stack.last != :public
|
215
214
|
|
216
215
|
name = node.name.to_s
|
@@ -232,7 +231,7 @@ module RubyLsp
|
|
232
231
|
end
|
233
232
|
|
234
233
|
#: (Prism::CallNode node) -> void
|
235
|
-
def on_call_node_enter(node)
|
234
|
+
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
236
235
|
name = node.name
|
237
236
|
return unless ACCESS_MODIFIERS.include?(name)
|
238
237
|
|
@@ -240,7 +239,7 @@ module RubyLsp
|
|
240
239
|
end
|
241
240
|
|
242
241
|
#: (Prism::CallNode node) -> void
|
243
|
-
def on_call_node_leave(node)
|
242
|
+
def on_call_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
244
243
|
name = node.name
|
245
244
|
return unless ACCESS_MODIFIERS.include?(name)
|
246
245
|
return unless node.arguments&.arguments
|
@@ -100,7 +100,7 @@ module RubyLsp
|
|
100
100
|
|
101
101
|
# Find the closest statements node, so that we place the refactor in a valid position
|
102
102
|
node_context = RubyDocument
|
103
|
-
.locate(@document.
|
103
|
+
.locate(@document.ast,
|
104
104
|
start_index,
|
105
105
|
node_types: [
|
106
106
|
Prism::StatementsNode,
|
@@ -207,7 +207,7 @@ module RubyLsp
|
|
207
207
|
|
208
208
|
# Find the closest method declaration node, so that we place the refactor in a valid position
|
209
209
|
node_context = RubyDocument.locate(
|
210
|
-
@document.
|
210
|
+
@document.ast,
|
211
211
|
start_index,
|
212
212
|
node_types: [Prism::DefNode],
|
213
213
|
code_units_cache: @document.code_units_cache,
|
@@ -43,7 +43,7 @@ module RubyLsp
|
|
43
43
|
addon.create_discover_tests_listener(@response_builder, @dispatcher, @document.uri)
|
44
44
|
end
|
45
45
|
|
46
|
-
@dispatcher.visit(@document.
|
46
|
+
@dispatcher.visit(@document.ast)
|
47
47
|
else
|
48
48
|
@global_state.synchronize do
|
49
49
|
RubyIndexer::DeclarationListener.new(
|
@@ -64,7 +64,7 @@ module RubyLsp
|
|
64
64
|
# Dispatch the events both for indexing the test file and discovering the tests. The order here is
|
65
65
|
# important because we need the index to be aware of the existing classes/modules/methods before the test
|
66
66
|
# listeners can do their work
|
67
|
-
@dispatcher.visit(@document.
|
67
|
+
@dispatcher.visit(@document.ast)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -24,7 +24,7 @@ module RubyLsp
|
|
24
24
|
delegate_request_if_needed!(global_state, document, char_position)
|
25
25
|
|
26
26
|
node_context = RubyDocument.locate(
|
27
|
-
document.
|
27
|
+
document.ast,
|
28
28
|
char_position,
|
29
29
|
node_types: Listeners::Hover::ALLOWED_TARGETS,
|
30
30
|
code_units_cache: document.code_units_cache,
|
@@ -22,7 +22,7 @@ module RubyLsp
|
|
22
22
|
char_position, _ = @document.find_index_by_position(@position)
|
23
23
|
|
24
24
|
node_context = RubyDocument.locate(
|
25
|
-
@document.
|
25
|
+
@document.ast,
|
26
26
|
char_position,
|
27
27
|
node_types: [Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode],
|
28
28
|
code_units_cache: @document.code_units_cache,
|
@@ -26,7 +26,7 @@ module RubyLsp
|
|
26
26
|
char_position, _ = @document.find_index_by_position(position)
|
27
27
|
|
28
28
|
node_context = RubyDocument.locate(
|
29
|
-
@document.
|
29
|
+
@document.ast,
|
30
30
|
char_position,
|
31
31
|
node_types: [
|
32
32
|
Prism::ConstantReadNode,
|
@@ -101,7 +101,11 @@ module RubyLsp
|
|
101
101
|
Prism::InstanceVariableReadNode,
|
102
102
|
Prism::InstanceVariableTargetNode,
|
103
103
|
Prism::InstanceVariableWriteNode
|
104
|
-
|
104
|
+
receiver_type = @global_state.type_inferrer.infer_receiver_type(node_context)
|
105
|
+
return unless receiver_type
|
106
|
+
|
107
|
+
ancestors = @global_state.index.linearized_ancestors_of(receiver_type.name)
|
108
|
+
RubyIndexer::ReferenceFinder::InstanceVariableTarget.new(target_node.name.to_s, ancestors)
|
105
109
|
when Prism::CallNode, Prism::DefNode
|
106
110
|
RubyIndexer::ReferenceFinder::MethodTarget.new(target_node.name.to_s)
|
107
111
|
end
|
@@ -34,7 +34,7 @@ module RubyLsp
|
|
34
34
|
char_position, _ = @document.find_index_by_position(@position)
|
35
35
|
|
36
36
|
node_context = RubyDocument.locate(
|
37
|
-
@document.
|
37
|
+
@document.ast,
|
38
38
|
char_position,
|
39
39
|
node_types: [Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode],
|
40
40
|
code_units_cache: @document.code_units_cache,
|
@@ -136,25 +136,27 @@ module RubyLsp
|
|
136
136
|
next if @store.key?(uri)
|
137
137
|
|
138
138
|
parse_result = Prism.parse_file(path)
|
139
|
-
edits = collect_changes(target, parse_result, name, uri)
|
139
|
+
edits = collect_changes(target, parse_result.value, name, uri)
|
140
140
|
changes[uri.to_s] = edits unless edits.empty?
|
141
141
|
rescue Errno::EISDIR, Errno::ENOENT
|
142
142
|
# If `path` is a directory, just ignore it and continue. If the file doesn't exist, then we also ignore it.
|
143
143
|
end
|
144
144
|
|
145
145
|
@store.each do |uri, document|
|
146
|
-
|
146
|
+
next unless document.is_a?(RubyDocument) || document.is_a?(ERBDocument)
|
147
|
+
|
148
|
+
edits = collect_changes(target, document.ast, name, document.uri)
|
147
149
|
changes[uri] = edits unless edits.empty?
|
148
150
|
end
|
149
151
|
|
150
152
|
changes
|
151
153
|
end
|
152
154
|
|
153
|
-
#: (RubyIndexer::ReferenceFinder::Target target, Prism::
|
154
|
-
def collect_changes(target,
|
155
|
+
#: (RubyIndexer::ReferenceFinder::Target target, Prism::Node ast, String name, URI::Generic uri) -> Array[Interface::TextEdit]
|
156
|
+
def collect_changes(target, ast, name, uri)
|
155
157
|
dispatcher = Prism::Dispatcher.new
|
156
158
|
finder = RubyIndexer::ReferenceFinder.new(target, @global_state.index, dispatcher, uri)
|
157
|
-
dispatcher.visit(
|
159
|
+
dispatcher.visit(ast)
|
158
160
|
|
159
161
|
finder.references.map do |reference|
|
160
162
|
adjust_reference_for_edit(name, reference)
|
@@ -3,15 +3,12 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
+
# @abstract
|
6
7
|
class Request
|
7
|
-
extend T::Helpers
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
class InvalidFormatter < StandardError; end
|
11
9
|
|
12
|
-
abstract
|
13
|
-
|
14
|
-
sig { abstract.returns(T.anything) }
|
10
|
+
# @abstract
|
11
|
+
#: -> untyped
|
15
12
|
def perform; end
|
16
13
|
|
17
14
|
private
|
@@ -27,7 +27,7 @@ module RubyLsp
|
|
27
27
|
delegate_request_if_needed!(global_state, document, char_position)
|
28
28
|
|
29
29
|
node_context = RubyDocument.locate(
|
30
|
-
document.
|
30
|
+
document.ast,
|
31
31
|
char_position,
|
32
32
|
node_types: [Prism::CallNode],
|
33
33
|
code_units_cache: document.code_units_cache,
|
@@ -4,13 +4,11 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
|
+
# @requires_ancestor: Kernel
|
7
8
|
module Common
|
8
9
|
# WARNING: Methods in this class may be used by Ruby LSP add-ons such as
|
9
10
|
# https://github.com/Shopify/ruby-lsp-rails, or add-ons by created by developers outside of Shopify, so be
|
10
11
|
# cautious of changing anything.
|
11
|
-
extend T::Helpers
|
12
|
-
|
13
|
-
requires_ancestor { Kernel }
|
14
12
|
|
15
13
|
#: (Prism::Node node) -> Interface::Range
|
16
14
|
def range_from_node(node)
|
@@ -4,24 +4,19 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
|
+
# Empty module to avoid the runtime component. This is an interface defined in sorbet/rbi/shims/ruby_lsp.rbi
|
8
|
+
# @interface
|
7
9
|
module Formatter
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
interface!
|
12
|
-
|
13
|
-
sig { abstract.params(uri: URI::Generic, document: RubyDocument).returns(T.nilable(String)) }
|
10
|
+
# @abstract
|
11
|
+
#: (URI::Generic, RubyLsp::RubyDocument) -> String?
|
14
12
|
def run_formatting(uri, document); end
|
15
13
|
|
16
|
-
|
14
|
+
# @abstract
|
15
|
+
#: (URI::Generic, String, Integer) -> String?
|
17
16
|
def run_range_formatting(uri, source, base_indentation); end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
uri: URI::Generic,
|
22
|
-
document: RubyDocument,
|
23
|
-
).returns(T.nilable(T::Array[Interface::Diagnostic]))
|
24
|
-
end
|
18
|
+
# @abstract
|
19
|
+
#: (URI::Generic, RubyLsp::RubyDocument) -> Array[Interface::Diagnostic]?
|
25
20
|
def run_diagnostic(uri, document); end
|
26
21
|
end
|
27
22
|
end
|
@@ -3,14 +3,12 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
|
+
# @abstract
|
6
7
|
class ResponseBuilder
|
7
|
-
extend T::Sig
|
8
|
-
extend T::Helpers
|
9
8
|
extend T::Generic
|
10
9
|
|
11
|
-
abstract
|
12
|
-
|
13
|
-
sig { abstract.returns(T.anything) }
|
10
|
+
# @abstract
|
11
|
+
#: -> top
|
14
12
|
def response; end
|
15
13
|
end
|
16
14
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module RubyLsp
|
5
|
-
#: [ParseResultType = Prism::
|
5
|
+
#: [ParseResultType = Prism::ParseLexResult]
|
6
6
|
class RubyDocument < Document
|
7
7
|
METHODS_THAT_CHANGE_DECLARATIONS = [
|
8
8
|
:private_constant,
|
@@ -129,11 +129,16 @@ module RubyLsp
|
|
129
129
|
return false unless @needs_parsing
|
130
130
|
|
131
131
|
@needs_parsing = false
|
132
|
-
@parse_result = Prism.
|
132
|
+
@parse_result = Prism.parse_lex(@source)
|
133
133
|
@code_units_cache = @parse_result.code_units_cache(@encoding)
|
134
134
|
true
|
135
135
|
end
|
136
136
|
|
137
|
+
#: -> Prism::ProgramNode
|
138
|
+
def ast
|
139
|
+
@parse_result.value.first
|
140
|
+
end
|
141
|
+
|
137
142
|
# @override
|
138
143
|
#: -> bool
|
139
144
|
def syntax_error?
|
@@ -151,7 +156,7 @@ module RubyLsp
|
|
151
156
|
start_position, end_position = find_index_by_position(range[:start], range[:end])
|
152
157
|
|
153
158
|
desired_range = (start_position...end_position)
|
154
|
-
queue =
|
159
|
+
queue = ast.child_nodes.compact #: Array[Prism::Node?]
|
155
160
|
|
156
161
|
until queue.empty?
|
157
162
|
candidate = queue.shift
|
@@ -179,7 +184,7 @@ module RubyLsp
|
|
179
184
|
char_position, _ = find_index_by_position(position)
|
180
185
|
|
181
186
|
RubyDocument.locate(
|
182
|
-
|
187
|
+
ast,
|
183
188
|
char_position,
|
184
189
|
code_units_cache: @code_units_cache,
|
185
190
|
node_types: node_types,
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -94,16 +94,7 @@ module RubyLsp
|
|
94
94
|
id: message[:id],
|
95
95
|
response:
|
96
96
|
Addon.addons.map do |addon|
|
97
|
-
|
98
|
-
|
99
|
-
# If the add-on doesn't define a `version` method, we'd be calling the abstract method defined by
|
100
|
-
# Sorbet, which would raise an error.
|
101
|
-
# Therefore, we only call the method if it's defined by the add-on itself
|
102
|
-
if version_method.owner != Addon
|
103
|
-
version = addon.version
|
104
|
-
end
|
105
|
-
|
106
|
-
{ name: addon.name, version: version, errored: addon.error? }
|
97
|
+
{ name: addon.name, version: addon.version, errored: addon.error? }
|
107
98
|
end,
|
108
99
|
),
|
109
100
|
)
|
@@ -130,24 +121,12 @@ module RubyLsp
|
|
130
121
|
# If a document is deleted before we are able to process all of its enqueued requests, we will try to read it
|
131
122
|
# from disk and it raise this error. This is expected, so we don't include the `data` attribute to avoid
|
132
123
|
# reporting these to our telemetry
|
133
|
-
|
134
|
-
when Store::NonExistingDocumentError
|
124
|
+
if e.is_a?(Store::NonExistingDocumentError)
|
135
125
|
send_message(Error.new(
|
136
126
|
id: message[:id],
|
137
127
|
code: Constant::ErrorCodes::INVALID_PARAMS,
|
138
128
|
message: e.full_message,
|
139
129
|
))
|
140
|
-
when Document::LocationNotFoundError
|
141
|
-
send_message(Error.new(
|
142
|
-
id: message[:id],
|
143
|
-
code: Constant::ErrorCodes::REQUEST_FAILED,
|
144
|
-
message: <<~MESSAGE,
|
145
|
-
Request #{message[:method]} failed to find the target position.
|
146
|
-
The file might have been modified while the server was in the middle of searching for the target.
|
147
|
-
If you experience this regularly, please report any findings and extra information on
|
148
|
-
https://github.com/Shopify/ruby-lsp/issues/2446
|
149
|
-
MESSAGE
|
150
|
-
))
|
151
130
|
else
|
152
131
|
send_message(Error.new(
|
153
132
|
id: message[:id],
|
@@ -513,12 +492,12 @@ module RubyLsp
|
|
513
492
|
index.delete(uri, skip_require_paths_tree: true)
|
514
493
|
RubyIndexer::DeclarationListener.new(index, dispatcher, parse_result, uri, collect_comments: true)
|
515
494
|
code_lens = Requests::CodeLens.new(@global_state, document, dispatcher)
|
516
|
-
dispatcher.dispatch(
|
495
|
+
dispatcher.dispatch(document.ast)
|
517
496
|
end
|
518
497
|
end
|
519
498
|
else
|
520
499
|
code_lens = Requests::CodeLens.new(@global_state, document, dispatcher)
|
521
|
-
dispatcher.dispatch(
|
500
|
+
dispatcher.dispatch(document.ast)
|
522
501
|
end
|
523
502
|
|
524
503
|
# Store all responses retrieve in this round of visits in the cache and then return the response for the request
|
@@ -557,7 +536,7 @@ module RubyLsp
|
|
557
536
|
|
558
537
|
dispatcher = Prism::Dispatcher.new
|
559
538
|
semantic_highlighting = Requests::SemanticHighlighting.new(@global_state, dispatcher, document, nil)
|
560
|
-
dispatcher.visit(document.
|
539
|
+
dispatcher.visit(document.ast)
|
561
540
|
|
562
541
|
send_message(Result.new(id: message[:id], response: semantic_highlighting.perform))
|
563
542
|
end
|
@@ -583,7 +562,7 @@ module RubyLsp
|
|
583
562
|
document,
|
584
563
|
message.dig(:params, :previousResultId),
|
585
564
|
)
|
586
|
-
dispatcher.visit(document.
|
565
|
+
dispatcher.visit(document.ast)
|
587
566
|
send_message(Result.new(id: message[:id], response: request.perform))
|
588
567
|
end
|
589
568
|
|
@@ -612,7 +591,7 @@ module RubyLsp
|
|
612
591
|
nil,
|
613
592
|
range: range.dig(:start, :line)..range.dig(:end, :line),
|
614
593
|
)
|
615
|
-
dispatcher.visit(document.
|
594
|
+
dispatcher.visit(document.ast)
|
616
595
|
send_message(Result.new(id: message[:id], response: request.perform))
|
617
596
|
end
|
618
597
|
|
@@ -704,7 +683,7 @@ module RubyLsp
|
|
704
683
|
end
|
705
684
|
|
706
685
|
request = Requests::DocumentHighlight.new(@global_state, document, params[:position], dispatcher)
|
707
|
-
dispatcher.dispatch(document.
|
686
|
+
dispatcher.dispatch(document.ast)
|
708
687
|
send_message(Result.new(id: message[:id], response: request.perform))
|
709
688
|
end
|
710
689
|
|
@@ -851,7 +830,7 @@ module RubyLsp
|
|
851
830
|
end
|
852
831
|
|
853
832
|
request = Requests::InlayHints.new(document, hints_configurations, dispatcher)
|
854
|
-
dispatcher.visit(document.
|
833
|
+
dispatcher.visit(document.ast)
|
855
834
|
result = request.perform
|
856
835
|
document.cache_set("textDocument/inlayHint", result)
|
857
836
|
|
@@ -12,9 +12,9 @@ require "digest"
|
|
12
12
|
require "time"
|
13
13
|
require "uri"
|
14
14
|
|
15
|
-
# This file is a script that will configure a composed bundle for the Ruby LSP. The composed bundle allows developers to
|
16
|
-
# the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to
|
17
|
-
# exact locked versions of dependencies.
|
15
|
+
# This file is a script that will configure a composed bundle for the Ruby LSP. The composed bundle allows developers to
|
16
|
+
# use the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to
|
17
|
+
# the exact locked versions of dependencies.
|
18
18
|
|
19
19
|
Bundler.ui.level = :silent
|
20
20
|
|
data/lib/ruby_lsp/test_helper.rb
CHANGED
@@ -4,13 +4,10 @@
|
|
4
4
|
# NOTE: This module is intended to be used by addons for writing their own tests, so keep that in mind if changing.
|
5
5
|
|
6
6
|
module RubyLsp
|
7
|
+
# @requires_ancestor: Kernel
|
7
8
|
module TestHelper
|
8
9
|
class TestError < StandardError; end
|
9
10
|
|
10
|
-
extend T::Helpers
|
11
|
-
|
12
|
-
requires_ancestor { Kernel }
|
13
|
-
|
14
11
|
#: [T] (?String? source, ?URI::Generic uri, ?stub_no_typechecker: bool, ?load_addons: bool) { (RubyLsp::Server server, URI::Generic uri) -> T } -> T
|
15
12
|
def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typechecker: false, load_addons: true,
|
16
13
|
&block)
|