ruby-lsp 0.22.0 → 0.22.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +43 -1
- data/lib/ruby_indexer/test/method_test.rb +80 -0
- data/lib/ruby_lsp/global_state.rb +1 -1
- data/lib/ruby_lsp/listeners/document_symbol.rb +37 -4
- data/lib/ruby_lsp/setup_bundler.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efd5671eae595026a17c3114a00de1053865ac828726dd7ac5a66548f6b1ad56
|
4
|
+
data.tar.gz: ccf5b7af12a6e1e327cc2d458be11f39a9ac7319ab9049863ed5a74e333e8a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fbcdfaac508788a17fb3b7e939ce290e33049a0080ff6260abfaeb609ee76a033234ccc2efa5724587e9c4cbf4552e2cd5d2cb0af1186971b8ed06fec290cb3
|
7
|
+
data.tar.gz: 3e37acf250618e60df2addbce7f9acf86df4bf3e771b7b49c4cd8f4ad326ea82e3d41ad80c5ce71e3b0429dab98385df51f4645824cd419e32dac5ea13778760
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.22.
|
1
|
+
0.22.1
|
@@ -282,6 +282,9 @@ module RubyIndexer
|
|
282
282
|
@visibility_stack.push(Entry::Visibility::PRIVATE)
|
283
283
|
when :module_function
|
284
284
|
handle_module_function(node)
|
285
|
+
when :private_class_method
|
286
|
+
@visibility_stack.push(Entry::Visibility::PRIVATE)
|
287
|
+
handle_private_class_method(node)
|
285
288
|
end
|
286
289
|
|
287
290
|
@enhancements.each do |enhancement|
|
@@ -297,7 +300,7 @@ module RubyIndexer
|
|
297
300
|
def on_call_node_leave(node)
|
298
301
|
message = node.name
|
299
302
|
case message
|
300
|
-
when :public, :protected, :private
|
303
|
+
when :public, :protected, :private, :private_class_method
|
301
304
|
# We want to restore the visibility stack when we leave a method definition with a visibility modifier
|
302
305
|
# e.g. `private def foo; end`
|
303
306
|
if node.arguments&.arguments&.first&.is_a?(Prism::DefNode)
|
@@ -875,6 +878,45 @@ module RubyIndexer
|
|
875
878
|
end
|
876
879
|
end
|
877
880
|
|
881
|
+
sig { params(node: Prism::CallNode).void }
|
882
|
+
def handle_private_class_method(node)
|
883
|
+
node.arguments&.arguments&.each do |argument|
|
884
|
+
string_or_symbol_nodes = case argument
|
885
|
+
when Prism::StringNode, Prism::SymbolNode
|
886
|
+
[argument]
|
887
|
+
when Prism::ArrayNode
|
888
|
+
argument.elements
|
889
|
+
else
|
890
|
+
[]
|
891
|
+
end
|
892
|
+
|
893
|
+
unless string_or_symbol_nodes.empty?
|
894
|
+
# pop the visibility off since there isn't a method definition following `private_class_method`
|
895
|
+
@visibility_stack.pop
|
896
|
+
end
|
897
|
+
|
898
|
+
string_or_symbol_nodes.each do |string_or_symbol_node|
|
899
|
+
method_name = case string_or_symbol_node
|
900
|
+
when Prism::StringNode
|
901
|
+
string_or_symbol_node.content
|
902
|
+
when Prism::SymbolNode
|
903
|
+
string_or_symbol_node.value
|
904
|
+
end
|
905
|
+
next unless method_name
|
906
|
+
|
907
|
+
owner_name = @owner_stack.last&.name
|
908
|
+
next unless owner_name
|
909
|
+
|
910
|
+
entries = @index.resolve_method(method_name, @index.existing_or_new_singleton_class(owner_name).name)
|
911
|
+
next unless entries
|
912
|
+
|
913
|
+
entries.each do |entry|
|
914
|
+
entry.visibility = Entry::Visibility::PRIVATE
|
915
|
+
end
|
916
|
+
end
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
878
920
|
sig { returns(Entry::Visibility) }
|
879
921
|
def current_visibility
|
880
922
|
T.must(@visibility_stack.last)
|
@@ -149,6 +149,86 @@ module RubyIndexer
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
def test_private_class_method_visibility_tracking_string_symbol_arguments
|
153
|
+
index(<<~RUBY)
|
154
|
+
class Test
|
155
|
+
def self.foo
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.bar
|
159
|
+
end
|
160
|
+
|
161
|
+
private_class_method("foo", :bar)
|
162
|
+
|
163
|
+
def self.baz
|
164
|
+
end
|
165
|
+
end
|
166
|
+
RUBY
|
167
|
+
|
168
|
+
["foo", "bar"].each do |keyword|
|
169
|
+
entries = T.must(@index[keyword])
|
170
|
+
assert_equal(1, entries.size)
|
171
|
+
entry = entries.first
|
172
|
+
assert_predicate(entry, :private?)
|
173
|
+
end
|
174
|
+
|
175
|
+
entries = T.must(@index["baz"])
|
176
|
+
assert_equal(1, entries.size)
|
177
|
+
entry = entries.first
|
178
|
+
assert_predicate(entry, :public?)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_private_class_method_visibility_tracking_array_argument
|
182
|
+
index(<<~RUBY)
|
183
|
+
class Test
|
184
|
+
def self.foo
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.bar
|
188
|
+
end
|
189
|
+
|
190
|
+
private_class_method(["foo", :bar])
|
191
|
+
|
192
|
+
def self.baz
|
193
|
+
end
|
194
|
+
end
|
195
|
+
RUBY
|
196
|
+
|
197
|
+
["foo", "bar"].each do |keyword|
|
198
|
+
entries = T.must(@index[keyword])
|
199
|
+
assert_equal(1, entries.size)
|
200
|
+
entry = entries.first
|
201
|
+
assert_predicate(entry, :private?)
|
202
|
+
end
|
203
|
+
|
204
|
+
entries = T.must(@index["baz"])
|
205
|
+
assert_equal(1, entries.size)
|
206
|
+
entry = entries.first
|
207
|
+
assert_predicate(entry, :public?)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_private_class_method_visibility_tracking_method_argument
|
211
|
+
index(<<~RUBY)
|
212
|
+
class Test
|
213
|
+
private_class_method def self.foo
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.bar
|
217
|
+
end
|
218
|
+
end
|
219
|
+
RUBY
|
220
|
+
|
221
|
+
entries = T.must(@index["foo"])
|
222
|
+
assert_equal(1, entries.size)
|
223
|
+
entry = entries.first
|
224
|
+
assert_predicate(entry, :private?)
|
225
|
+
|
226
|
+
entries = T.must(@index["bar"])
|
227
|
+
assert_equal(1, entries.size)
|
228
|
+
entry = entries.first
|
229
|
+
assert_predicate(entry, :public?)
|
230
|
+
end
|
231
|
+
|
152
232
|
def test_comments_documentation
|
153
233
|
index(<<~RUBY)
|
154
234
|
# Documentation for Foo
|
@@ -41,6 +41,9 @@ module RubyLsp
|
|
41
41
|
:on_module_node_enter,
|
42
42
|
:on_module_node_leave,
|
43
43
|
:on_instance_variable_write_node_enter,
|
44
|
+
:on_instance_variable_operator_write_node_enter,
|
45
|
+
:on_instance_variable_or_write_node_enter,
|
46
|
+
:on_instance_variable_and_write_node_enter,
|
44
47
|
:on_class_variable_write_node_enter,
|
45
48
|
:on_singleton_class_node_enter,
|
46
49
|
:on_singleton_class_node_leave,
|
@@ -249,21 +252,51 @@ module RubyLsp
|
|
249
252
|
@response_builder.pop
|
250
253
|
end
|
251
254
|
|
255
|
+
sig { params(node: Prism::ClassVariableWriteNode).void }
|
256
|
+
def on_class_variable_write_node_enter(node)
|
257
|
+
create_document_symbol(
|
258
|
+
name: node.name.to_s,
|
259
|
+
kind: Constant::SymbolKind::VARIABLE,
|
260
|
+
range_location: node.name_loc,
|
261
|
+
selection_range_location: node.name_loc,
|
262
|
+
)
|
263
|
+
end
|
264
|
+
|
252
265
|
sig { params(node: Prism::InstanceVariableWriteNode).void }
|
253
266
|
def on_instance_variable_write_node_enter(node)
|
254
267
|
create_document_symbol(
|
255
268
|
name: node.name.to_s,
|
256
|
-
kind: Constant::SymbolKind::
|
269
|
+
kind: Constant::SymbolKind::FIELD,
|
257
270
|
range_location: node.name_loc,
|
258
271
|
selection_range_location: node.name_loc,
|
259
272
|
)
|
260
273
|
end
|
261
274
|
|
262
|
-
sig { params(node: Prism::
|
263
|
-
def
|
275
|
+
sig { params(node: Prism::InstanceVariableOperatorWriteNode).void }
|
276
|
+
def on_instance_variable_operator_write_node_enter(node)
|
264
277
|
create_document_symbol(
|
265
278
|
name: node.name.to_s,
|
266
|
-
kind: Constant::SymbolKind::
|
279
|
+
kind: Constant::SymbolKind::FIELD,
|
280
|
+
range_location: node.name_loc,
|
281
|
+
selection_range_location: node.name_loc,
|
282
|
+
)
|
283
|
+
end
|
284
|
+
|
285
|
+
sig { params(node: Prism::InstanceVariableOrWriteNode).void }
|
286
|
+
def on_instance_variable_or_write_node_enter(node)
|
287
|
+
create_document_symbol(
|
288
|
+
name: node.name.to_s,
|
289
|
+
kind: Constant::SymbolKind::FIELD,
|
290
|
+
range_location: node.name_loc,
|
291
|
+
selection_range_location: node.name_loc,
|
292
|
+
)
|
293
|
+
end
|
294
|
+
|
295
|
+
sig { params(node: Prism::InstanceVariableAndWriteNode).void }
|
296
|
+
def on_instance_variable_and_write_node_enter(node)
|
297
|
+
create_document_symbol(
|
298
|
+
name: node.name.to_s,
|
299
|
+
kind: Constant::SymbolKind::FIELD,
|
267
300
|
range_location: node.name_loc,
|
268
301
|
selection_range_location: node.name_loc,
|
269
302
|
)
|
@@ -45,6 +45,9 @@ module RubyLsp
|
|
45
45
|
)
|
46
46
|
@lockfile = T.let(@gemfile ? Bundler.default_lockfile : nil, T.nilable(Pathname))
|
47
47
|
|
48
|
+
@gemfile_hash = T.let(@gemfile ? Digest::SHA256.hexdigest(@gemfile.read) : nil, T.nilable(String))
|
49
|
+
@lockfile_hash = T.let(@lockfile&.exist? ? Digest::SHA256.hexdigest(@lockfile.read) : nil, T.nilable(String))
|
50
|
+
|
48
51
|
@gemfile_name = T.let(@gemfile&.basename&.to_s || "Gemfile", String)
|
49
52
|
|
50
53
|
# Custom bundle paths
|
@@ -91,10 +94,8 @@ module RubyLsp
|
|
91
94
|
return run_bundle_install(@custom_gemfile)
|
92
95
|
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if @custom_lockfile.exist? && @lockfile_hash_path.exist? && @lockfile_hash_path.read == current_lockfile_hash
|
97
|
+
if @lockfile_hash && @custom_lockfile.exist? && @lockfile_hash_path.exist? &&
|
98
|
+
@lockfile_hash_path.read == @lockfile_hash
|
98
99
|
$stderr.puts(
|
99
100
|
"Ruby LSP> Skipping composed bundle setup since #{@custom_lockfile} already exists and is up to date",
|
100
101
|
)
|
@@ -103,7 +104,7 @@ module RubyLsp
|
|
103
104
|
|
104
105
|
FileUtils.cp(@lockfile.to_s, @custom_lockfile.to_s)
|
105
106
|
correct_relative_remote_paths
|
106
|
-
@lockfile_hash_path.write(
|
107
|
+
@lockfile_hash_path.write(@lockfile_hash)
|
107
108
|
run_bundle_install(@custom_gemfile)
|
108
109
|
end
|
109
110
|
|
@@ -214,6 +215,23 @@ module RubyLsp
|
|
214
215
|
@error_path.write(Marshal.dump(e))
|
215
216
|
end
|
216
217
|
|
218
|
+
# If either the Gemfile or the lockfile have been modified during the process of setting up the bundle, retry
|
219
|
+
# composing the bundle from scratch
|
220
|
+
|
221
|
+
if @gemfile && @lockfile
|
222
|
+
current_gemfile_hash = Digest::SHA256.hexdigest(@gemfile.read)
|
223
|
+
current_lockfile_hash = Digest::SHA256.hexdigest(@lockfile.read)
|
224
|
+
|
225
|
+
if !@retry && (current_gemfile_hash != @gemfile_hash || current_lockfile_hash != @lockfile_hash)
|
226
|
+
@gemfile_hash = current_gemfile_hash
|
227
|
+
@lockfile_hash = current_lockfile_hash
|
228
|
+
@retry = true
|
229
|
+
@custom_dir.rmtree
|
230
|
+
$stderr.puts("Ruby LSP> Bundle was modified during setup. Retrying from scratch...")
|
231
|
+
return setup!
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
217
235
|
env
|
218
236
|
end
|
219
237
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.22.
|
4
|
+
version: 0.22.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|