ruby-lsp 0.23.12 → 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/VERSION +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +31 -40
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +56 -22
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +15 -18
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +8 -11
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +2 -2
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +2 -2
- data/lib/ruby_indexer/test/configuration_test.rb +10 -1
- data/lib/ruby_indexer/test/method_test.rb +26 -0
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_lsp/addon.rb +12 -4
- data/lib/ruby_lsp/base_server.rb +19 -22
- data/lib/ruby_lsp/client_capabilities.rb +6 -6
- data/lib/ruby_lsp/document.rb +13 -13
- data/lib/ruby_lsp/erb_document.rb +7 -9
- data/lib/ruby_lsp/global_state.rb +21 -24
- data/lib/ruby_lsp/listeners/code_lens.rb +59 -48
- data/lib/ruby_lsp/listeners/completion.rb +2 -2
- data/lib/ruby_lsp/listeners/definition.rb +2 -2
- data/lib/ruby_lsp/listeners/document_highlight.rb +62 -80
- data/lib/ruby_lsp/listeners/document_link.rb +34 -43
- data/lib/ruby_lsp/listeners/document_symbol.rb +1 -1
- data/lib/ruby_lsp/listeners/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/listeners/hover.rb +43 -52
- data/lib/ruby_lsp/listeners/inlay_hints.rb +1 -1
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +11 -14
- data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
- data/lib/ruby_lsp/listeners/spec_style.rb +15 -59
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +47 -81
- data/lib/ruby_lsp/node_context.rb +4 -4
- data/lib/ruby_lsp/rbs_document.rb +1 -1
- data/lib/ruby_lsp/requests/code_actions.rb +9 -12
- data/lib/ruby_lsp/requests/code_lens.rb +2 -4
- data/lib/ruby_lsp/requests/completion.rb +3 -5
- data/lib/ruby_lsp/requests/completion_resolve.rb +1 -1
- data/lib/ruby_lsp/requests/definition.rb +4 -5
- data/lib/ruby_lsp/requests/diagnostics.rb +2 -2
- data/lib/ruby_lsp/requests/discover_tests.rb +3 -2
- data/lib/ruby_lsp/requests/document_highlight.rb +2 -4
- data/lib/ruby_lsp/requests/document_link.rb +2 -4
- data/lib/ruby_lsp/requests/document_symbol.rb +1 -1
- data/lib/ruby_lsp/requests/folding_ranges.rb +3 -8
- data/lib/ruby_lsp/requests/formatting.rb +2 -2
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +3 -3
- data/lib/ruby_lsp/requests/hover.rb +2 -2
- data/lib/ruby_lsp/requests/inlay_hints.rb +2 -4
- data/lib/ruby_lsp/requests/on_type_formatting.rb +10 -13
- data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
- data/lib/ruby_lsp/requests/range_formatting.rb +2 -2
- data/lib/ruby_lsp/requests/references.rb +1 -1
- data/lib/ruby_lsp/requests/rename.rb +2 -2
- data/lib/ruby_lsp/requests/request.rb +2 -2
- data/lib/ruby_lsp/requests/selection_ranges.rb +2 -2
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +5 -7
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -1
- data/lib/ruby_lsp/requests/signature_help.rb +2 -2
- data/lib/ruby_lsp/requests/support/common.rb +1 -1
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +15 -21
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +12 -18
- data/lib/ruby_lsp/requests/support/sorbet.rb +28 -31
- data/lib/ruby_lsp/requests/support/source_uri.rb +11 -14
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +5 -9
- data/lib/ruby_lsp/requests/support/test_item.rb +4 -9
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +1 -1
- data/lib/ruby_lsp/requests/workspace_symbol.rb +1 -1
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -5
- data/lib/ruby_lsp/response_builders/hover.rb +5 -8
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +41 -47
- data/lib/ruby_lsp/response_builders/signature_help.rb +1 -1
- data/lib/ruby_lsp/response_builders/test_collection.rb +1 -1
- data/lib/ruby_lsp/ruby_document.rb +7 -20
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +7 -4
- data/lib/ruby_lsp/scope.rb +1 -1
- data/lib/ruby_lsp/server.rb +9 -1
- data/lib/ruby_lsp/setup_bundler.rb +36 -42
- data/lib/ruby_lsp/static_docs.rb +4 -7
- data/lib/ruby_lsp/store.rb +9 -12
- data/lib/ruby_lsp/test_reporter.rb +140 -4
- data/lib/ruby_lsp/test_unit_test_runner.rb +10 -8
- data/lib/ruby_lsp/utils.rb +10 -16
- metadata +3 -2
data/lib/ruby_lsp/document.rb
CHANGED
@@ -21,7 +21,7 @@ module RubyLsp
|
|
21
21
|
# This maximum number of characters for providing expensive features, like semantic highlighting and diagnostics.
|
22
22
|
# This is the same number used by the TypeScript extension in VS Code
|
23
23
|
MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES = 100_000
|
24
|
-
EMPTY_CACHE =
|
24
|
+
EMPTY_CACHE = Object.new.freeze #: Object
|
25
25
|
|
26
26
|
abstract!
|
27
27
|
|
@@ -51,13 +51,13 @@ module RubyLsp
|
|
51
51
|
@source = source
|
52
52
|
@version = version
|
53
53
|
@global_state = global_state
|
54
|
-
@cache =
|
55
|
-
@semantic_tokens =
|
56
|
-
@encoding =
|
57
|
-
@uri =
|
58
|
-
@needs_parsing =
|
59
|
-
@parse_result = T.
|
60
|
-
@last_edit =
|
54
|
+
@cache = Hash.new(EMPTY_CACHE) #: Hash[String, untyped]
|
55
|
+
@semantic_tokens = EMPTY_CACHE #: (Interface::SemanticTokens | Object)
|
56
|
+
@encoding = global_state.encoding #: Encoding
|
57
|
+
@uri = uri #: URI::Generic
|
58
|
+
@needs_parsing = true #: bool
|
59
|
+
@parse_result = T.unsafe(nil) #: ParseResultType
|
60
|
+
@last_edit = nil #: Edit?
|
61
61
|
parse!
|
62
62
|
end
|
63
63
|
|
@@ -170,15 +170,15 @@ module RubyLsp
|
|
170
170
|
class Scanner
|
171
171
|
extend T::Sig
|
172
172
|
|
173
|
-
LINE_BREAK =
|
173
|
+
LINE_BREAK = 0x0A #: Integer
|
174
174
|
# After character 0xFFFF, UTF-16 considers characters to have length 2 and we have to account for that
|
175
|
-
SURROGATE_PAIR_START =
|
175
|
+
SURROGATE_PAIR_START = 0xFFFF #: Integer
|
176
176
|
|
177
177
|
#: (String source, Encoding encoding) -> void
|
178
178
|
def initialize(source, encoding)
|
179
|
-
@current_line =
|
180
|
-
@pos =
|
181
|
-
@source =
|
179
|
+
@current_line = 0 #: Integer
|
180
|
+
@pos = 0 #: Integer
|
181
|
+
@source = source.codepoints #: Array[Integer]
|
182
182
|
@encoding = encoding
|
183
183
|
end
|
184
184
|
|
@@ -17,12 +17,10 @@ module RubyLsp
|
|
17
17
|
def initialize(source:, version:, uri:, global_state:)
|
18
18
|
# This has to be initialized before calling super because we call `parse` in the parent constructor, which
|
19
19
|
# overrides this with the proper virtual host language source
|
20
|
-
@host_language_source =
|
20
|
+
@host_language_source = "" #: String
|
21
21
|
super
|
22
|
-
@code_units_cache =
|
23
|
-
|
24
|
-
Prism::CodeUnitsCache,
|
25
|
-
))
|
22
|
+
@code_units_cache =
|
23
|
+
@parse_result.code_units_cache(@encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
|
26
24
|
end
|
27
25
|
|
28
26
|
# @override
|
@@ -78,10 +76,10 @@ module RubyLsp
|
|
78
76
|
#: (String source) -> void
|
79
77
|
def initialize(source)
|
80
78
|
@source = source
|
81
|
-
@host_language =
|
82
|
-
@ruby =
|
83
|
-
@current_pos =
|
84
|
-
@inside_ruby =
|
79
|
+
@host_language = +"" #: String
|
80
|
+
@ruby = +"" #: String
|
81
|
+
@current_pos = 0 #: Integer
|
82
|
+
@inside_ruby = false #: bool
|
85
83
|
end
|
86
84
|
|
87
85
|
#: -> void
|
@@ -35,30 +35,27 @@ module RubyLsp
|
|
35
35
|
|
36
36
|
#: -> void
|
37
37
|
def initialize
|
38
|
-
@workspace_uri =
|
39
|
-
@encoding =
|
40
|
-
|
41
|
-
@formatter =
|
42
|
-
@linters =
|
43
|
-
@test_library =
|
44
|
-
@has_type_checker =
|
45
|
-
@index =
|
46
|
-
@supported_formatters =
|
47
|
-
@type_inferrer =
|
48
|
-
@addon_settings =
|
49
|
-
@top_level_bundle =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@
|
59
|
-
@enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean])
|
60
|
-
@mutex = T.let(Mutex.new, Mutex)
|
61
|
-
@telemetry_machine_id = T.let(nil, T.nilable(String))
|
38
|
+
@workspace_uri = URI::Generic.from_path(path: Dir.pwd) #: URI::Generic
|
39
|
+
@encoding = Encoding::UTF_8 #: Encoding
|
40
|
+
|
41
|
+
@formatter = "auto" #: String
|
42
|
+
@linters = [] #: Array[String]
|
43
|
+
@test_library = "minitest" #: String
|
44
|
+
@has_type_checker = true #: bool
|
45
|
+
@index = RubyIndexer::Index.new #: RubyIndexer::Index
|
46
|
+
@supported_formatters = {} #: Hash[String, Requests::Support::Formatter]
|
47
|
+
@type_inferrer = TypeInferrer.new(@index) #: TypeInferrer
|
48
|
+
@addon_settings = {} #: Hash[String, untyped]
|
49
|
+
@top_level_bundle = begin
|
50
|
+
Bundler.with_original_env { Bundler.default_gemfile }
|
51
|
+
true
|
52
|
+
rescue Bundler::GemfileNotFound, Bundler::GitError
|
53
|
+
false
|
54
|
+
end #: bool
|
55
|
+
@client_capabilities = ClientCapabilities.new #: ClientCapabilities
|
56
|
+
@enabled_feature_flags = {} #: Hash[Symbol, bool]
|
57
|
+
@mutex = Mutex.new #: Mutex
|
58
|
+
@telemetry_machine_id = nil #: String?
|
62
59
|
end
|
63
60
|
|
64
61
|
#: [T] { -> T } -> T
|
@@ -8,33 +8,30 @@ module RubyLsp
|
|
8
8
|
class CodeLens
|
9
9
|
include Requests::Support::Common
|
10
10
|
|
11
|
-
BASE_COMMAND =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
ACCESS_MODIFIERS = T.let([:public, :private, :protected], T::Array[Symbol])
|
21
|
-
SUPPORTED_TEST_LIBRARIES = T.let(["minitest", "test-unit"], T::Array[String])
|
22
|
-
DYNAMIC_REFERENCE_MARKER = T.let("<dynamic_reference>", String)
|
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
|
23
20
|
|
24
21
|
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
25
22
|
def initialize(response_builder, global_state, uri, dispatcher)
|
26
23
|
@response_builder = response_builder
|
27
24
|
@global_state = global_state
|
28
|
-
@uri =
|
29
|
-
@path =
|
25
|
+
@uri = uri #: URI::Generic
|
26
|
+
@path = uri.to_standardized_path #: String?
|
30
27
|
# visibility_stack is a stack of [current_visibility, previous_visibility]
|
31
|
-
@visibility_stack =
|
32
|
-
@group_stack =
|
33
|
-
@group_id =
|
34
|
-
@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]
|
35
32
|
# We want to avoid adding code lenses for nested definitions
|
36
|
-
@def_depth =
|
37
|
-
@spec_id =
|
33
|
+
@def_depth = 0 #: Integer
|
34
|
+
@spec_id = 0 #: Integer
|
38
35
|
|
39
36
|
dispatcher.register(
|
40
37
|
self,
|
@@ -219,38 +216,52 @@ module RubyLsp
|
|
219
216
|
|
220
217
|
case @global_state.test_library
|
221
218
|
when "minitest"
|
222
|
-
|
223
|
-
command += if last_dynamic_reference_index
|
224
|
-
# In cases where the test path looks like `foo::Bar`
|
225
|
-
# the best we can do is match everything to the right of it.
|
226
|
-
# Tests are classes, dynamic references are only a thing for modules,
|
227
|
-
# so there must be something to the left of the available path.
|
228
|
-
group_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
|
229
|
-
if method_name
|
230
|
-
" --name " + "/::#{Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
|
231
|
-
else
|
232
|
-
# When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
|
233
|
-
# that are registered on the class itself (matches after `#`) and all tests
|
234
|
-
# that are nested inside of that class in other modules/classes (matches after `::`)
|
235
|
-
" --name " + "\"/::#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
|
236
|
-
end
|
237
|
-
elsif method_name
|
238
|
-
# We know the entire path, do an exact match
|
239
|
-
" --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
|
240
|
-
elsif spec_name
|
241
|
-
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}##{Shellwords.escape(spec_name)}$/\""
|
242
|
-
else
|
243
|
-
# Execute all tests of the selected class and tests in
|
244
|
-
# modules/classes nested inside of that class
|
245
|
-
" --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
|
246
|
-
end
|
219
|
+
command += generate_minitest_command(group_stack, method_name, spec_name)
|
247
220
|
when "test-unit"
|
248
|
-
|
249
|
-
|
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..])
|
250
237
|
|
251
238
|
if method_name
|
252
|
-
|
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("::"))}(#|::)/\""
|
253
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)
|
254
265
|
end
|
255
266
|
|
256
267
|
command
|
@@ -62,8 +62,8 @@ module RubyLsp
|
|
62
62
|
)
|
63
63
|
@response_builder = response_builder
|
64
64
|
@global_state = global_state
|
65
|
-
@index =
|
66
|
-
@type_inferrer =
|
65
|
+
@index = global_state.index #: RubyIndexer::Index
|
66
|
+
@type_inferrer = global_state.type_inferrer #: TypeInferrer
|
67
67
|
@node_context = node_context
|
68
68
|
@sorbet_level = sorbet_level
|
69
69
|
@uri = uri
|
@@ -12,8 +12,8 @@ module RubyLsp
|
|
12
12
|
def initialize(response_builder, global_state, language_id, uri, node_context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
|
13
13
|
@response_builder = response_builder
|
14
14
|
@global_state = global_state
|
15
|
-
@index =
|
16
|
-
@type_inferrer =
|
15
|
+
@index = global_state.index #: RubyIndexer::Index
|
16
|
+
@type_inferrer = global_state.type_inferrer #: TypeInferrer
|
17
17
|
@language_id = language_id
|
18
18
|
@uri = uri
|
19
19
|
@node_context = node_context
|
@@ -6,84 +6,66 @@ module RubyLsp
|
|
6
6
|
class DocumentHighlight
|
7
7
|
include Requests::Support::Common
|
8
8
|
|
9
|
-
GLOBAL_VARIABLE_NODES =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
LOCAL_NODES = T.let(
|
70
|
-
[
|
71
|
-
Prism::LocalVariableAndWriteNode,
|
72
|
-
Prism::LocalVariableOperatorWriteNode,
|
73
|
-
Prism::LocalVariableOrWriteNode,
|
74
|
-
Prism::LocalVariableReadNode,
|
75
|
-
Prism::LocalVariableTargetNode,
|
76
|
-
Prism::LocalVariableWriteNode,
|
77
|
-
Prism::BlockParameterNode,
|
78
|
-
Prism::RequiredParameterNode,
|
79
|
-
Prism::RequiredKeywordParameterNode,
|
80
|
-
Prism::OptionalKeywordParameterNode,
|
81
|
-
Prism::RestParameterNode,
|
82
|
-
Prism::OptionalParameterNode,
|
83
|
-
Prism::KeywordRestParameterNode,
|
84
|
-
],
|
85
|
-
T::Array[T.class_of(Prism::Node)],
|
86
|
-
)
|
9
|
+
GLOBAL_VARIABLE_NODES = [
|
10
|
+
Prism::GlobalVariableAndWriteNode,
|
11
|
+
Prism::GlobalVariableOperatorWriteNode,
|
12
|
+
Prism::GlobalVariableOrWriteNode,
|
13
|
+
Prism::GlobalVariableReadNode,
|
14
|
+
Prism::GlobalVariableTargetNode,
|
15
|
+
Prism::GlobalVariableWriteNode,
|
16
|
+
] #: Array[singleton(Prism::Node)]
|
17
|
+
|
18
|
+
INSTANCE_VARIABLE_NODES = [
|
19
|
+
Prism::InstanceVariableAndWriteNode,
|
20
|
+
Prism::InstanceVariableOperatorWriteNode,
|
21
|
+
Prism::InstanceVariableOrWriteNode,
|
22
|
+
Prism::InstanceVariableReadNode,
|
23
|
+
Prism::InstanceVariableTargetNode,
|
24
|
+
Prism::InstanceVariableWriteNode,
|
25
|
+
] #: Array[singleton(Prism::Node)]
|
26
|
+
|
27
|
+
CONSTANT_NODES = [
|
28
|
+
Prism::ConstantAndWriteNode,
|
29
|
+
Prism::ConstantOperatorWriteNode,
|
30
|
+
Prism::ConstantOrWriteNode,
|
31
|
+
Prism::ConstantReadNode,
|
32
|
+
Prism::ConstantTargetNode,
|
33
|
+
Prism::ConstantWriteNode,
|
34
|
+
] #: Array[singleton(Prism::Node)]
|
35
|
+
|
36
|
+
CONSTANT_PATH_NODES = [
|
37
|
+
Prism::ConstantPathAndWriteNode,
|
38
|
+
Prism::ConstantPathNode,
|
39
|
+
Prism::ConstantPathOperatorWriteNode,
|
40
|
+
Prism::ConstantPathOrWriteNode,
|
41
|
+
Prism::ConstantPathTargetNode,
|
42
|
+
Prism::ConstantPathWriteNode,
|
43
|
+
] #: Array[singleton(Prism::Node)]
|
44
|
+
|
45
|
+
CLASS_VARIABLE_NODES = [
|
46
|
+
Prism::ClassVariableAndWriteNode,
|
47
|
+
Prism::ClassVariableOperatorWriteNode,
|
48
|
+
Prism::ClassVariableOrWriteNode,
|
49
|
+
Prism::ClassVariableReadNode,
|
50
|
+
Prism::ClassVariableTargetNode,
|
51
|
+
Prism::ClassVariableWriteNode,
|
52
|
+
] #: Array[singleton(Prism::Node)]
|
53
|
+
|
54
|
+
LOCAL_NODES = [
|
55
|
+
Prism::LocalVariableAndWriteNode,
|
56
|
+
Prism::LocalVariableOperatorWriteNode,
|
57
|
+
Prism::LocalVariableOrWriteNode,
|
58
|
+
Prism::LocalVariableReadNode,
|
59
|
+
Prism::LocalVariableTargetNode,
|
60
|
+
Prism::LocalVariableWriteNode,
|
61
|
+
Prism::BlockParameterNode,
|
62
|
+
Prism::RequiredParameterNode,
|
63
|
+
Prism::RequiredKeywordParameterNode,
|
64
|
+
Prism::OptionalKeywordParameterNode,
|
65
|
+
Prism::RestParameterNode,
|
66
|
+
Prism::OptionalParameterNode,
|
67
|
+
Prism::KeywordRestParameterNode,
|
68
|
+
] #: Array[singleton(Prism::Node)]
|
87
69
|
|
88
70
|
#: (ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight] response_builder, Prism::Node? target, Prism::Node? parent, Prism::Dispatcher dispatcher, Hash[Symbol, untyped] position) -> void
|
89
71
|
def initialize(response_builder, target, parent, dispatcher, position)
|
@@ -114,8 +96,8 @@ module RubyLsp
|
|
114
96
|
[target, nil]
|
115
97
|
end
|
116
98
|
|
117
|
-
@target =
|
118
|
-
@target_value =
|
99
|
+
@target = highlight_target #: Prism::Node?
|
100
|
+
@target_value = highlight_target_value #: String?
|
119
101
|
@target_position = position
|
120
102
|
|
121
103
|
if @target
|
@@ -8,49 +8,43 @@ module RubyLsp
|
|
8
8
|
class DocumentLink
|
9
9
|
include Requests::Support::Common
|
10
10
|
|
11
|
-
GEM_TO_VERSION_MAP =
|
12
|
-
[
|
13
|
-
|
14
|
-
end.to_h.freeze,
|
15
|
-
T::Hash[String, String],
|
16
|
-
)
|
11
|
+
GEM_TO_VERSION_MAP = [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].map! do |s|
|
12
|
+
[s.name, s.version.to_s]
|
13
|
+
end.to_h.freeze #: Hash[String, String]
|
17
14
|
|
18
15
|
class << self
|
19
16
|
#: -> Hash[String, Hash[String, Hash[String, String]]]
|
20
17
|
def gem_paths
|
21
|
-
@gem_paths ||=
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
lookup[spec.name][spec.version.to_s] = {}
|
29
|
-
|
30
|
-
Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
|
31
|
-
lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
|
32
|
-
end
|
33
|
-
end
|
18
|
+
@gem_paths ||= begin
|
19
|
+
lookup = {}
|
20
|
+
|
21
|
+
Gem::Specification.stubs.each do |stub|
|
22
|
+
spec = stub.to_spec
|
23
|
+
lookup[spec.name] = {}
|
24
|
+
lookup[spec.name][spec.version.to_s] = {}
|
34
25
|
|
35
|
-
|
36
|
-
spec =
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
26
|
+
Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
|
27
|
+
lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Gem::Specification.default_stubs.each do |stub|
|
32
|
+
spec = stub.to_spec
|
33
|
+
lookup[spec.name] = {}
|
34
|
+
lookup[spec.name][spec.version.to_s] = {}
|
35
|
+
prefix_matchers = Regexp.union(spec.require_paths.map do |rp|
|
36
|
+
Regexp.new("^#{rp}/")
|
37
|
+
end)
|
38
|
+
prefix_matcher = Regexp.union(prefix_matchers, //)
|
39
|
+
|
40
|
+
spec.files.each do |file|
|
41
|
+
path = file.sub(prefix_matcher, "")
|
42
|
+
lookup[spec.name][spec.version.to_s][path] = "#{RbConfig::CONFIG["rubylibdir"]}/#{path}"
|
48
43
|
end
|
44
|
+
end
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
T.nilable(T::Hash[String, T::Hash[String, T::Hash[String, String]]]),
|
53
|
-
)
|
46
|
+
lookup
|
47
|
+
end #: Hash[String, Hash[String, Hash[String, String]]]?
|
54
48
|
end
|
55
49
|
end
|
56
50
|
|
@@ -61,13 +55,10 @@ module RubyLsp
|
|
61
55
|
@response_builder = response_builder
|
62
56
|
path = uri.to_standardized_path
|
63
57
|
version_match = path ? /(?<=%40)[\d.]+(?=\.rbi$)/.match(path) : nil
|
64
|
-
@gem_version =
|
65
|
-
@lines_to_comments =
|
66
|
-
|
67
|
-
|
68
|
-
end,
|
69
|
-
T::Hash[Integer, Prism::Comment],
|
70
|
-
)
|
58
|
+
@gem_version = version_match && version_match[0] #: String?
|
59
|
+
@lines_to_comments = comments.to_h do |comment|
|
60
|
+
[comment.location.end_line, comment]
|
61
|
+
end #: Hash[Integer, Prism::Comment]
|
71
62
|
|
72
63
|
dispatcher.register(
|
73
64
|
self,
|
@@ -6,7 +6,7 @@ module RubyLsp
|
|
6
6
|
class DocumentSymbol
|
7
7
|
include Requests::Support::Common
|
8
8
|
|
9
|
-
ATTR_ACCESSORS =
|
9
|
+
ATTR_ACCESSORS = [:attr_reader, :attr_writer, :attr_accessor].freeze #: Array[Symbol]
|
10
10
|
|
11
11
|
#: (ResponseBuilders::DocumentSymbol response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
12
12
|
def initialize(response_builder, uri, dispatcher)
|
@@ -9,7 +9,7 @@ module RubyLsp
|
|
9
9
|
#: (ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange] response_builder, Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
|
10
10
|
def initialize(response_builder, comments, dispatcher)
|
11
11
|
@response_builder = response_builder
|
12
|
-
@requires =
|
12
|
+
@requires = [] #: Array[Prism::CallNode]
|
13
13
|
@comments = comments
|
14
14
|
|
15
15
|
dispatcher.register(
|