ruby-lsp 0.23.11 → 0.23.13
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/README.md +2 -2
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +12 -11
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +81 -115
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +117 -166
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +88 -200
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +56 -192
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +14 -16
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +42 -60
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
- data/lib/ruby_indexer/test/configuration_test.rb +42 -3
- data/lib/ruby_indexer/test/method_test.rb +28 -2
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_lsp/addon.rb +44 -71
- data/lib/ruby_lsp/base_server.rb +29 -32
- data/lib/ruby_lsp/client_capabilities.rb +10 -12
- data/lib/ruby_lsp/document.rb +34 -45
- data/lib/ruby_lsp/erb_document.rb +24 -36
- data/lib/ruby_lsp/global_state.rb +51 -56
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +81 -88
- data/lib/ruby_lsp/listeners/completion.rb +36 -55
- data/lib/ruby_lsp/listeners/definition.rb +37 -51
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +43 -62
- data/lib/ruby_lsp/listeners/document_symbol.rb +35 -49
- data/lib/ruby_lsp/listeners/folding_ranges.rb +32 -39
- data/lib/ruby_lsp/listeners/hover.rb +81 -100
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +42 -51
- data/lib/ruby_lsp/listeners/signature_help.rb +6 -25
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +160 -88
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +8 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +6 -17
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +5 -5
- data/lib/ruby_lsp/requests/definition.rb +8 -17
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
- data/lib/ruby_lsp/requests/document_link.rb +6 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
- data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
- data/lib/ruby_lsp/requests/formatting.rb +6 -9
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
- data/lib/ruby_lsp/requests/hover.rb +8 -18
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +28 -38
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +6 -36
- data/lib/ruby_lsp/requests/rename.rb +11 -37
- data/lib/ruby_lsp/requests/request.rb +7 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +5 -5
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +12 -31
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +5 -6
- data/lib/ruby_lsp/requests/signature_help.rb +8 -26
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +13 -50
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +9 -12
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
- data/lib/ruby_lsp/requests/support/source_uri.rb +16 -30
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
- data/lib/ruby_lsp/response_builders/document_symbol.rb +10 -16
- data/lib/ruby_lsp/response_builders/hover.rb +10 -13
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +59 -87
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
- data/lib/ruby_lsp/ruby_document.rb +22 -60
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +109 -0
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/server.rb +133 -74
- data/lib/ruby_lsp/setup_bundler.rb +58 -57
- data/lib/ruby_lsp/static_docs.rb +4 -7
- data/lib/ruby_lsp/store.rb +21 -40
- data/lib/ruby_lsp/test_helper.rb +3 -12
- data/lib/ruby_lsp/test_reporter.rb +207 -0
- data/lib/ruby_lsp/test_unit_test_runner.rb +98 -0
- data/lib/ruby_lsp/type_inferrer.rb +9 -13
- data/lib/ruby_lsp/utils.rb +37 -81
- metadata +9 -3
@@ -6,45 +6,32 @@ require "shellwords"
|
|
6
6
|
module RubyLsp
|
7
7
|
module Listeners
|
8
8
|
class CodeLens
|
9
|
-
extend T::Sig
|
10
9
|
include Requests::Support::Common
|
11
10
|
|
12
|
-
BASE_COMMAND =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
DESCRIBE_KEYWORD = T.let(:describe, Symbol)
|
24
|
-
IT_KEYWORD = T.let(:it, Symbol)
|
25
|
-
DYNAMIC_REFERENCE_MARKER = T.let("<dynamic_reference>", String)
|
26
|
-
|
27
|
-
sig do
|
28
|
-
params(
|
29
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
|
30
|
-
global_state: GlobalState,
|
31
|
-
uri: URI::Generic,
|
32
|
-
dispatcher: Prism::Dispatcher,
|
33
|
-
).void
|
34
|
-
end
|
11
|
+
BASE_COMMAND = begin
|
12
|
+
Bundler.with_original_env { Bundler.default_lockfile }
|
13
|
+
"bundle exec ruby"
|
14
|
+
rescue Bundler::GemfileNotFound
|
15
|
+
"ruby"
|
16
|
+
end #: String
|
17
|
+
ACCESS_MODIFIERS = [:public, :private, :protected] #: Array[Symbol]
|
18
|
+
SUPPORTED_TEST_LIBRARIES = ["minitest", "test-unit"] #: Array[String]
|
19
|
+
DYNAMIC_REFERENCE_MARKER = "<dynamic_reference>" #: String
|
20
|
+
|
21
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
35
22
|
def initialize(response_builder, global_state, uri, dispatcher)
|
36
23
|
@response_builder = response_builder
|
37
24
|
@global_state = global_state
|
38
|
-
@uri =
|
39
|
-
@path =
|
25
|
+
@uri = uri #: URI::Generic
|
26
|
+
@path = uri.to_standardized_path #: String?
|
40
27
|
# visibility_stack is a stack of [current_visibility, previous_visibility]
|
41
|
-
@visibility_stack =
|
42
|
-
@group_stack =
|
43
|
-
@group_id =
|
44
|
-
@group_id_stack =
|
28
|
+
@visibility_stack = [[:public, :public]] #: Array[Array[Symbol?]]
|
29
|
+
@group_stack = [] #: Array[String]
|
30
|
+
@group_id = 1 #: Integer
|
31
|
+
@group_id_stack = [] #: Array[Integer]
|
45
32
|
# We want to avoid adding code lenses for nested definitions
|
46
|
-
@def_depth =
|
47
|
-
@spec_id =
|
33
|
+
@def_depth = 0 #: Integer
|
34
|
+
@spec_id = 0 #: Integer
|
48
35
|
|
49
36
|
dispatcher.register(
|
50
37
|
self,
|
@@ -59,7 +46,7 @@ module RubyLsp
|
|
59
46
|
)
|
60
47
|
end
|
61
48
|
|
62
|
-
|
49
|
+
#: (Prism::ClassNode node) -> void
|
63
50
|
def on_class_node_enter(node)
|
64
51
|
@visibility_stack.push([:public, :public])
|
65
52
|
class_name = node.constant_path.slice
|
@@ -79,7 +66,7 @@ module RubyLsp
|
|
79
66
|
end
|
80
67
|
end
|
81
68
|
|
82
|
-
|
69
|
+
#: (Prism::ClassNode node) -> void
|
83
70
|
def on_class_node_leave(node)
|
84
71
|
@visibility_stack.pop
|
85
72
|
@group_stack.pop
|
@@ -91,7 +78,7 @@ module RubyLsp
|
|
91
78
|
end
|
92
79
|
end
|
93
80
|
|
94
|
-
|
81
|
+
#: (Prism::DefNode node) -> void
|
95
82
|
def on_def_node_enter(node)
|
96
83
|
@def_depth += 1
|
97
84
|
return if @def_depth > 1
|
@@ -114,12 +101,12 @@ module RubyLsp
|
|
114
101
|
end
|
115
102
|
end
|
116
103
|
|
117
|
-
|
104
|
+
#: (Prism::DefNode node) -> void
|
118
105
|
def on_def_node_leave(node)
|
119
106
|
@def_depth -= 1
|
120
107
|
end
|
121
108
|
|
122
|
-
|
109
|
+
#: (Prism::ModuleNode node) -> void
|
123
110
|
def on_module_node_enter(node)
|
124
111
|
if (path = namespace_constant_name(node))
|
125
112
|
@group_stack.push(path)
|
@@ -128,12 +115,12 @@ module RubyLsp
|
|
128
115
|
end
|
129
116
|
end
|
130
117
|
|
131
|
-
|
118
|
+
#: (Prism::ModuleNode node) -> void
|
132
119
|
def on_module_node_leave(node)
|
133
120
|
@group_stack.pop
|
134
121
|
end
|
135
122
|
|
136
|
-
|
123
|
+
#: (Prism::CallNode node) -> void
|
137
124
|
def on_call_node_enter(node)
|
138
125
|
name = node.name
|
139
126
|
arguments = node.arguments
|
@@ -151,23 +138,21 @@ module RubyLsp
|
|
151
138
|
return
|
152
139
|
end
|
153
140
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
add_spec_code_lens(node, kind: :example)
|
162
|
-
end
|
141
|
+
case name
|
142
|
+
when :describe
|
143
|
+
add_spec_code_lens(node, kind: :group)
|
144
|
+
@group_id_stack.push(@group_id)
|
145
|
+
@group_id += 1
|
146
|
+
when :it, :specify # `specify` is an alias for `it`
|
147
|
+
add_spec_code_lens(node, kind: :example)
|
163
148
|
end
|
164
149
|
end
|
165
150
|
|
166
|
-
|
151
|
+
#: (Prism::CallNode node) -> void
|
167
152
|
def on_call_node_leave(node)
|
168
153
|
_, prev_visibility = @visibility_stack.pop
|
169
154
|
@visibility_stack.push([prev_visibility, prev_visibility])
|
170
|
-
if node.name ==
|
155
|
+
if node.name == :describe
|
171
156
|
@group_id_stack.pop
|
172
157
|
@group_stack.pop
|
173
158
|
end
|
@@ -175,7 +160,7 @@ module RubyLsp
|
|
175
160
|
|
176
161
|
private
|
177
162
|
|
178
|
-
|
163
|
+
#: (Prism::Node node, name: String, command: String, kind: Symbol, ?id: String) -> void
|
179
164
|
def add_test_code_lens(node, name:, command:, kind:, id: name)
|
180
165
|
# don't add code lenses if the test library is not supported or unknown
|
181
166
|
return unless SUPPORTED_TEST_LIBRARIES.include?(@global_state.test_library) && @path
|
@@ -221,13 +206,7 @@ module RubyLsp
|
|
221
206
|
)
|
222
207
|
end
|
223
208
|
|
224
|
-
|
225
|
-
params(
|
226
|
-
group_stack: T::Array[String],
|
227
|
-
spec_name: T.nilable(String),
|
228
|
-
method_name: T.nilable(String),
|
229
|
-
).returns(String)
|
230
|
-
end
|
209
|
+
#: (?group_stack: Array[String], ?spec_name: String?, ?method_name: String?) -> String
|
231
210
|
def generate_test_command(group_stack: [], spec_name: nil, method_name: nil)
|
232
211
|
path = T.must(@path)
|
233
212
|
command = BASE_COMMAND
|
@@ -237,44 +216,58 @@ module RubyLsp
|
|
237
216
|
|
238
217
|
case @global_state.test_library
|
239
218
|
when "minitest"
|
240
|
-
|
241
|
-
command += if last_dynamic_reference_index
|
242
|
-
# In cases where the test path looks like `foo::Bar`
|
243
|
-
# the best we can do is match everything to the right of it.
|
244
|
-
# Tests are classes, dynamic references are only a thing for modules,
|
245
|
-
# so there must be something to the left of the available path.
|
246
|
-
group_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
|
247
|
-
if method_name
|
248
|
-
" --name " + "/::#{Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
|
249
|
-
else
|
250
|
-
# When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
|
251
|
-
# that are registered on the class itself (matches after `#`) and all tests
|
252
|
-
# that are nested inside of that class in other modules/classes (matches after `::`)
|
253
|
-
" --name " + "\"/::#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
|
254
|
-
end
|
255
|
-
elsif method_name
|
256
|
-
# We know the entire path, do an exact match
|
257
|
-
" --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
|
258
|
-
elsif spec_name
|
259
|
-
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}##{Shellwords.escape(spec_name)}$/\""
|
260
|
-
else
|
261
|
-
# Execute all tests of the selected class and tests in
|
262
|
-
# modules/classes nested inside of that class
|
263
|
-
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
|
264
|
-
end
|
219
|
+
command += generate_minitest_command(group_stack, method_name, spec_name)
|
265
220
|
when "test-unit"
|
266
|
-
|
267
|
-
|
221
|
+
command += generate_test_unit_command(group_stack, method_name)
|
222
|
+
end
|
223
|
+
|
224
|
+
command
|
225
|
+
end
|
226
|
+
|
227
|
+
#: (Array[String] group_stack, String? method_name, String? spec_name) -> String
|
228
|
+
def generate_minitest_command(group_stack, method_name, spec_name)
|
229
|
+
last_dynamic_reference_index = group_stack.rindex(DYNAMIC_REFERENCE_MARKER)
|
230
|
+
|
231
|
+
if last_dynamic_reference_index
|
232
|
+
# In cases where the test path looks like `foo::Bar`
|
233
|
+
# the best we can do is match everything to the right of it.
|
234
|
+
# Tests are classes, dynamic references are only a thing for modules,
|
235
|
+
# so there must be something to the left of the available path.
|
236
|
+
dynamic_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
|
268
237
|
|
269
238
|
if method_name
|
270
|
-
|
239
|
+
" --name " + "/::#{Shellwords.escape(dynamic_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
|
240
|
+
else
|
241
|
+
# When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
|
242
|
+
# that are registered on the class itself (matches after `#`) and all tests
|
243
|
+
# that are nested inside of that class in other modules/classes (matches after `::`)
|
244
|
+
" --name " + "\"/::#{Shellwords.escape(dynamic_stack.join("::"))}(#|::)/\""
|
271
245
|
end
|
246
|
+
elsif method_name
|
247
|
+
# We know the entire path, do an exact match
|
248
|
+
" --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
|
249
|
+
elsif spec_name
|
250
|
+
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}##{Shellwords.escape(spec_name)}$/\""
|
251
|
+
else
|
252
|
+
# Execute all tests of the selected class and tests in
|
253
|
+
# modules/classes nested inside of that class
|
254
|
+
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
#: (Array[String] group_stack, String? method_name) -> String
|
259
|
+
def generate_test_unit_command(group_stack, method_name)
|
260
|
+
group_name = T.must(group_stack.last)
|
261
|
+
command = " --testcase " + "/#{Shellwords.escape(group_name)}/"
|
262
|
+
|
263
|
+
if method_name
|
264
|
+
command += " --name " + Shellwords.escape(method_name)
|
272
265
|
end
|
273
266
|
|
274
267
|
command
|
275
268
|
end
|
276
269
|
|
277
|
-
|
270
|
+
#: (Prism::CallNode node, kind: Symbol) -> void
|
278
271
|
def add_spec_code_lens(node, kind:)
|
279
272
|
arguments = node.arguments
|
280
273
|
return unless arguments
|
@@ -312,7 +305,7 @@ module RubyLsp
|
|
312
305
|
end
|
313
306
|
end
|
314
307
|
|
315
|
-
|
308
|
+
#: (group_stack: Array[String], ?method_name: String?) -> String
|
316
309
|
def generate_fully_qualified_id(group_stack:, method_name: nil)
|
317
310
|
if method_name
|
318
311
|
# For tests, this will be the test class and method name: `Foo::BarTest#test_baz`.
|
@@ -4,7 +4,6 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Listeners
|
6
6
|
class Completion
|
7
|
-
extend T::Sig
|
8
7
|
include Requests::Support::Common
|
9
8
|
|
10
9
|
KEYWORDS = [
|
@@ -51,17 +50,7 @@ module RubyLsp
|
|
51
50
|
"__LINE__",
|
52
51
|
].freeze
|
53
52
|
|
54
|
-
|
55
|
-
params(
|
56
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
|
57
|
-
global_state: GlobalState,
|
58
|
-
node_context: NodeContext,
|
59
|
-
sorbet_level: RubyDocument::SorbetLevel,
|
60
|
-
dispatcher: Prism::Dispatcher,
|
61
|
-
uri: URI::Generic,
|
62
|
-
trigger_character: T.nilable(String),
|
63
|
-
).void
|
64
|
-
end
|
53
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, GlobalState global_state, NodeContext node_context, RubyDocument::SorbetLevel sorbet_level, Prism::Dispatcher dispatcher, URI::Generic uri, String? trigger_character) -> void
|
65
54
|
def initialize( # rubocop:disable Metrics/ParameterLists
|
66
55
|
response_builder,
|
67
56
|
global_state,
|
@@ -73,8 +62,8 @@ module RubyLsp
|
|
73
62
|
)
|
74
63
|
@response_builder = response_builder
|
75
64
|
@global_state = global_state
|
76
|
-
@index =
|
77
|
-
@type_inferrer =
|
65
|
+
@index = global_state.index #: RubyIndexer::Index
|
66
|
+
@type_inferrer = global_state.type_inferrer #: TypeInferrer
|
78
67
|
@node_context = node_context
|
79
68
|
@sorbet_level = sorbet_level
|
80
69
|
@uri = uri
|
@@ -107,7 +96,7 @@ module RubyLsp
|
|
107
96
|
end
|
108
97
|
|
109
98
|
# Handle completion on regular constant references (e.g. `Bar`)
|
110
|
-
|
99
|
+
#: (Prism::ConstantReadNode node) -> void
|
111
100
|
def on_constant_read_node_enter(node)
|
112
101
|
# The only scenario where Sorbet doesn't provide constant completion is on ignored files. Even if the file has
|
113
102
|
# no sigil, Sorbet will still provide completion for constants
|
@@ -131,7 +120,7 @@ module RubyLsp
|
|
131
120
|
end
|
132
121
|
|
133
122
|
# Handle completion on namespaced constant references (e.g. `Foo::Bar`)
|
134
|
-
|
123
|
+
#: (Prism::ConstantPathNode node) -> void
|
135
124
|
def on_constant_path_node_enter(node)
|
136
125
|
# The only scenario where Sorbet doesn't provide constant completion is on ignored files. Even if the file has
|
137
126
|
# no sigil, Sorbet will still provide completion for constants
|
@@ -149,7 +138,7 @@ module RubyLsp
|
|
149
138
|
constant_path_completion(name, range_from_location(node.location))
|
150
139
|
end
|
151
140
|
|
152
|
-
|
141
|
+
#: (Prism::CallNode node) -> void
|
153
142
|
def on_call_node_enter(node)
|
154
143
|
# The only scenario where Sorbet doesn't provide constant completion is on ignored files. Even if the file has
|
155
144
|
# no sigil, Sorbet will still provide completion for constants
|
@@ -193,99 +182,99 @@ module RubyLsp
|
|
193
182
|
end
|
194
183
|
end
|
195
184
|
|
196
|
-
|
185
|
+
#: (Prism::GlobalVariableAndWriteNode node) -> void
|
197
186
|
def on_global_variable_and_write_node_enter(node)
|
198
187
|
handle_global_variable_completion(node.name.to_s, node.name_loc)
|
199
188
|
end
|
200
189
|
|
201
|
-
|
190
|
+
#: (Prism::GlobalVariableOperatorWriteNode node) -> void
|
202
191
|
def on_global_variable_operator_write_node_enter(node)
|
203
192
|
handle_global_variable_completion(node.name.to_s, node.name_loc)
|
204
193
|
end
|
205
194
|
|
206
|
-
|
195
|
+
#: (Prism::GlobalVariableOrWriteNode node) -> void
|
207
196
|
def on_global_variable_or_write_node_enter(node)
|
208
197
|
handle_global_variable_completion(node.name.to_s, node.name_loc)
|
209
198
|
end
|
210
199
|
|
211
|
-
|
200
|
+
#: (Prism::GlobalVariableReadNode node) -> void
|
212
201
|
def on_global_variable_read_node_enter(node)
|
213
202
|
handle_global_variable_completion(node.name.to_s, node.location)
|
214
203
|
end
|
215
204
|
|
216
|
-
|
205
|
+
#: (Prism::GlobalVariableTargetNode node) -> void
|
217
206
|
def on_global_variable_target_node_enter(node)
|
218
207
|
handle_global_variable_completion(node.name.to_s, node.location)
|
219
208
|
end
|
220
209
|
|
221
|
-
|
210
|
+
#: (Prism::GlobalVariableWriteNode node) -> void
|
222
211
|
def on_global_variable_write_node_enter(node)
|
223
212
|
handle_global_variable_completion(node.name.to_s, node.name_loc)
|
224
213
|
end
|
225
214
|
|
226
|
-
|
215
|
+
#: (Prism::InstanceVariableReadNode node) -> void
|
227
216
|
def on_instance_variable_read_node_enter(node)
|
228
217
|
handle_instance_variable_completion(node.name.to_s, node.location)
|
229
218
|
end
|
230
219
|
|
231
|
-
|
220
|
+
#: (Prism::InstanceVariableWriteNode node) -> void
|
232
221
|
def on_instance_variable_write_node_enter(node)
|
233
222
|
handle_instance_variable_completion(node.name.to_s, node.name_loc)
|
234
223
|
end
|
235
224
|
|
236
|
-
|
225
|
+
#: (Prism::InstanceVariableAndWriteNode node) -> void
|
237
226
|
def on_instance_variable_and_write_node_enter(node)
|
238
227
|
handle_instance_variable_completion(node.name.to_s, node.name_loc)
|
239
228
|
end
|
240
229
|
|
241
|
-
|
230
|
+
#: (Prism::InstanceVariableOperatorWriteNode node) -> void
|
242
231
|
def on_instance_variable_operator_write_node_enter(node)
|
243
232
|
handle_instance_variable_completion(node.name.to_s, node.name_loc)
|
244
233
|
end
|
245
234
|
|
246
|
-
|
235
|
+
#: (Prism::InstanceVariableOrWriteNode node) -> void
|
247
236
|
def on_instance_variable_or_write_node_enter(node)
|
248
237
|
handle_instance_variable_completion(node.name.to_s, node.name_loc)
|
249
238
|
end
|
250
239
|
|
251
|
-
|
240
|
+
#: (Prism::InstanceVariableTargetNode node) -> void
|
252
241
|
def on_instance_variable_target_node_enter(node)
|
253
242
|
handle_instance_variable_completion(node.name.to_s, node.location)
|
254
243
|
end
|
255
244
|
|
256
|
-
|
245
|
+
#: (Prism::ClassVariableAndWriteNode node) -> void
|
257
246
|
def on_class_variable_and_write_node_enter(node)
|
258
247
|
handle_class_variable_completion(node.name.to_s, node.name_loc)
|
259
248
|
end
|
260
249
|
|
261
|
-
|
250
|
+
#: (Prism::ClassVariableOperatorWriteNode node) -> void
|
262
251
|
def on_class_variable_operator_write_node_enter(node)
|
263
252
|
handle_class_variable_completion(node.name.to_s, node.name_loc)
|
264
253
|
end
|
265
254
|
|
266
|
-
|
255
|
+
#: (Prism::ClassVariableOrWriteNode node) -> void
|
267
256
|
def on_class_variable_or_write_node_enter(node)
|
268
257
|
handle_class_variable_completion(node.name.to_s, node.name_loc)
|
269
258
|
end
|
270
259
|
|
271
|
-
|
260
|
+
#: (Prism::ClassVariableTargetNode node) -> void
|
272
261
|
def on_class_variable_target_node_enter(node)
|
273
262
|
handle_class_variable_completion(node.name.to_s, node.location)
|
274
263
|
end
|
275
264
|
|
276
|
-
|
265
|
+
#: (Prism::ClassVariableReadNode node) -> void
|
277
266
|
def on_class_variable_read_node_enter(node)
|
278
267
|
handle_class_variable_completion(node.name.to_s, node.location)
|
279
268
|
end
|
280
269
|
|
281
|
-
|
270
|
+
#: (Prism::ClassVariableWriteNode node) -> void
|
282
271
|
def on_class_variable_write_node_enter(node)
|
283
272
|
handle_class_variable_completion(node.name.to_s, node.name_loc)
|
284
273
|
end
|
285
274
|
|
286
275
|
private
|
287
276
|
|
288
|
-
|
277
|
+
#: (String name, Interface::Range range) -> void
|
289
278
|
def constant_path_completion(name, range)
|
290
279
|
top_level_reference = if name.start_with?("::")
|
291
280
|
name = name.delete_prefix("::")
|
@@ -340,7 +329,7 @@ module RubyLsp
|
|
340
329
|
end
|
341
330
|
end
|
342
331
|
|
343
|
-
|
332
|
+
#: (String name, Prism::Location location) -> void
|
344
333
|
def handle_global_variable_completion(name, location)
|
345
334
|
candidates = @index.prefix_search(name)
|
346
335
|
|
@@ -363,7 +352,7 @@ module RubyLsp
|
|
363
352
|
end
|
364
353
|
end
|
365
354
|
|
366
|
-
|
355
|
+
#: (String name, Prism::Location location) -> void
|
367
356
|
def handle_class_variable_completion(name, location)
|
368
357
|
type = @type_inferrer.infer_receiver_type(@node_context)
|
369
358
|
return unless type
|
@@ -394,7 +383,7 @@ module RubyLsp
|
|
394
383
|
# If by any chance we haven't indexed the owner, then there's no way to find the right declaration
|
395
384
|
end
|
396
385
|
|
397
|
-
|
386
|
+
#: (String name, Prism::Location location) -> void
|
398
387
|
def handle_instance_variable_completion(name, location)
|
399
388
|
# Sorbet enforces that all instance variables be declared on typed strict or higher, which means it will be able
|
400
389
|
# to provide all features for them
|
@@ -428,7 +417,7 @@ module RubyLsp
|
|
428
417
|
# If by any chance we haven't indexed the owner, then there's no way to find the right declaration
|
429
418
|
end
|
430
419
|
|
431
|
-
|
420
|
+
#: (Prism::CallNode node) -> void
|
432
421
|
def complete_require(node)
|
433
422
|
arguments_node = node.arguments
|
434
423
|
return unless arguments_node
|
@@ -444,7 +433,7 @@ module RubyLsp
|
|
444
433
|
end
|
445
434
|
end
|
446
435
|
|
447
|
-
|
436
|
+
#: (Prism::CallNode node) -> void
|
448
437
|
def complete_require_relative(node)
|
449
438
|
arguments_node = node.arguments
|
450
439
|
return unless arguments_node
|
@@ -476,7 +465,7 @@ module RubyLsp
|
|
476
465
|
# might fail with EPERM
|
477
466
|
end
|
478
467
|
|
479
|
-
|
468
|
+
#: (Prism::CallNode node, String name) -> void
|
480
469
|
def complete_methods(node, name)
|
481
470
|
# If the node has a receiver, then we don't need to provide local nor keyword completions. Sorbet can provide
|
482
471
|
# local and keyword completion for any file with a Sorbet level of true or higher
|
@@ -540,7 +529,7 @@ module RubyLsp
|
|
540
529
|
# We have not indexed this namespace, so we can't provide any completions
|
541
530
|
end
|
542
531
|
|
543
|
-
|
532
|
+
#: (Prism::CallNode node, String name) -> void
|
544
533
|
def add_local_completions(node, name)
|
545
534
|
range = range_from_location(T.must(node.message_loc))
|
546
535
|
|
@@ -560,7 +549,7 @@ module RubyLsp
|
|
560
549
|
end
|
561
550
|
end
|
562
551
|
|
563
|
-
|
552
|
+
#: (Prism::CallNode node, String name) -> void
|
564
553
|
def add_keyword_completions(node, name)
|
565
554
|
range = range_from_location(T.must(node.message_loc))
|
566
555
|
|
@@ -578,7 +567,7 @@ module RubyLsp
|
|
578
567
|
end
|
579
568
|
end
|
580
569
|
|
581
|
-
|
570
|
+
#: (String label, Prism::StringNode node) -> Interface::CompletionItem
|
582
571
|
def build_completion(label, node)
|
583
572
|
# We should use the content location as we only replace the content and not the delimiters of the string
|
584
573
|
loc = node.content_loc
|
@@ -593,15 +582,7 @@ module RubyLsp
|
|
593
582
|
)
|
594
583
|
end
|
595
584
|
|
596
|
-
|
597
|
-
params(
|
598
|
-
real_name: String,
|
599
|
-
incomplete_name: String,
|
600
|
-
range: Interface::Range,
|
601
|
-
entries: T::Array[RubyIndexer::Entry],
|
602
|
-
top_level: T::Boolean,
|
603
|
-
).returns(Interface::CompletionItem)
|
604
|
-
end
|
585
|
+
#: (String real_name, String incomplete_name, Interface::Range range, Array[RubyIndexer::Entry] entries, bool top_level) -> Interface::CompletionItem
|
605
586
|
def build_entry_completion(real_name, incomplete_name, range, entries, top_level)
|
606
587
|
first_entry = T.must(entries.first)
|
607
588
|
kind = case first_entry
|
@@ -690,7 +671,7 @@ module RubyLsp
|
|
690
671
|
# B
|
691
672
|
# end
|
692
673
|
# ```
|
693
|
-
|
674
|
+
#: (String entry_name) -> bool
|
694
675
|
def top_level?(entry_name)
|
695
676
|
nesting = @node_context.nesting
|
696
677
|
nesting.length.downto(0) do |i|
|