ruby-lsp 0.23.11 → 0.23.17
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 +20 -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 +82 -116
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +134 -183
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -10
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +97 -217
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +139 -281
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +18 -19
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +23 -55
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +47 -61
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +17 -19
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +7 -11
- data/lib/ruby_indexer/test/class_variables_test.rb +14 -14
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +65 -40
- data/lib/ruby_indexer/test/configuration_test.rb +48 -7
- data/lib/ruby_indexer/test/constant_test.rb +34 -34
- data/lib/ruby_indexer/test/enhancements_test.rb +1 -1
- data/lib/ruby_indexer/test/index_test.rb +146 -135
- data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
- data/lib/ruby_indexer/test/method_test.rb +149 -123
- data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +68 -73
- data/lib/ruby_indexer/test/test_case.rb +9 -3
- data/lib/ruby_indexer/test/uri_test.rb +15 -2
- 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 +40 -54
- data/lib/ruby_lsp/erb_document.rb +37 -41
- data/lib/ruby_lsp/global_state.rb +52 -57
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +82 -89
- data/lib/ruby_lsp/listeners/completion.rb +67 -73
- data/lib/ruby_lsp/listeners/definition.rb +44 -58
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +50 -70
- data/lib/ruby_lsp/listeners/document_symbol.rb +38 -52
- data/lib/ruby_lsp/listeners/folding_ranges.rb +40 -43
- data/lib/ruby_lsp/listeners/hover.rb +92 -110
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +54 -56
- data/lib/ruby_lsp/listeners/signature_help.rb +12 -27
- 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 +167 -90
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +9 -7
- data/lib/ruby_lsp/requests/code_action_resolve.rb +63 -59
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +20 -19
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +6 -6
- data/lib/ruby_lsp/requests/definition.rb +7 -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 +85 -0
- data/lib/ruby_lsp/requests/hover.rb +10 -20
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +32 -40
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +5 -15
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +9 -53
- data/lib/ruby_lsp/requests/rename.rb +20 -46
- data/lib/ruby_lsp/requests/request.rb +8 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +6 -6
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +16 -35
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +7 -8
- 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 +15 -55
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +11 -14
- 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 +20 -32
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +16 -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 +14 -19
- data/lib/ruby_lsp/response_builders/hover.rb +11 -14
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +60 -88
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +43 -10
- data/lib/ruby_lsp/ruby_document.rb +24 -92
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/scripts/compose_bundle.rb +6 -4
- data/lib/ruby_lsp/server.rb +182 -99
- data/lib/ruby_lsp/setup_bundler.rb +65 -60
- data/lib/ruby_lsp/static_docs.rb +11 -7
- data/lib/ruby_lsp/store.rb +29 -47
- data/lib/ruby_lsp/test_helper.rb +2 -12
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +191 -0
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +105 -0
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +94 -0
- data/lib/ruby_lsp/type_inferrer.rb +13 -14
- data/lib/ruby_lsp/utils.rb +92 -83
- metadata +9 -3
data/lib/ruby_lsp/addon.rb
CHANGED
@@ -25,42 +25,34 @@ module RubyLsp
|
|
25
25
|
|
26
26
|
abstract!
|
27
27
|
|
28
|
-
@addons =
|
29
|
-
@addon_classes =
|
28
|
+
@addons = [] #: Array[Addon]
|
29
|
+
@addon_classes = [] #: Array[singleton(Addon)]
|
30
30
|
# Add-on instances that have declared a handler to accept file watcher events
|
31
|
-
@file_watcher_addons =
|
31
|
+
@file_watcher_addons = [] #: Array[Addon]
|
32
32
|
|
33
33
|
AddonNotFoundError = Class.new(StandardError)
|
34
34
|
|
35
35
|
class IncompatibleApiError < StandardError; end
|
36
36
|
|
37
37
|
class << self
|
38
|
-
|
39
|
-
|
40
|
-
sig { returns(T::Array[Addon]) }
|
38
|
+
#: Array[Addon]
|
41
39
|
attr_accessor :addons
|
42
40
|
|
43
|
-
|
41
|
+
#: Array[Addon]
|
44
42
|
attr_accessor :file_watcher_addons
|
45
43
|
|
46
|
-
|
44
|
+
#: Array[singleton(Addon)]
|
47
45
|
attr_reader :addon_classes
|
48
46
|
|
49
47
|
# Automatically track and instantiate add-on classes
|
50
|
-
|
48
|
+
#: (singleton(Addon) child_class) -> void
|
51
49
|
def inherited(child_class)
|
52
50
|
addon_classes << child_class
|
53
51
|
super
|
54
52
|
end
|
55
53
|
|
56
54
|
# Discovers and loads all add-ons. Returns a list of errors when trying to require add-ons
|
57
|
-
|
58
|
-
params(
|
59
|
-
global_state: GlobalState,
|
60
|
-
outgoing_queue: Thread::Queue,
|
61
|
-
include_project_addons: T::Boolean,
|
62
|
-
).returns(T::Array[StandardError])
|
63
|
-
end
|
55
|
+
#: (GlobalState global_state, Thread::Queue outgoing_queue, ?include_project_addons: bool) -> Array[StandardError]
|
64
56
|
def load_addons(global_state, outgoing_queue, include_project_addons: true)
|
65
57
|
# Require all add-ons entry points, which should be placed under
|
66
58
|
# `some_gem/lib/ruby_lsp/your_gem_name/addon.rb` or in the workspace under
|
@@ -98,7 +90,7 @@ module RubyLsp
|
|
98
90
|
end
|
99
91
|
|
100
92
|
# Unloads all add-ons. Only intended to be invoked once when shutting down the Ruby LSP server
|
101
|
-
|
93
|
+
#: -> void
|
102
94
|
def unload_addons
|
103
95
|
@addons.each(&:deactivate)
|
104
96
|
@addons.clear
|
@@ -112,7 +104,7 @@ module RubyLsp
|
|
112
104
|
# Important: if the add-on is not found, AddonNotFoundError will be raised. If the add-on is found, but its
|
113
105
|
# current version does not satisfy the given version constraint, then IncompatibleApiError will be raised. It is
|
114
106
|
# the responsibility of the add-ons using this API to handle these errors appropriately.
|
115
|
-
|
107
|
+
#: (String addon_name, *String version_constraints) -> Addon
|
116
108
|
def get(addon_name, *version_constraints)
|
117
109
|
if version_constraints.empty?
|
118
110
|
raise IncompatibleApiError, "Must specify version constraints when accessing other add-ons"
|
@@ -144,7 +136,7 @@ module RubyLsp
|
|
144
136
|
# end
|
145
137
|
# end
|
146
138
|
# ```
|
147
|
-
|
139
|
+
#: (*String version_constraints) -> void
|
148
140
|
def depend_on_ruby_lsp!(*version_constraints)
|
149
141
|
version_object = Gem::Version.new(RubyLsp::VERSION)
|
150
142
|
|
@@ -155,23 +147,23 @@ module RubyLsp
|
|
155
147
|
end
|
156
148
|
end
|
157
149
|
|
158
|
-
|
150
|
+
#: -> void
|
159
151
|
def initialize
|
160
|
-
@errors =
|
152
|
+
@errors = [] #: Array[StandardError]
|
161
153
|
end
|
162
154
|
|
163
|
-
|
155
|
+
#: (StandardError error) -> self
|
164
156
|
def add_error(error)
|
165
157
|
@errors << error
|
166
158
|
self
|
167
159
|
end
|
168
160
|
|
169
|
-
|
161
|
+
#: -> bool
|
170
162
|
def error?
|
171
163
|
@errors.any?
|
172
164
|
end
|
173
165
|
|
174
|
-
|
166
|
+
#: -> String
|
175
167
|
def formatted_errors
|
176
168
|
<<~ERRORS
|
177
169
|
#{name}:
|
@@ -179,7 +171,7 @@ module RubyLsp
|
|
179
171
|
ERRORS
|
180
172
|
end
|
181
173
|
|
182
|
-
|
174
|
+
#: -> String
|
183
175
|
def errors_details
|
184
176
|
@errors.map(&:full_message).join("\n\n")
|
185
177
|
end
|
@@ -207,69 +199,50 @@ module RubyLsp
|
|
207
199
|
# original request so that the response is delegated to the correct add-on and must override this method to handle
|
208
200
|
# the response
|
209
201
|
# https://microsoft.github.io/language-server-protocol/specification#window_showMessageRequest
|
210
|
-
|
202
|
+
# @overridable
|
203
|
+
#: (String title) -> void
|
211
204
|
def handle_window_show_message_response(title); end
|
212
205
|
|
213
206
|
# Creates a new CodeLens listener. This method is invoked on every CodeLens request
|
214
|
-
|
215
|
-
|
216
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
|
217
|
-
uri: URI::Generic,
|
218
|
-
dispatcher: Prism::Dispatcher,
|
219
|
-
).void
|
220
|
-
end
|
207
|
+
# @overridable
|
208
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
221
209
|
def create_code_lens_listener(response_builder, uri, dispatcher); end
|
222
210
|
|
223
211
|
# Creates a new Hover listener. This method is invoked on every Hover request
|
224
|
-
|
225
|
-
|
226
|
-
response_builder: ResponseBuilders::Hover,
|
227
|
-
node_context: NodeContext,
|
228
|
-
dispatcher: Prism::Dispatcher,
|
229
|
-
).void
|
230
|
-
end
|
212
|
+
# @overridable
|
213
|
+
#: (ResponseBuilders::Hover response_builder, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
231
214
|
def create_hover_listener(response_builder, node_context, dispatcher); end
|
232
215
|
|
233
216
|
# Creates a new DocumentSymbol listener. This method is invoked on every DocumentSymbol request
|
234
|
-
|
235
|
-
|
236
|
-
response_builder: ResponseBuilders::DocumentSymbol,
|
237
|
-
dispatcher: Prism::Dispatcher,
|
238
|
-
).void
|
239
|
-
end
|
217
|
+
# @overridable
|
218
|
+
#: (ResponseBuilders::DocumentSymbol response_builder, Prism::Dispatcher dispatcher) -> void
|
240
219
|
def create_document_symbol_listener(response_builder, dispatcher); end
|
241
220
|
|
242
|
-
|
243
|
-
|
244
|
-
response_builder: ResponseBuilders::SemanticHighlighting,
|
245
|
-
dispatcher: Prism::Dispatcher,
|
246
|
-
).void
|
247
|
-
end
|
221
|
+
# @overridable
|
222
|
+
#: (ResponseBuilders::SemanticHighlighting response_builder, Prism::Dispatcher dispatcher) -> void
|
248
223
|
def create_semantic_highlighting_listener(response_builder, dispatcher); end
|
249
224
|
|
250
225
|
# Creates a new Definition listener. This method is invoked on every Definition request
|
251
|
-
|
252
|
-
|
253
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
|
254
|
-
Interface::Location,
|
255
|
-
Interface::LocationLink,
|
256
|
-
)],
|
257
|
-
uri: URI::Generic,
|
258
|
-
node_context: NodeContext,
|
259
|
-
dispatcher: Prism::Dispatcher,
|
260
|
-
).void
|
261
|
-
end
|
226
|
+
# @overridable
|
227
|
+
#: (ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] response_builder, URI::Generic uri, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
262
228
|
def create_definition_listener(response_builder, uri, node_context, dispatcher); end
|
263
229
|
|
264
230
|
# Creates a new Completion listener. This method is invoked on every Completion request
|
265
|
-
|
266
|
-
|
267
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
|
268
|
-
node_context: NodeContext,
|
269
|
-
dispatcher: Prism::Dispatcher,
|
270
|
-
uri: URI::Generic,
|
271
|
-
).void
|
272
|
-
end
|
231
|
+
# @overridable
|
232
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, NodeContext node_context, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
273
233
|
def create_completion_listener(response_builder, node_context, dispatcher, uri); end
|
234
|
+
|
235
|
+
# Creates a new Discover Tests listener. This method is invoked on every DiscoverTests request
|
236
|
+
# @overridable
|
237
|
+
#: (ResponseBuilders::TestCollection response_builder, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
238
|
+
def create_discover_tests_listener(response_builder, dispatcher, uri); end
|
239
|
+
|
240
|
+
# Resolves the minimal set of commands required to execute the requested tests. Add-ons are responsible for only
|
241
|
+
# handling items related to the framework they add support for and have discovered themselves
|
242
|
+
# @overridable
|
243
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
244
|
+
def resolve_test_commands(items)
|
245
|
+
[]
|
246
|
+
end
|
274
247
|
end
|
275
248
|
end
|
data/lib/ruby_lsp/base_server.rb
CHANGED
@@ -8,30 +8,27 @@ module RubyLsp
|
|
8
8
|
|
9
9
|
abstract!
|
10
10
|
|
11
|
-
|
11
|
+
#: (**untyped options) -> void
|
12
12
|
def initialize(**options)
|
13
|
-
@test_mode =
|
14
|
-
@setup_error =
|
15
|
-
@install_error =
|
16
|
-
@writer =
|
17
|
-
@reader =
|
18
|
-
@incoming_queue =
|
19
|
-
@outgoing_queue =
|
20
|
-
@cancelled_requests =
|
21
|
-
@worker =
|
22
|
-
@current_request_id =
|
23
|
-
@global_state =
|
24
|
-
@store =
|
25
|
-
@outgoing_dispatcher =
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@global_state.synchronize { @writer.write(message.to_hash) }
|
30
|
-
end
|
13
|
+
@test_mode = options[:test_mode] #: bool?
|
14
|
+
@setup_error = options[:setup_error] #: StandardError?
|
15
|
+
@install_error = options[:install_error] #: StandardError?
|
16
|
+
@writer = Transport::Stdio::Writer.new #: Transport::Stdio::Writer
|
17
|
+
@reader = Transport::Stdio::Reader.new #: Transport::Stdio::Reader
|
18
|
+
@incoming_queue = Thread::Queue.new #: Thread::Queue
|
19
|
+
@outgoing_queue = Thread::Queue.new #: Thread::Queue
|
20
|
+
@cancelled_requests = [] #: Array[Integer]
|
21
|
+
@worker = new_worker #: Thread
|
22
|
+
@current_request_id = 1 #: Integer
|
23
|
+
@global_state = GlobalState.new #: GlobalState
|
24
|
+
@store = Store.new(@global_state) #: Store
|
25
|
+
@outgoing_dispatcher = Thread.new do
|
26
|
+
unless @test_mode
|
27
|
+
while (message = @outgoing_queue.pop)
|
28
|
+
@global_state.synchronize { @writer.write(message.to_hash) }
|
31
29
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
)
|
30
|
+
end
|
31
|
+
end #: Thread
|
35
32
|
|
36
33
|
Thread.main.priority = 1
|
37
34
|
|
@@ -41,7 +38,7 @@ module RubyLsp
|
|
41
38
|
process_message(initialize_request) if initialize_request
|
42
39
|
end
|
43
40
|
|
44
|
-
|
41
|
+
#: -> void
|
45
42
|
def start
|
46
43
|
@reader.read do |message|
|
47
44
|
method = message[:method]
|
@@ -108,7 +105,7 @@ module RubyLsp
|
|
108
105
|
end
|
109
106
|
end
|
110
107
|
|
111
|
-
|
108
|
+
#: -> void
|
112
109
|
def run_shutdown
|
113
110
|
@incoming_queue.clear
|
114
111
|
@outgoing_queue.clear
|
@@ -122,13 +119,13 @@ module RubyLsp
|
|
122
119
|
end
|
123
120
|
|
124
121
|
# This method is only intended to be used in tests! Pops the latest response that would be sent to the client
|
125
|
-
|
122
|
+
#: -> untyped
|
126
123
|
def pop_response
|
127
124
|
@outgoing_queue.pop
|
128
125
|
end
|
129
126
|
|
130
127
|
# This method is only intended to be used in tests! Pushes a message to the incoming queue directly
|
131
|
-
|
128
|
+
#: (Hash[Symbol, untyped] message) -> void
|
132
129
|
def push_message(message)
|
133
130
|
@incoming_queue << message
|
134
131
|
end
|
@@ -139,16 +136,16 @@ module RubyLsp
|
|
139
136
|
sig { abstract.void }
|
140
137
|
def shutdown; end
|
141
138
|
|
142
|
-
|
139
|
+
#: (Integer id, String message, ?type: Integer) -> void
|
143
140
|
def fail_request_and_notify(id, message, type: Constant::MessageType::INFO)
|
144
141
|
send_message(Error.new(id: id, code: Constant::ErrorCodes::REQUEST_FAILED, message: message))
|
145
142
|
send_message(Notification.window_show_message(message, type: type))
|
146
143
|
end
|
147
144
|
|
148
|
-
|
145
|
+
#: -> Thread
|
149
146
|
def new_worker
|
150
147
|
Thread.new do
|
151
|
-
while (message =
|
148
|
+
while (message = @incoming_queue.pop)
|
152
149
|
id = message[:id]
|
153
150
|
|
154
151
|
# Check if the request was cancelled before trying to process it
|
@@ -165,7 +162,7 @@ module RubyLsp
|
|
165
162
|
end
|
166
163
|
end
|
167
164
|
|
168
|
-
|
165
|
+
#: ((Result | Error | Notification | Request) message) -> void
|
169
166
|
def send_message(message)
|
170
167
|
# When we're shutting down the server, there's a small race condition between closing the thread queues and
|
171
168
|
# finishing remaining requests. We may close the queue in the middle of processing a request, which will then fail
|
@@ -176,12 +173,12 @@ module RubyLsp
|
|
176
173
|
@current_request_id += 1 if message.is_a?(Request)
|
177
174
|
end
|
178
175
|
|
179
|
-
|
176
|
+
#: (Integer id) -> void
|
180
177
|
def send_empty_response(id)
|
181
178
|
send_message(Result.new(id: id, response: nil))
|
182
179
|
end
|
183
180
|
|
184
|
-
|
181
|
+
#: (String message, ?type: Integer) -> void
|
185
182
|
def send_log_message(message, type: Constant::MessageType::LOG)
|
186
183
|
send_message(Notification.window_log_message(message, type: Constant::MessageType::LOG))
|
187
184
|
end
|
@@ -5,40 +5,38 @@ module RubyLsp
|
|
5
5
|
# This class stores all client capabilities that the Ruby LSP and its add-ons depend on to ensure that we're
|
6
6
|
# not enabling functionality unsupported by the editor connecting to the server
|
7
7
|
class ClientCapabilities
|
8
|
-
|
9
|
-
|
10
|
-
sig { returns(T::Boolean) }
|
8
|
+
#: bool
|
11
9
|
attr_reader :supports_watching_files,
|
12
10
|
:supports_request_delegation,
|
13
11
|
:window_show_message_supports_extra_properties,
|
14
12
|
:supports_progress,
|
15
13
|
:supports_diagnostic_refresh
|
16
14
|
|
17
|
-
|
15
|
+
#: -> void
|
18
16
|
def initialize
|
19
17
|
# The editor supports watching files. This requires two capabilities: dynamic registration and relative pattern
|
20
18
|
# support
|
21
|
-
@supports_watching_files =
|
19
|
+
@supports_watching_files = false #: bool
|
22
20
|
|
23
21
|
# The editor supports request delegation. This is an experimental capability since request delegation has not been
|
24
22
|
# standardized into the LSP spec yet
|
25
|
-
@supports_request_delegation =
|
23
|
+
@supports_request_delegation = false #: bool
|
26
24
|
|
27
25
|
# The editor supports extra arbitrary properties for `window/showMessageRequest`. Necessary for add-ons to show
|
28
26
|
# dialogs with user interactions
|
29
|
-
@window_show_message_supports_extra_properties =
|
27
|
+
@window_show_message_supports_extra_properties = false #: bool
|
30
28
|
|
31
29
|
# Which resource operations the editor supports, like renaming files
|
32
|
-
@supported_resource_operations =
|
30
|
+
@supported_resource_operations = [] #: Array[String]
|
33
31
|
|
34
32
|
# The editor supports displaying progress requests
|
35
|
-
@supports_progress =
|
33
|
+
@supports_progress = false #: bool
|
36
34
|
|
37
35
|
# The editor supports server initiated refresh for diagnostics
|
38
|
-
@supports_diagnostic_refresh =
|
36
|
+
@supports_diagnostic_refresh = false #: bool
|
39
37
|
end
|
40
38
|
|
41
|
-
|
39
|
+
#: (Hash[Symbol, untyped] capabilities) -> void
|
42
40
|
def apply_client_capabilities(capabilities)
|
43
41
|
workspace_capabilities = capabilities[:workspace] || {}
|
44
42
|
|
@@ -65,7 +63,7 @@ module RubyLsp
|
|
65
63
|
@supports_diagnostic_refresh = workspace_capabilities.dig(:diagnostics, :refreshSupport) || false
|
66
64
|
end
|
67
65
|
|
68
|
-
|
66
|
+
#: -> bool
|
69
67
|
def supports_rename?
|
70
68
|
@supported_resource_operations.include?("rename")
|
71
69
|
end
|
data/lib/ruby_lsp/document.rb
CHANGED
@@ -3,14 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class Document
|
6
|
-
class LanguageId < T::Enum
|
7
|
-
enums do
|
8
|
-
Ruby = new("ruby")
|
9
|
-
ERB = new("erb")
|
10
|
-
RBS = new("rbs")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
extend T::Sig
|
15
7
|
extend T::Helpers
|
16
8
|
extend T::Generic
|
@@ -21,61 +13,60 @@ module RubyLsp
|
|
21
13
|
# This maximum number of characters for providing expensive features, like semantic highlighting and diagnostics.
|
22
14
|
# This is the same number used by the TypeScript extension in VS Code
|
23
15
|
MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES = 100_000
|
24
|
-
EMPTY_CACHE =
|
16
|
+
EMPTY_CACHE = Object.new.freeze #: Object
|
25
17
|
|
26
18
|
abstract!
|
27
19
|
|
28
|
-
|
20
|
+
#: ParseResultType
|
29
21
|
attr_reader :parse_result
|
30
22
|
|
31
|
-
|
23
|
+
#: String
|
32
24
|
attr_reader :source
|
33
25
|
|
34
|
-
|
26
|
+
#: Integer
|
35
27
|
attr_reader :version
|
36
28
|
|
37
|
-
|
29
|
+
#: URI::Generic
|
38
30
|
attr_reader :uri
|
39
31
|
|
40
|
-
|
32
|
+
#: Encoding
|
41
33
|
attr_reader :encoding
|
42
34
|
|
43
|
-
|
35
|
+
#: Edit?
|
44
36
|
attr_reader :last_edit
|
45
37
|
|
46
|
-
|
38
|
+
#: (Interface::SemanticTokens | Object)
|
47
39
|
attr_accessor :semantic_tokens
|
48
40
|
|
49
|
-
|
41
|
+
#: (source: String, version: Integer, uri: URI::Generic, global_state: GlobalState) -> void
|
50
42
|
def initialize(source:, version:, uri:, global_state:)
|
51
43
|
@source = source
|
52
44
|
@version = version
|
53
45
|
@global_state = global_state
|
54
|
-
@cache =
|
55
|
-
@semantic_tokens =
|
56
|
-
@encoding =
|
57
|
-
@uri =
|
58
|
-
@needs_parsing =
|
59
|
-
@
|
60
|
-
|
46
|
+
@cache = Hash.new(EMPTY_CACHE) #: Hash[String, untyped]
|
47
|
+
@semantic_tokens = EMPTY_CACHE #: (Interface::SemanticTokens | Object)
|
48
|
+
@encoding = global_state.encoding #: Encoding
|
49
|
+
@uri = uri #: URI::Generic
|
50
|
+
@needs_parsing = true #: bool
|
51
|
+
@last_edit = nil #: Edit?
|
52
|
+
|
53
|
+
# Workaround to be able to type parse_result properly. It is immediately set when invoking parse!
|
54
|
+
@parse_result = ( # rubocop:disable Style/RedundantParentheses
|
55
|
+
nil #: as untyped
|
56
|
+
) #: ParseResultType
|
57
|
+
|
61
58
|
parse!
|
62
59
|
end
|
63
60
|
|
64
|
-
|
61
|
+
#: (Document[untyped] other) -> bool
|
65
62
|
def ==(other)
|
66
63
|
self.class == other.class && uri == other.uri && @source == other.source
|
67
64
|
end
|
68
65
|
|
69
|
-
sig { abstract.returns(
|
66
|
+
sig { abstract.returns(Symbol) }
|
70
67
|
def language_id; end
|
71
68
|
|
72
|
-
|
73
|
-
type_parameters(:T)
|
74
|
-
.params(
|
75
|
-
request_name: String,
|
76
|
-
block: T.proc.params(document: Document[ParseResultType]).returns(T.type_parameter(:T)),
|
77
|
-
).returns(T.type_parameter(:T))
|
78
|
-
end
|
69
|
+
#: [T] (String request_name) { (Document[ParseResultType] document) -> T } -> T
|
79
70
|
def cache_fetch(request_name, &block)
|
80
71
|
cached = @cache[request_name]
|
81
72
|
return cached if cached != EMPTY_CACHE
|
@@ -85,17 +76,17 @@ module RubyLsp
|
|
85
76
|
result
|
86
77
|
end
|
87
78
|
|
88
|
-
|
79
|
+
#: [T] (String request_name, T value) -> T
|
89
80
|
def cache_set(request_name, value)
|
90
81
|
@cache[request_name] = value
|
91
82
|
end
|
92
83
|
|
93
|
-
|
84
|
+
#: (String request_name) -> untyped
|
94
85
|
def cache_get(request_name)
|
95
86
|
@cache[request_name]
|
96
87
|
end
|
97
88
|
|
98
|
-
|
89
|
+
#: (Array[Hash[Symbol, untyped]] edits, version: Integer) -> void
|
99
90
|
def push_edits(edits, version:)
|
100
91
|
edits.each do |edit|
|
101
92
|
range = edit[:range]
|
@@ -132,17 +123,12 @@ module RubyLsp
|
|
132
123
|
sig { abstract.returns(T::Boolean) }
|
133
124
|
def syntax_error?; end
|
134
125
|
|
135
|
-
|
126
|
+
#: -> bool
|
136
127
|
def past_expensive_limit?
|
137
128
|
@source.length > MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES
|
138
129
|
end
|
139
130
|
|
140
|
-
|
141
|
-
params(
|
142
|
-
start_pos: T::Hash[Symbol, T.untyped],
|
143
|
-
end_pos: T.nilable(T::Hash[Symbol, T.untyped]),
|
144
|
-
).returns([Integer, T.nilable(Integer)])
|
145
|
-
end
|
131
|
+
#: (Hash[Symbol, untyped] start_pos, ?Hash[Symbol, untyped]? end_pos) -> [Integer, Integer?]
|
146
132
|
def find_index_by_position(start_pos, end_pos = nil)
|
147
133
|
@global_state.synchronize do
|
148
134
|
scanner = create_scanner
|
@@ -154,7 +140,7 @@ module RubyLsp
|
|
154
140
|
|
155
141
|
private
|
156
142
|
|
157
|
-
|
143
|
+
#: -> Scanner
|
158
144
|
def create_scanner
|
159
145
|
Scanner.new(@source, @encoding)
|
160
146
|
end
|
@@ -165,10 +151,10 @@ module RubyLsp
|
|
165
151
|
|
166
152
|
abstract!
|
167
153
|
|
168
|
-
|
154
|
+
#: Hash[Symbol, untyped]
|
169
155
|
attr_reader :range
|
170
156
|
|
171
|
-
|
157
|
+
#: (Hash[Symbol, untyped] range) -> void
|
172
158
|
def initialize(range)
|
173
159
|
@range = range
|
174
160
|
end
|
@@ -181,20 +167,20 @@ module RubyLsp
|
|
181
167
|
class Scanner
|
182
168
|
extend T::Sig
|
183
169
|
|
184
|
-
LINE_BREAK =
|
170
|
+
LINE_BREAK = 0x0A #: Integer
|
185
171
|
# After character 0xFFFF, UTF-16 considers characters to have length 2 and we have to account for that
|
186
|
-
SURROGATE_PAIR_START =
|
172
|
+
SURROGATE_PAIR_START = 0xFFFF #: Integer
|
187
173
|
|
188
|
-
|
174
|
+
#: (String source, Encoding encoding) -> void
|
189
175
|
def initialize(source, encoding)
|
190
|
-
@current_line =
|
191
|
-
@pos =
|
192
|
-
@source =
|
176
|
+
@current_line = 0 #: Integer
|
177
|
+
@pos = 0 #: Integer
|
178
|
+
@source = source.codepoints #: Array[Integer]
|
193
179
|
@encoding = encoding
|
194
180
|
end
|
195
181
|
|
196
182
|
# Finds the character index inside the source string for a given line and column
|
197
|
-
|
183
|
+
#: (Hash[Symbol, untyped] position) -> Integer
|
198
184
|
def find_char_position(position)
|
199
185
|
# Find the character index for the beginning of the requested line
|
200
186
|
until @current_line == position[:line]
|
@@ -224,7 +210,7 @@ module RubyLsp
|
|
224
210
|
|
225
211
|
# Subtract 1 for each character after 0xFFFF in the current line from the column position, so that we hit the
|
226
212
|
# right character in the UTF-8 representation
|
227
|
-
|
213
|
+
#: (Integer current_position, Integer requested_position) -> Integer
|
228
214
|
def utf_16_character_position_correction(current_position, requested_position)
|
229
215
|
utf16_unicode_correction = 0
|
230
216
|
|