ruby-lsp 0.23.11 → 0.23.12
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_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +52 -77
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +61 -144
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +8 -6
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +73 -182
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +48 -181
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +12 -14
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +21 -44
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +40 -58
- 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 +32 -2
- data/lib/ruby_indexer/test/method_test.rb +2 -2
- data/lib/ruby_lsp/addon.rb +32 -67
- data/lib/ruby_lsp/base_server.rb +10 -10
- data/lib/ruby_lsp/client_capabilities.rb +4 -6
- data/lib/ruby_lsp/document.rb +21 -32
- data/lib/ruby_lsp/erb_document.rb +17 -27
- data/lib/ruby_lsp/global_state.rb +30 -32
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +21 -39
- data/lib/ruby_lsp/listeners/completion.rb +34 -53
- data/lib/ruby_lsp/listeners/definition.rb +35 -49
- data/lib/ruby_lsp/listeners/document_highlight.rb +60 -69
- data/lib/ruby_lsp/listeners/document_link.rb +9 -19
- data/lib/ruby_lsp/listeners/document_symbol.rb +34 -48
- data/lib/ruby_lsp/listeners/folding_ranges.rb +31 -38
- data/lib/ruby_lsp/listeners/hover.rb +37 -47
- data/lib/ruby_lsp/listeners/inlay_hints.rb +3 -10
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +29 -35
- data/lib/ruby_lsp/listeners/signature_help.rb +4 -23
- data/lib/ruby_lsp/listeners/spec_style.rb +199 -0
- data/lib/ruby_lsp/listeners/test_style.rb +136 -30
- data/lib/ruby_lsp/node_context.rb +8 -35
- data/lib/ruby_lsp/rbs_document.rb +7 -5
- data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
- data/lib/ruby_lsp/requests/code_actions.rb +5 -14
- data/lib/ruby_lsp/requests/code_lens.rb +4 -13
- data/lib/ruby_lsp/requests/completion.rb +4 -15
- data/lib/ruby_lsp/requests/completion_resolve.rb +4 -4
- data/lib/ruby_lsp/requests/definition.rb +4 -12
- data/lib/ruby_lsp/requests/diagnostics.rb +6 -9
- data/lib/ruby_lsp/requests/discover_tests.rb +15 -3
- data/lib/ruby_lsp/requests/document_highlight.rb +3 -11
- data/lib/ruby_lsp/requests/document_link.rb +4 -13
- data/lib/ruby_lsp/requests/document_symbol.rb +4 -7
- data/lib/ruby_lsp/requests/folding_ranges.rb +4 -7
- data/lib/ruby_lsp/requests/formatting.rb +4 -7
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
- data/lib/ruby_lsp/requests/hover.rb +6 -16
- data/lib/ruby_lsp/requests/inlay_hints.rb +4 -13
- data/lib/ruby_lsp/requests/on_type_formatting.rb +17 -24
- data/lib/ruby_lsp/requests/prepare_rename.rb +3 -8
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
- data/lib/ruby_lsp/requests/range_formatting.rb +3 -4
- data/lib/ruby_lsp/requests/references.rb +5 -35
- data/lib/ruby_lsp/requests/rename.rb +9 -35
- data/lib/ruby_lsp/requests/request.rb +5 -17
- data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +6 -23
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +4 -5
- data/lib/ruby_lsp/requests/signature_help.rb +6 -24
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +12 -49
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -14
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +7 -10
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -15
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +1 -7
- data/lib/ruby_lsp/requests/support/source_uri.rb +5 -16
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +7 -10
- data/lib/ruby_lsp/requests/support/test_item.rb +14 -13
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +4 -5
- data/lib/ruby_lsp/requests/workspace_symbol.rb +3 -3
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +4 -4
- data/lib/ruby_lsp/response_builders/document_symbol.rb +8 -11
- data/lib/ruby_lsp/response_builders/hover.rb +5 -5
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +18 -40
- data/lib/ruby_lsp/response_builders/signature_help.rb +4 -5
- data/lib/ruby_lsp/response_builders/test_collection.rb +5 -9
- data/lib/ruby_lsp/ruby_document.rb +15 -40
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +106 -0
- data/lib/ruby_lsp/scope.rb +6 -10
- data/lib/ruby_lsp/server.rb +125 -74
- data/lib/ruby_lsp/setup_bundler.rb +22 -15
- data/lib/ruby_lsp/store.rb +12 -28
- data/lib/ruby_lsp/test_helper.rb +3 -12
- data/lib/ruby_lsp/test_reporter.rb +71 -0
- data/lib/ruby_lsp/test_unit_test_runner.rb +96 -0
- data/lib/ruby_lsp/type_inferrer.rb +9 -13
- data/lib/ruby_lsp/utils.rb +27 -65
- metadata +8 -3
@@ -3,39 +3,37 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class GlobalState
|
6
|
-
|
7
|
-
|
8
|
-
sig { returns(String) }
|
6
|
+
#: String
|
9
7
|
attr_reader :test_library
|
10
8
|
|
11
|
-
|
9
|
+
#: String
|
12
10
|
attr_accessor :formatter
|
13
11
|
|
14
|
-
|
12
|
+
#: bool
|
15
13
|
attr_reader :has_type_checker
|
16
14
|
|
17
|
-
|
15
|
+
#: RubyIndexer::Index
|
18
16
|
attr_reader :index
|
19
17
|
|
20
|
-
|
18
|
+
#: Encoding
|
21
19
|
attr_reader :encoding
|
22
20
|
|
23
|
-
|
21
|
+
#: bool
|
24
22
|
attr_reader :top_level_bundle
|
25
23
|
|
26
|
-
|
24
|
+
#: TypeInferrer
|
27
25
|
attr_reader :type_inferrer
|
28
26
|
|
29
|
-
|
27
|
+
#: ClientCapabilities
|
30
28
|
attr_reader :client_capabilities
|
31
29
|
|
32
|
-
|
30
|
+
#: URI::Generic
|
33
31
|
attr_reader :workspace_uri
|
34
32
|
|
35
|
-
|
33
|
+
#: String?
|
36
34
|
attr_reader :telemetry_machine_id
|
37
35
|
|
38
|
-
|
36
|
+
#: -> void
|
39
37
|
def initialize
|
40
38
|
@workspace_uri = T.let(URI::Generic.from_path(path: Dir.pwd), URI::Generic)
|
41
39
|
@encoding = T.let(Encoding::UTF_8, Encoding)
|
@@ -63,33 +61,33 @@ module RubyLsp
|
|
63
61
|
@telemetry_machine_id = T.let(nil, T.nilable(String))
|
64
62
|
end
|
65
63
|
|
66
|
-
|
64
|
+
#: [T] { -> T } -> T
|
67
65
|
def synchronize(&block)
|
68
66
|
@mutex.synchronize(&block)
|
69
67
|
end
|
70
68
|
|
71
|
-
|
69
|
+
#: (String addon_name) -> Hash[Symbol, untyped]?
|
72
70
|
def settings_for_addon(addon_name)
|
73
71
|
@addon_settings[addon_name]
|
74
72
|
end
|
75
73
|
|
76
|
-
|
74
|
+
#: (String identifier, Requests::Support::Formatter instance) -> void
|
77
75
|
def register_formatter(identifier, instance)
|
78
76
|
@supported_formatters[identifier] = instance
|
79
77
|
end
|
80
78
|
|
81
|
-
|
79
|
+
#: -> Requests::Support::Formatter?
|
82
80
|
def active_formatter
|
83
81
|
@supported_formatters[@formatter]
|
84
82
|
end
|
85
83
|
|
86
|
-
|
84
|
+
#: -> Array[Requests::Support::Formatter]
|
87
85
|
def active_linters
|
88
86
|
@linters.filter_map { |name| @supported_formatters[name] }
|
89
87
|
end
|
90
88
|
|
91
89
|
# Applies the options provided by the editor and returns an array of notifications to send back to the client
|
92
|
-
|
90
|
+
#: (Hash[Symbol, untyped] options) -> Array[Notification]
|
93
91
|
def apply_options(options)
|
94
92
|
notifications = []
|
95
93
|
direct_dependencies = gather_direct_dependencies
|
@@ -183,17 +181,17 @@ module RubyLsp
|
|
183
181
|
notifications
|
184
182
|
end
|
185
183
|
|
186
|
-
|
184
|
+
#: (Symbol flag) -> bool?
|
187
185
|
def enabled_feature?(flag)
|
188
186
|
@enabled_feature_flags[:all] || @enabled_feature_flags[flag]
|
189
187
|
end
|
190
188
|
|
191
|
-
|
189
|
+
#: -> String
|
192
190
|
def workspace_path
|
193
191
|
T.must(@workspace_uri.to_standardized_path)
|
194
192
|
end
|
195
193
|
|
196
|
-
|
194
|
+
#: -> String
|
197
195
|
def encoding_name
|
198
196
|
case @encoding
|
199
197
|
when Encoding::UTF_8
|
@@ -205,14 +203,14 @@ module RubyLsp
|
|
205
203
|
end
|
206
204
|
end
|
207
205
|
|
208
|
-
|
206
|
+
#: -> bool
|
209
207
|
def supports_watching_files
|
210
208
|
@client_capabilities.supports_watching_files
|
211
209
|
end
|
212
210
|
|
213
211
|
private
|
214
212
|
|
215
|
-
|
213
|
+
#: (Array[String] direct_dependencies, Array[String] all_dependencies) -> String
|
216
214
|
def detect_formatter(direct_dependencies, all_dependencies)
|
217
215
|
# NOTE: Intentionally no $ at end, since we want to match rubocop-shopify, etc.
|
218
216
|
return "rubocop_internal" if direct_dependencies.any?(/^rubocop/)
|
@@ -228,7 +226,7 @@ module RubyLsp
|
|
228
226
|
|
229
227
|
# Try to detect if there are linters in the project's dependencies. For auto-detection, we always only consider a
|
230
228
|
# single linter. To have multiple linters running, the user must configure them manually
|
231
|
-
|
229
|
+
#: (Array[String] dependencies, Array[String] all_dependencies) -> Array[String]
|
232
230
|
def detect_linters(dependencies, all_dependencies)
|
233
231
|
linters = []
|
234
232
|
|
@@ -239,7 +237,7 @@ module RubyLsp
|
|
239
237
|
linters
|
240
238
|
end
|
241
239
|
|
242
|
-
|
240
|
+
#: (Array[String] dependencies) -> String
|
243
241
|
def detect_test_library(dependencies)
|
244
242
|
if dependencies.any?(/^rspec/)
|
245
243
|
"rspec"
|
@@ -259,7 +257,7 @@ module RubyLsp
|
|
259
257
|
end
|
260
258
|
end
|
261
259
|
|
262
|
-
|
260
|
+
#: (Array[String] dependencies) -> bool
|
263
261
|
def detect_typechecker(dependencies)
|
264
262
|
return false if ENV["RUBY_LSP_BYPASS_TYPECHECKER"]
|
265
263
|
|
@@ -268,17 +266,17 @@ module RubyLsp
|
|
268
266
|
false
|
269
267
|
end
|
270
268
|
|
271
|
-
|
269
|
+
#: -> bool
|
272
270
|
def bin_rails_present
|
273
271
|
File.exist?(File.join(workspace_path, "bin/rails"))
|
274
272
|
end
|
275
273
|
|
276
|
-
|
274
|
+
#: -> bool
|
277
275
|
def dot_rubocop_yml_present
|
278
276
|
File.exist?(File.join(workspace_path, ".rubocop.yml"))
|
279
277
|
end
|
280
278
|
|
281
|
-
|
279
|
+
#: -> Array[String]
|
282
280
|
def gather_direct_dependencies
|
283
281
|
Bundler.with_original_env { Bundler.default_gemfile }
|
284
282
|
|
@@ -288,14 +286,14 @@ module RubyLsp
|
|
288
286
|
[]
|
289
287
|
end
|
290
288
|
|
291
|
-
|
289
|
+
#: -> Array[String]
|
292
290
|
def gemspec_dependencies
|
293
291
|
(Bundler.locked_gems&.sources || [])
|
294
292
|
.grep(Bundler::Source::Gemspec)
|
295
293
|
.flat_map { _1.gemspec&.dependencies&.map(&:name) }
|
296
294
|
end
|
297
295
|
|
298
|
-
|
296
|
+
#: -> Array[String]
|
299
297
|
def gather_direct_and_indirect_dependencies
|
300
298
|
Bundler.with_original_env { Bundler.default_gemfile }
|
301
299
|
Bundler.locked_gems&.specs&.map(&:name) || []
|
data/lib/ruby_lsp/internal.rb
CHANGED
@@ -25,6 +25,7 @@ require "fileutils"
|
|
25
25
|
require "open3"
|
26
26
|
require "securerandom"
|
27
27
|
require "shellwords"
|
28
|
+
require "set"
|
28
29
|
|
29
30
|
require "ruby-lsp"
|
30
31
|
require "ruby_lsp/base_server"
|
@@ -79,6 +80,7 @@ require "ruby_lsp/requests/document_link"
|
|
79
80
|
require "ruby_lsp/requests/document_symbol"
|
80
81
|
require "ruby_lsp/requests/folding_ranges"
|
81
82
|
require "ruby_lsp/requests/formatting"
|
83
|
+
require "ruby_lsp/requests/go_to_relevant_file"
|
82
84
|
require "ruby_lsp/requests/hover"
|
83
85
|
require "ruby_lsp/requests/inlay_hints"
|
84
86
|
require "ruby_lsp/requests/on_type_formatting"
|
@@ -6,7 +6,6 @@ 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
11
|
BASE_COMMAND = T.let(
|
@@ -20,18 +19,9 @@ module RubyLsp
|
|
20
19
|
)
|
21
20
|
ACCESS_MODIFIERS = T.let([:public, :private, :protected], T::Array[Symbol])
|
22
21
|
SUPPORTED_TEST_LIBRARIES = T.let(["minitest", "test-unit"], T::Array[String])
|
23
|
-
DESCRIBE_KEYWORD = T.let(:describe, Symbol)
|
24
|
-
IT_KEYWORD = T.let(:it, Symbol)
|
25
22
|
DYNAMIC_REFERENCE_MARKER = T.let("<dynamic_reference>", String)
|
26
23
|
|
27
|
-
|
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
|
24
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
35
25
|
def initialize(response_builder, global_state, uri, dispatcher)
|
36
26
|
@response_builder = response_builder
|
37
27
|
@global_state = global_state
|
@@ -59,7 +49,7 @@ module RubyLsp
|
|
59
49
|
)
|
60
50
|
end
|
61
51
|
|
62
|
-
|
52
|
+
#: (Prism::ClassNode node) -> void
|
63
53
|
def on_class_node_enter(node)
|
64
54
|
@visibility_stack.push([:public, :public])
|
65
55
|
class_name = node.constant_path.slice
|
@@ -79,7 +69,7 @@ module RubyLsp
|
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
82
|
-
|
72
|
+
#: (Prism::ClassNode node) -> void
|
83
73
|
def on_class_node_leave(node)
|
84
74
|
@visibility_stack.pop
|
85
75
|
@group_stack.pop
|
@@ -91,7 +81,7 @@ module RubyLsp
|
|
91
81
|
end
|
92
82
|
end
|
93
83
|
|
94
|
-
|
84
|
+
#: (Prism::DefNode node) -> void
|
95
85
|
def on_def_node_enter(node)
|
96
86
|
@def_depth += 1
|
97
87
|
return if @def_depth > 1
|
@@ -114,12 +104,12 @@ module RubyLsp
|
|
114
104
|
end
|
115
105
|
end
|
116
106
|
|
117
|
-
|
107
|
+
#: (Prism::DefNode node) -> void
|
118
108
|
def on_def_node_leave(node)
|
119
109
|
@def_depth -= 1
|
120
110
|
end
|
121
111
|
|
122
|
-
|
112
|
+
#: (Prism::ModuleNode node) -> void
|
123
113
|
def on_module_node_enter(node)
|
124
114
|
if (path = namespace_constant_name(node))
|
125
115
|
@group_stack.push(path)
|
@@ -128,12 +118,12 @@ module RubyLsp
|
|
128
118
|
end
|
129
119
|
end
|
130
120
|
|
131
|
-
|
121
|
+
#: (Prism::ModuleNode node) -> void
|
132
122
|
def on_module_node_leave(node)
|
133
123
|
@group_stack.pop
|
134
124
|
end
|
135
125
|
|
136
|
-
|
126
|
+
#: (Prism::CallNode node) -> void
|
137
127
|
def on_call_node_enter(node)
|
138
128
|
name = node.name
|
139
129
|
arguments = node.arguments
|
@@ -151,23 +141,21 @@ module RubyLsp
|
|
151
141
|
return
|
152
142
|
end
|
153
143
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
add_spec_code_lens(node, kind: :example)
|
162
|
-
end
|
144
|
+
case name
|
145
|
+
when :describe
|
146
|
+
add_spec_code_lens(node, kind: :group)
|
147
|
+
@group_id_stack.push(@group_id)
|
148
|
+
@group_id += 1
|
149
|
+
when :it, :specify # `specify` is an alias for `it`
|
150
|
+
add_spec_code_lens(node, kind: :example)
|
163
151
|
end
|
164
152
|
end
|
165
153
|
|
166
|
-
|
154
|
+
#: (Prism::CallNode node) -> void
|
167
155
|
def on_call_node_leave(node)
|
168
156
|
_, prev_visibility = @visibility_stack.pop
|
169
157
|
@visibility_stack.push([prev_visibility, prev_visibility])
|
170
|
-
if node.name ==
|
158
|
+
if node.name == :describe
|
171
159
|
@group_id_stack.pop
|
172
160
|
@group_stack.pop
|
173
161
|
end
|
@@ -175,7 +163,7 @@ module RubyLsp
|
|
175
163
|
|
176
164
|
private
|
177
165
|
|
178
|
-
|
166
|
+
#: (Prism::Node node, name: String, command: String, kind: Symbol, ?id: String) -> void
|
179
167
|
def add_test_code_lens(node, name:, command:, kind:, id: name)
|
180
168
|
# don't add code lenses if the test library is not supported or unknown
|
181
169
|
return unless SUPPORTED_TEST_LIBRARIES.include?(@global_state.test_library) && @path
|
@@ -221,13 +209,7 @@ module RubyLsp
|
|
221
209
|
)
|
222
210
|
end
|
223
211
|
|
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
|
212
|
+
#: (?group_stack: Array[String], ?spec_name: String?, ?method_name: String?) -> String
|
231
213
|
def generate_test_command(group_stack: [], spec_name: nil, method_name: nil)
|
232
214
|
path = T.must(@path)
|
233
215
|
command = BASE_COMMAND
|
@@ -274,7 +256,7 @@ module RubyLsp
|
|
274
256
|
command
|
275
257
|
end
|
276
258
|
|
277
|
-
|
259
|
+
#: (Prism::CallNode node, kind: Symbol) -> void
|
278
260
|
def add_spec_code_lens(node, kind:)
|
279
261
|
arguments = node.arguments
|
280
262
|
return unless arguments
|
@@ -312,7 +294,7 @@ module RubyLsp
|
|
312
294
|
end
|
313
295
|
end
|
314
296
|
|
315
|
-
|
297
|
+
#: (group_stack: Array[String], ?method_name: String?) -> String
|
316
298
|
def generate_fully_qualified_id(group_stack:, method_name: nil)
|
317
299
|
if method_name
|
318
300
|
# 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,
|
@@ -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|
|