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
@@ -4,23 +4,19 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class DocumentSymbol < ResponseBuilder
|
7
|
-
extend T::Sig
|
8
|
-
|
9
7
|
ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }
|
10
8
|
|
11
9
|
class SymbolHierarchyRoot
|
12
|
-
|
13
|
-
|
14
|
-
sig { returns(T::Array[Interface::DocumentSymbol]) }
|
10
|
+
#: Array[Interface::DocumentSymbol]
|
15
11
|
attr_reader :children
|
16
12
|
|
17
|
-
|
13
|
+
#: -> void
|
18
14
|
def initialize
|
19
15
|
@children = T.let([], T::Array[Interface::DocumentSymbol])
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
|
19
|
+
#: -> void
|
24
20
|
def initialize
|
25
21
|
super
|
26
22
|
@stack = T.let(
|
@@ -29,26 +25,27 @@ module RubyLsp
|
|
29
25
|
)
|
30
26
|
end
|
31
27
|
|
32
|
-
|
28
|
+
#: (Interface::DocumentSymbol symbol) -> void
|
33
29
|
def push(symbol)
|
34
30
|
@stack << symbol
|
35
31
|
end
|
36
32
|
|
37
33
|
alias_method(:<<, :push)
|
38
34
|
|
39
|
-
|
35
|
+
#: -> Interface::DocumentSymbol?
|
40
36
|
def pop
|
41
37
|
if @stack.size > 1
|
42
38
|
T.cast(@stack.pop, Interface::DocumentSymbol)
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
46
|
-
|
42
|
+
#: -> (SymbolHierarchyRoot | Interface::DocumentSymbol)
|
47
43
|
def last
|
48
44
|
T.must(@stack.last)
|
49
45
|
end
|
50
46
|
|
51
|
-
|
47
|
+
# @override
|
48
|
+
#: -> Array[Interface::DocumentSymbol]
|
52
49
|
def response
|
53
50
|
T.must(@stack.first).children
|
54
51
|
end
|
@@ -4,12 +4,11 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class Hover < ResponseBuilder
|
7
|
-
extend T::Sig
|
8
7
|
extend T::Generic
|
9
8
|
|
10
9
|
ResponseType = type_member { { fixed: String } }
|
11
10
|
|
12
|
-
|
11
|
+
#: -> void
|
13
12
|
def initialize
|
14
13
|
super
|
15
14
|
|
@@ -23,7 +22,7 @@ module RubyLsp
|
|
23
22
|
)
|
24
23
|
end
|
25
24
|
|
26
|
-
|
25
|
+
#: (String content, category: Symbol) -> void
|
27
26
|
def push(content, category:)
|
28
27
|
hover_content = @response[category]
|
29
28
|
if hover_content
|
@@ -31,12 +30,13 @@ module RubyLsp
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
|
33
|
+
#: -> bool
|
35
34
|
def empty?
|
36
35
|
@response.values.all?(&:empty?)
|
37
36
|
end
|
38
37
|
|
39
|
-
|
38
|
+
# @override
|
39
|
+
#: -> ResponseType
|
40
40
|
def response
|
41
41
|
result = T.must(@response[:title])
|
42
42
|
result << "\n" << @response[:links] if @response[:links]
|
@@ -6,8 +6,6 @@ module RubyLsp
|
|
6
6
|
class SemanticHighlighting < ResponseBuilder
|
7
7
|
class UndefinedTokenType < StandardError; end
|
8
8
|
|
9
|
-
extend T::Sig
|
10
|
-
|
11
9
|
TOKEN_TYPES = T.let(
|
12
10
|
{
|
13
11
|
namespace: 0,
|
@@ -55,19 +53,14 @@ module RubyLsp
|
|
55
53
|
|
56
54
|
ResponseType = type_member { { fixed: Interface::SemanticTokens } }
|
57
55
|
|
58
|
-
|
59
|
-
params(code_units_cache: T.any(
|
60
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
61
|
-
Prism::CodeUnitsCache,
|
62
|
-
)).void
|
63
|
-
end
|
56
|
+
#: ((^(Integer arg0) -> Integer | Prism::CodeUnitsCache) code_units_cache) -> void
|
64
57
|
def initialize(code_units_cache)
|
65
58
|
super()
|
66
59
|
@code_units_cache = code_units_cache
|
67
60
|
@stack = T.let([], T::Array[SemanticToken])
|
68
61
|
end
|
69
62
|
|
70
|
-
|
63
|
+
#: (Prism::Location location, Symbol type, ?Array[Symbol] modifiers) -> void
|
71
64
|
def add_token(location, type, modifiers = [])
|
72
65
|
end_code_unit = location.cached_end_code_units_offset(@code_units_cache)
|
73
66
|
length = end_code_unit - location.cached_start_code_units_offset(@code_units_cache)
|
@@ -83,7 +76,7 @@ module RubyLsp
|
|
83
76
|
)
|
84
77
|
end
|
85
78
|
|
86
|
-
|
79
|
+
#: (Prism::Location location) -> bool
|
87
80
|
def last_token_matches?(location)
|
88
81
|
token = @stack.last
|
89
82
|
return false unless token
|
@@ -92,43 +85,34 @@ module RubyLsp
|
|
92
85
|
token.start_code_unit_column == location.cached_start_code_units_column(@code_units_cache)
|
93
86
|
end
|
94
87
|
|
95
|
-
|
88
|
+
#: -> SemanticToken?
|
96
89
|
def last
|
97
90
|
@stack.last
|
98
91
|
end
|
99
92
|
|
100
|
-
|
93
|
+
# @override
|
94
|
+
#: -> Array[SemanticToken]
|
101
95
|
def response
|
102
96
|
@stack
|
103
97
|
end
|
104
98
|
|
105
99
|
class SemanticToken
|
106
|
-
|
107
|
-
|
108
|
-
sig { returns(Integer) }
|
100
|
+
#: Integer
|
109
101
|
attr_reader :start_line
|
110
102
|
|
111
|
-
|
103
|
+
#: Integer
|
112
104
|
attr_reader :start_code_unit_column
|
113
105
|
|
114
|
-
|
106
|
+
#: Integer
|
115
107
|
attr_reader :length
|
116
108
|
|
117
|
-
|
109
|
+
#: Integer
|
118
110
|
attr_reader :type
|
119
111
|
|
120
|
-
|
112
|
+
#: Array[Integer]
|
121
113
|
attr_reader :modifier
|
122
114
|
|
123
|
-
|
124
|
-
params(
|
125
|
-
start_line: Integer,
|
126
|
-
start_code_unit_column: Integer,
|
127
|
-
length: Integer,
|
128
|
-
type: Integer,
|
129
|
-
modifier: T::Array[Integer],
|
130
|
-
).void
|
131
|
-
end
|
115
|
+
#: (start_line: Integer, start_code_unit_column: Integer, length: Integer, type: Integer, modifier: Array[Integer]) -> void
|
132
116
|
def initialize(start_line:, start_code_unit_column:, length:, type:, modifier:)
|
133
117
|
@start_line = start_line
|
134
118
|
@start_code_unit_column = start_code_unit_column
|
@@ -137,7 +121,7 @@ module RubyLsp
|
|
137
121
|
@modifier = modifier
|
138
122
|
end
|
139
123
|
|
140
|
-
|
124
|
+
#: (Symbol type_symbol) -> void
|
141
125
|
def replace_type(type_symbol)
|
142
126
|
type_int = TOKEN_TYPES[type_symbol]
|
143
127
|
raise UndefinedTokenType, "Undefined token type: #{type_symbol}" unless type_int
|
@@ -145,7 +129,7 @@ module RubyLsp
|
|
145
129
|
@type = type_int
|
146
130
|
end
|
147
131
|
|
148
|
-
|
132
|
+
#: (Array[Symbol] modifier_symbols) -> void
|
149
133
|
def replace_modifier(modifier_symbols)
|
150
134
|
@modifier = modifier_symbols.filter_map do |modifier_symbol|
|
151
135
|
modifier_index = TOKEN_MODIFIERS[modifier_symbol]
|
@@ -157,19 +141,13 @@ module RubyLsp
|
|
157
141
|
end
|
158
142
|
|
159
143
|
class SemanticTokenEncoder
|
160
|
-
|
161
|
-
|
162
|
-
sig { void }
|
144
|
+
#: -> void
|
163
145
|
def initialize
|
164
146
|
@current_row = T.let(0, Integer)
|
165
147
|
@current_column = T.let(0, Integer)
|
166
148
|
end
|
167
149
|
|
168
|
-
|
169
|
-
params(
|
170
|
-
tokens: T::Array[SemanticToken],
|
171
|
-
).returns(T::Array[Integer])
|
172
|
-
end
|
150
|
+
#: (Array[SemanticToken] tokens) -> Array[Integer]
|
173
151
|
def encode(tokens)
|
174
152
|
sorted_tokens = tokens.sort_by.with_index do |token, index|
|
175
153
|
# Enumerable#sort_by is not deterministic when the compared values are equal.
|
@@ -194,7 +172,7 @@ module RubyLsp
|
|
194
172
|
|
195
173
|
# For more information on how each number is calculated, read:
|
196
174
|
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
|
197
|
-
|
175
|
+
#: (SemanticToken token) -> Array[Integer]
|
198
176
|
def compute_delta(token)
|
199
177
|
row = token.start_line - 1
|
200
178
|
column = token.start_code_unit_column
|
@@ -216,7 +194,7 @@ module RubyLsp
|
|
216
194
|
# For example, [:default_library] will be encoded as
|
217
195
|
# 0b1000000000, as :default_library is the 10th bit according
|
218
196
|
# to the token modifiers index map.
|
219
|
-
|
197
|
+
#: (Array[Integer] modifiers) -> Integer
|
220
198
|
def encode_modifiers(modifiers)
|
221
199
|
modifiers.inject(0) do |encoded_modifiers, modifier|
|
222
200
|
encoded_modifiers | (1 << modifier)
|
@@ -4,22 +4,21 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class SignatureHelp < ResponseBuilder
|
7
|
-
extend T::Sig
|
8
|
-
|
9
7
|
ResponseType = type_member { { fixed: T.nilable(Interface::SignatureHelp) } }
|
10
8
|
|
11
|
-
|
9
|
+
#: -> void
|
12
10
|
def initialize
|
13
11
|
super
|
14
12
|
@signature_help = T.let(nil, ResponseType)
|
15
13
|
end
|
16
14
|
|
17
|
-
|
15
|
+
#: (ResponseType signature_help) -> void
|
18
16
|
def replace(signature_help)
|
19
17
|
@signature_help = signature_help
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
# @override
|
21
|
+
#: -> ResponseType
|
23
22
|
def response
|
24
23
|
@signature_help
|
25
24
|
end
|
@@ -4,32 +4,28 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class TestCollection < ResponseBuilder
|
7
|
-
class DuplicateIdError < StandardError; end
|
8
|
-
|
9
|
-
extend T::Sig
|
10
7
|
extend T::Generic
|
11
8
|
|
12
9
|
ResponseType = type_member { { fixed: Requests::Support::TestItem } }
|
13
10
|
|
14
|
-
|
11
|
+
#: -> void
|
15
12
|
def initialize
|
16
13
|
super
|
17
14
|
@items = T.let({}, T::Hash[String, ResponseType])
|
18
15
|
end
|
19
16
|
|
20
|
-
|
17
|
+
#: (ResponseType item) -> void
|
21
18
|
def add(item)
|
22
|
-
raise DuplicateIdError, "TestItem ID is already in use" if @items.key?(item.id)
|
23
|
-
|
24
19
|
@items[item.id] = item
|
25
20
|
end
|
26
21
|
|
27
|
-
|
22
|
+
#: (String id) -> ResponseType?
|
28
23
|
def [](id)
|
29
24
|
@items[id]
|
30
25
|
end
|
31
26
|
|
32
|
-
|
27
|
+
# @override
|
28
|
+
#: -> Array[ResponseType]
|
33
29
|
def response
|
34
30
|
@items.values
|
35
31
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class RubyDocument < Document
|
6
|
-
extend T::Sig
|
7
6
|
extend T::Generic
|
8
7
|
|
9
8
|
ParseResultType = type_member { { fixed: Prism::ParseResult } }
|
@@ -35,19 +34,7 @@ module RubyLsp
|
|
35
34
|
end
|
36
35
|
|
37
36
|
class << self
|
38
|
-
|
39
|
-
|
40
|
-
sig do
|
41
|
-
params(
|
42
|
-
node: Prism::Node,
|
43
|
-
char_position: Integer,
|
44
|
-
code_units_cache: T.any(
|
45
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
46
|
-
Prism::CodeUnitsCache,
|
47
|
-
),
|
48
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
49
|
-
).returns(NodeContext)
|
50
|
-
end
|
37
|
+
#: (Prism::Node node, Integer char_position, code_units_cache: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache), ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
|
51
38
|
def locate(node, char_position, code_units_cache:, node_types: [])
|
52
39
|
queue = T.let(node.child_nodes.compact, T::Array[T.nilable(Prism::Node)])
|
53
40
|
closest = node
|
@@ -150,15 +137,10 @@ module RubyLsp
|
|
150
137
|
end
|
151
138
|
end
|
152
139
|
|
153
|
-
|
154
|
-
returns(T.any(
|
155
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
156
|
-
Prism::CodeUnitsCache,
|
157
|
-
))
|
158
|
-
end
|
140
|
+
#: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
|
159
141
|
attr_reader :code_units_cache
|
160
142
|
|
161
|
-
|
143
|
+
#: (source: String, version: Integer, uri: URI::Generic, global_state: GlobalState) -> void
|
162
144
|
def initialize(source:, version:, uri:, global_state:)
|
163
145
|
super
|
164
146
|
@code_units_cache = T.let(@parse_result.code_units_cache(@encoding), T.any(
|
@@ -167,7 +149,8 @@ module RubyLsp
|
|
167
149
|
))
|
168
150
|
end
|
169
151
|
|
170
|
-
|
152
|
+
# @override
|
153
|
+
#: -> bool
|
171
154
|
def parse!
|
172
155
|
return false unless @needs_parsing
|
173
156
|
|
@@ -177,17 +160,19 @@ module RubyLsp
|
|
177
160
|
true
|
178
161
|
end
|
179
162
|
|
180
|
-
|
163
|
+
# @override
|
164
|
+
#: -> bool
|
181
165
|
def syntax_error?
|
182
166
|
@parse_result.failure?
|
183
167
|
end
|
184
168
|
|
185
|
-
|
169
|
+
# @override
|
170
|
+
#: -> LanguageId
|
186
171
|
def language_id
|
187
172
|
LanguageId::Ruby
|
188
173
|
end
|
189
174
|
|
190
|
-
|
175
|
+
#: -> SorbetLevel
|
191
176
|
def sorbet_level
|
192
177
|
sigil = parse_result.magic_comments.find do |comment|
|
193
178
|
comment.key == "typed"
|
@@ -207,12 +192,7 @@ module RubyLsp
|
|
207
192
|
end
|
208
193
|
end
|
209
194
|
|
210
|
-
|
211
|
-
params(
|
212
|
-
range: T::Hash[Symbol, T.untyped],
|
213
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
214
|
-
).returns(T.nilable(Prism::Node))
|
215
|
-
end
|
195
|
+
#: (Hash[Symbol, untyped] range, ?node_types: Array[singleton(Prism::Node)]) -> Prism::Node?
|
216
196
|
def locate_first_within_range(range, node_types: [])
|
217
197
|
start_position, end_position = find_index_by_position(range[:start], range[:end])
|
218
198
|
|
@@ -240,12 +220,7 @@ module RubyLsp
|
|
240
220
|
end
|
241
221
|
end
|
242
222
|
|
243
|
-
|
244
|
-
params(
|
245
|
-
position: T::Hash[Symbol, T.untyped],
|
246
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
247
|
-
).returns(NodeContext)
|
248
|
-
end
|
223
|
+
#: (Hash[Symbol, untyped] position, ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
|
249
224
|
def locate_node(position, node_types: [])
|
250
225
|
char_position, _ = find_index_by_position(position)
|
251
226
|
|
@@ -257,7 +232,7 @@ module RubyLsp
|
|
257
232
|
)
|
258
233
|
end
|
259
234
|
|
260
|
-
|
235
|
+
#: -> bool
|
261
236
|
def should_index?
|
262
237
|
# This method controls when we should index documents. If there's no recent edit and the document has just been
|
263
238
|
# opened, we need to index it
|
@@ -268,7 +243,7 @@ module RubyLsp
|
|
268
243
|
|
269
244
|
private
|
270
245
|
|
271
|
-
|
246
|
+
#: -> bool
|
272
247
|
def last_edit_may_change_declarations?
|
273
248
|
case @last_edit
|
274
249
|
when Delete
|
@@ -282,7 +257,7 @@ module RubyLsp
|
|
282
257
|
end
|
283
258
|
end
|
284
259
|
|
285
|
-
|
260
|
+
#: (Hash[Symbol, Integer] position) -> bool
|
286
261
|
def position_may_impact_declarations?(position)
|
287
262
|
node_context = locate_node(position)
|
288
263
|
node_at_edit = node_context.node
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "test_reporter"
|
5
|
+
require "ruby_indexer/lib/ruby_indexer/uri"
|
6
|
+
|
7
|
+
require "minitest"
|
8
|
+
|
9
|
+
module Minitest
|
10
|
+
module Reporters
|
11
|
+
class RubyLspReporter < ::Minitest::AbstractReporter
|
12
|
+
class << self
|
13
|
+
#: (Hash[untyped, untyped]) -> void
|
14
|
+
def minitest_plugin_init(_options)
|
15
|
+
Minitest.reporter.reporters = [RubyLspReporter.new]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#: (singleton(Minitest::Test) test_class, String method_name) -> void
|
20
|
+
def prerecord(test_class, method_name)
|
21
|
+
uri = uri_from_test_class(test_class, method_name)
|
22
|
+
return unless uri
|
23
|
+
|
24
|
+
RubyLsp::TestReporter.start_test(
|
25
|
+
id: "#{test_class.name}##{method_name}",
|
26
|
+
uri: uri,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
#: (Minitest::Result result) -> void
|
31
|
+
def record(result)
|
32
|
+
if result.error?
|
33
|
+
record_error(result)
|
34
|
+
elsif result.passed?
|
35
|
+
record_pass(result)
|
36
|
+
elsif result.skipped?
|
37
|
+
record_skip(result)
|
38
|
+
elsif result.failure
|
39
|
+
record_fail(result)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
#: (Minitest::Result result) -> void
|
46
|
+
def record_pass(result)
|
47
|
+
RubyLsp::TestReporter.record_pass(
|
48
|
+
id: id_from_result(result),
|
49
|
+
uri: uri_from_result(result),
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
#: (Minitest::Result result) -> void
|
54
|
+
def record_skip(result)
|
55
|
+
RubyLsp::TestReporter.record_skip(
|
56
|
+
id: id_from_result(result),
|
57
|
+
message: result.failure.message,
|
58
|
+
uri: uri_from_result(result),
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
#: (Minitest::Result result) -> void
|
63
|
+
def record_fail(result)
|
64
|
+
RubyLsp::TestReporter.record_fail(
|
65
|
+
id: id_from_result(result),
|
66
|
+
message: result.failure.message,
|
67
|
+
uri: uri_from_result(result),
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
#: (Minitest::Result result) -> void
|
72
|
+
def record_error(result)
|
73
|
+
RubyLsp::TestReporter.record_error(
|
74
|
+
id: id_from_result(result),
|
75
|
+
uri: uri_from_result(result),
|
76
|
+
message: result.failures.first.message,
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
#: (Minitest::Result result) -> String
|
81
|
+
def id_from_result(result)
|
82
|
+
"#{result.klass}##{result.name}"
|
83
|
+
end
|
84
|
+
|
85
|
+
#: (Minitest::Result result) -> URI::Generic
|
86
|
+
def uri_from_result(result)
|
87
|
+
file = result.source_location[0]
|
88
|
+
absolute_path = File.expand_path(file, Dir.pwd)
|
89
|
+
URI::Generic.from_path(path: absolute_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
#: (singleton(Minitest::Test) test_class, String method_name) -> URI::Generic?
|
93
|
+
def uri_from_test_class(test_class, method_name)
|
94
|
+
file, _line = test_class.instance_method(method_name).source_location
|
95
|
+
return unless file
|
96
|
+
|
97
|
+
return if file.start_with?("(eval at ") # test is dynamically defined
|
98
|
+
|
99
|
+
absolute_path = File.expand_path(file, Dir.pwd)
|
100
|
+
URI::Generic.from_path(path: absolute_path)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
Minitest.extensions << Minitest::Reporters::RubyLspReporter
|
data/lib/ruby_lsp/scope.rb
CHANGED
@@ -3,12 +3,10 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class Scope
|
6
|
-
|
7
|
-
|
8
|
-
sig { returns(T.nilable(Scope)) }
|
6
|
+
#: Scope?
|
9
7
|
attr_reader :parent
|
10
8
|
|
11
|
-
|
9
|
+
#: (?Scope? parent) -> void
|
12
10
|
def initialize(parent = nil)
|
13
11
|
@parent = parent
|
14
12
|
|
@@ -17,12 +15,12 @@ module RubyLsp
|
|
17
15
|
end
|
18
16
|
|
19
17
|
# Add a new local to this scope. The types should only be `:parameter` or `:variable`
|
20
|
-
|
18
|
+
#: ((String | Symbol) name, Symbol type) -> void
|
21
19
|
def add(name, type)
|
22
20
|
@locals[name.to_sym] = Local.new(type)
|
23
21
|
end
|
24
22
|
|
25
|
-
|
23
|
+
#: ((String | Symbol) name) -> Local?
|
26
24
|
def lookup(name)
|
27
25
|
sym = name.to_sym
|
28
26
|
entry = @locals[sym]
|
@@ -33,12 +31,10 @@ module RubyLsp
|
|
33
31
|
end
|
34
32
|
|
35
33
|
class Local
|
36
|
-
|
37
|
-
|
38
|
-
sig { returns(Symbol) }
|
34
|
+
#: Symbol
|
39
35
|
attr_reader :type
|
40
36
|
|
41
|
-
|
37
|
+
#: (Symbol type) -> void
|
42
38
|
def initialize(type)
|
43
39
|
@type = type
|
44
40
|
end
|