ruby-lsp 0.19.0 → 0.20.0
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/exe/ruby-lsp-check +1 -1
- data/lib/core_ext/uri.rb +2 -2
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +85 -36
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +5 -1
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +46 -98
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +7 -6
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +22 -0
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +20 -5
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +76 -14
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +12 -0
- data/lib/ruby_indexer/test/enhancements_test.rb +5 -7
- data/lib/ruby_indexer/test/global_variable_test.rb +49 -0
- data/lib/ruby_indexer/test/index_test.rb +3 -0
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +14 -0
- data/lib/ruby_indexer/test/reference_finder_test.rb +162 -6
- data/lib/ruby_lsp/erb_document.rb +20 -2
- data/lib/ruby_lsp/internal.rb +3 -1
- data/lib/ruby_lsp/listeners/definition.rb +20 -0
- data/lib/ruby_lsp/listeners/folding_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/code_action_resolve.rb +16 -4
- data/lib/ruby_lsp/requests/completion.rb +1 -0
- data/lib/ruby_lsp/requests/definition.rb +2 -0
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -1
- data/lib/ruby_lsp/requests/hover.rb +1 -0
- data/lib/ruby_lsp/requests/range_formatting.rb +57 -0
- data/lib/ruby_lsp/requests/references.rb +146 -0
- data/lib/ruby_lsp/requests/rename.rb +16 -9
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/signature_help.rb +6 -1
- data/lib/ruby_lsp/requests/support/common.rb +1 -1
- data/lib/ruby_lsp/requests/support/formatter.rb +3 -0
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +6 -0
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +6 -6
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +8 -0
- data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -2
- data/lib/ruby_lsp/response_builders/hover.rb +2 -2
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +14 -8
- data/lib/ruby_lsp/response_builders/signature_help.rb +2 -2
- data/lib/ruby_lsp/ruby_document.rb +44 -8
- data/lib/ruby_lsp/server.rb +63 -2
- data/lib/ruby_lsp/type_inferrer.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43d431cf15d817d80ebb8564f90a748b871ad3c2c278482d4b1b5c831b7bcd2
|
4
|
+
data.tar.gz: 28ab582396723d582f7909ad277300430b6e14e6a281408be21a71f4d768930f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a87212da50592a6b201a5f21ea559de74fb12ed795428e06392a4375aa73015a103aedd56734b9b05a2f0a27fcb7366b16107ea9f1a080b3459e2eff1dcd88
|
7
|
+
data.tar.gz: 7ad77f3dccbabba9cb306c73ccefca4e84e9ff480bc0594d20a1c6e03727948119f7accefc522e5ed25d6de1d21fff03b18c704c7c8908b33eb92cfc5b2c665d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.20.0
|
data/exe/ruby-lsp-check
CHANGED
@@ -32,7 +32,7 @@ files.each_with_index do |file, index|
|
|
32
32
|
})
|
33
33
|
|
34
34
|
result = server.pop_response
|
35
|
-
errors[file] = result
|
35
|
+
errors[file] = result if result.is_a?(RubyLsp::Error)
|
36
36
|
ensure
|
37
37
|
server.process_message({ method: "textDocument/didClose", params: { textDocument: { uri: uri } } })
|
38
38
|
server.pop_response
|
data/lib/core_ext/uri.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
module URI
|
5
5
|
class Generic
|
6
|
+
extend T::Sig
|
7
|
+
|
6
8
|
# Avoid a deprecation warning with Ruby 3.4 where the default parser was changed to RFC3986.
|
7
9
|
# This condition must remain even after support for 3.4 has been dropped for users that have
|
8
10
|
# `uri` in their lockfile, decoupling it from the ruby version.
|
@@ -27,8 +29,6 @@ module URI
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
extend T::Sig
|
31
|
-
|
32
32
|
sig { returns(T.nilable(String)) }
|
33
33
|
def to_standardized_path
|
34
34
|
parsed_path = path
|
@@ -33,6 +33,10 @@ module RubyIndexer
|
|
33
33
|
T::Hash[Integer, Prism::Comment],
|
34
34
|
)
|
35
35
|
@inside_def = T.let(false, T::Boolean)
|
36
|
+
@code_units_cache = T.let(
|
37
|
+
parse_result.code_units_cache(@index.configuration.encoding),
|
38
|
+
T.any(T.proc.params(arg0: Integer).returns(Integer), Prism::CodeUnitsCache),
|
39
|
+
)
|
36
40
|
|
37
41
|
# The nesting stack we're currently inside. Used to determine the fully qualified name of constants, but only
|
38
42
|
# stored by unresolved aliases which need the original nesting to be lazily resolved
|
@@ -65,6 +69,11 @@ module RubyIndexer
|
|
65
69
|
:on_constant_or_write_node_enter,
|
66
70
|
:on_constant_and_write_node_enter,
|
67
71
|
:on_constant_operator_write_node_enter,
|
72
|
+
:on_global_variable_and_write_node_enter,
|
73
|
+
:on_global_variable_operator_write_node_enter,
|
74
|
+
:on_global_variable_or_write_node_enter,
|
75
|
+
:on_global_variable_target_node_enter,
|
76
|
+
:on_global_variable_write_node_enter,
|
68
77
|
:on_instance_variable_write_node_enter,
|
69
78
|
:on_instance_variable_and_write_node_enter,
|
70
79
|
:on_instance_variable_operator_write_node_enter,
|
@@ -106,10 +115,9 @@ module RubyIndexer
|
|
106
115
|
entry = Entry::Class.new(
|
107
116
|
nesting,
|
108
117
|
@file_path,
|
109
|
-
node.location,
|
110
|
-
constant_path.location,
|
118
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
119
|
+
Location.from_prism_location(constant_path.location, @code_units_cache),
|
111
120
|
comments,
|
112
|
-
@index.configuration.encoding,
|
113
121
|
parent_class,
|
114
122
|
)
|
115
123
|
|
@@ -136,10 +144,9 @@ module RubyIndexer
|
|
136
144
|
entry = Entry::Module.new(
|
137
145
|
actual_nesting(name),
|
138
146
|
@file_path,
|
139
|
-
node.location,
|
140
|
-
constant_path.location,
|
147
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
148
|
+
Location.from_prism_location(constant_path.location, @code_units_cache),
|
141
149
|
comments,
|
142
|
-
@index.configuration.encoding,
|
143
150
|
)
|
144
151
|
|
145
152
|
@owner_stack << entry
|
@@ -170,19 +177,17 @@ module RubyIndexer
|
|
170
177
|
if existing_entries
|
171
178
|
entry = T.must(existing_entries.first)
|
172
179
|
entry.update_singleton_information(
|
173
|
-
node.location,
|
174
|
-
expression.location,
|
180
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
181
|
+
Location.from_prism_location(expression.location, @code_units_cache),
|
175
182
|
collect_comments(node),
|
176
|
-
@index.configuration.encoding,
|
177
183
|
)
|
178
184
|
else
|
179
185
|
entry = Entry::SingletonClass.new(
|
180
186
|
real_nesting,
|
181
187
|
@file_path,
|
182
|
-
node.location,
|
183
|
-
expression.location,
|
188
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
189
|
+
Location.from_prism_location(expression.location, @code_units_cache),
|
184
190
|
collect_comments(node),
|
185
|
-
@index.configuration.encoding,
|
186
191
|
nil,
|
187
192
|
)
|
188
193
|
@index.add(entry, skip_prefix_tree: true)
|
@@ -310,7 +315,7 @@ module RubyIndexer
|
|
310
315
|
end
|
311
316
|
|
312
317
|
@enhancements.each do |enhancement|
|
313
|
-
enhancement.on_call_node(@index, @owner_stack.last, node, @file_path)
|
318
|
+
enhancement.on_call_node(@index, @owner_stack.last, node, @file_path, @code_units_cache)
|
314
319
|
rescue StandardError => e
|
315
320
|
@indexing_errors << "Indexing error in #{@file_path} with '#{enhancement.class.name}' enhancement: #{e.message}"
|
316
321
|
end
|
@@ -340,10 +345,9 @@ module RubyIndexer
|
|
340
345
|
@index.add(Entry::Method.new(
|
341
346
|
method_name,
|
342
347
|
@file_path,
|
343
|
-
node.location,
|
344
|
-
node.name_loc,
|
348
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
349
|
+
Location.from_prism_location(node.name_loc, @code_units_cache),
|
345
350
|
comments,
|
346
|
-
@index.configuration.encoding,
|
347
351
|
[Entry::Signature.new(list_params(node.parameters))],
|
348
352
|
current_visibility,
|
349
353
|
@owner_stack.last,
|
@@ -357,10 +361,9 @@ module RubyIndexer
|
|
357
361
|
@index.add(Entry::Method.new(
|
358
362
|
method_name,
|
359
363
|
@file_path,
|
360
|
-
node.location,
|
361
|
-
node.name_loc,
|
364
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
365
|
+
Location.from_prism_location(node.name_loc, @code_units_cache),
|
362
366
|
comments,
|
363
|
-
@index.configuration.encoding,
|
364
367
|
[Entry::Signature.new(list_params(node.parameters))],
|
365
368
|
current_visibility,
|
366
369
|
singleton,
|
@@ -382,6 +385,31 @@ module RubyIndexer
|
|
382
385
|
end
|
383
386
|
end
|
384
387
|
|
388
|
+
sig { params(node: Prism::GlobalVariableAndWriteNode).void }
|
389
|
+
def on_global_variable_and_write_node_enter(node)
|
390
|
+
handle_global_variable(node, node.name_loc)
|
391
|
+
end
|
392
|
+
|
393
|
+
sig { params(node: Prism::GlobalVariableOperatorWriteNode).void }
|
394
|
+
def on_global_variable_operator_write_node_enter(node)
|
395
|
+
handle_global_variable(node, node.name_loc)
|
396
|
+
end
|
397
|
+
|
398
|
+
sig { params(node: Prism::GlobalVariableOrWriteNode).void }
|
399
|
+
def on_global_variable_or_write_node_enter(node)
|
400
|
+
handle_global_variable(node, node.name_loc)
|
401
|
+
end
|
402
|
+
|
403
|
+
sig { params(node: Prism::GlobalVariableTargetNode).void }
|
404
|
+
def on_global_variable_target_node_enter(node)
|
405
|
+
handle_global_variable(node, node.location)
|
406
|
+
end
|
407
|
+
|
408
|
+
sig { params(node: Prism::GlobalVariableWriteNode).void }
|
409
|
+
def on_global_variable_write_node_enter(node)
|
410
|
+
handle_global_variable(node, node.name_loc)
|
411
|
+
end
|
412
|
+
|
385
413
|
sig { params(node: Prism::InstanceVariableWriteNode).void }
|
386
414
|
def on_instance_variable_write_node_enter(node)
|
387
415
|
handle_instance_variable(node, node.name_loc)
|
@@ -417,15 +445,38 @@ module RubyIndexer
|
|
417
445
|
node.old_name.slice,
|
418
446
|
@owner_stack.last,
|
419
447
|
@file_path,
|
420
|
-
node.new_name.location,
|
448
|
+
Location.from_prism_location(node.new_name.location, @code_units_cache),
|
421
449
|
comments,
|
422
|
-
@index.configuration.encoding,
|
423
450
|
),
|
424
451
|
)
|
425
452
|
end
|
426
453
|
|
427
454
|
private
|
428
455
|
|
456
|
+
sig do
|
457
|
+
params(
|
458
|
+
node: T.any(
|
459
|
+
Prism::GlobalVariableAndWriteNode,
|
460
|
+
Prism::GlobalVariableOperatorWriteNode,
|
461
|
+
Prism::GlobalVariableOrWriteNode,
|
462
|
+
Prism::GlobalVariableTargetNode,
|
463
|
+
Prism::GlobalVariableWriteNode,
|
464
|
+
),
|
465
|
+
loc: Prism::Location,
|
466
|
+
).void
|
467
|
+
end
|
468
|
+
def handle_global_variable(node, loc)
|
469
|
+
name = node.name.to_s
|
470
|
+
comments = collect_comments(node)
|
471
|
+
|
472
|
+
@index.add(Entry::GlobalVariable.new(
|
473
|
+
name,
|
474
|
+
@file_path,
|
475
|
+
Location.from_prism_location(loc, @code_units_cache),
|
476
|
+
comments,
|
477
|
+
))
|
478
|
+
end
|
479
|
+
|
429
480
|
sig do
|
430
481
|
params(
|
431
482
|
node: T.any(
|
@@ -453,9 +504,8 @@ module RubyIndexer
|
|
453
504
|
@index.add(Entry::InstanceVariable.new(
|
454
505
|
name,
|
455
506
|
@file_path,
|
456
|
-
loc,
|
507
|
+
Location.from_prism_location(loc, @code_units_cache),
|
457
508
|
collect_comments(node),
|
458
|
-
@index.configuration.encoding,
|
459
509
|
owner,
|
460
510
|
))
|
461
511
|
end
|
@@ -518,9 +568,8 @@ module RubyIndexer
|
|
518
568
|
old_name_value,
|
519
569
|
@owner_stack.last,
|
520
570
|
@file_path,
|
521
|
-
new_name.location,
|
571
|
+
Location.from_prism_location(new_name.location, @code_units_cache),
|
522
572
|
comments,
|
523
|
-
@index.configuration.encoding,
|
524
573
|
),
|
525
574
|
)
|
526
575
|
end
|
@@ -555,9 +604,8 @@ module RubyIndexer
|
|
555
604
|
@stack.dup,
|
556
605
|
name,
|
557
606
|
@file_path,
|
558
|
-
node.location,
|
607
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
559
608
|
comments,
|
560
|
-
@index.configuration.encoding,
|
561
609
|
)
|
562
610
|
when Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOrWriteNode,
|
563
611
|
Prism::ConstantOperatorWriteNode
|
@@ -569,9 +617,8 @@ module RubyIndexer
|
|
569
617
|
@stack.dup,
|
570
618
|
name,
|
571
619
|
@file_path,
|
572
|
-
node.location,
|
620
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
573
621
|
comments,
|
574
|
-
@index.configuration.encoding,
|
575
622
|
)
|
576
623
|
when Prism::ConstantPathWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantPathOperatorWriteNode,
|
577
624
|
Prism::ConstantPathAndWriteNode
|
@@ -581,12 +628,16 @@ module RubyIndexer
|
|
581
628
|
@stack.dup,
|
582
629
|
name,
|
583
630
|
@file_path,
|
584
|
-
node.location,
|
631
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
585
632
|
comments,
|
586
|
-
@index.configuration.encoding,
|
587
633
|
)
|
588
634
|
else
|
589
|
-
Entry::Constant.new(
|
635
|
+
Entry::Constant.new(
|
636
|
+
name,
|
637
|
+
@file_path,
|
638
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
639
|
+
comments,
|
640
|
+
)
|
590
641
|
end,
|
591
642
|
)
|
592
643
|
end
|
@@ -652,9 +703,8 @@ module RubyIndexer
|
|
652
703
|
@index.add(Entry::Accessor.new(
|
653
704
|
name,
|
654
705
|
@file_path,
|
655
|
-
loc,
|
706
|
+
Location.from_prism_location(loc, @code_units_cache),
|
656
707
|
comments,
|
657
|
-
@index.configuration.encoding,
|
658
708
|
current_visibility,
|
659
709
|
@owner_stack.last,
|
660
710
|
))
|
@@ -665,9 +715,8 @@ module RubyIndexer
|
|
665
715
|
@index.add(Entry::Accessor.new(
|
666
716
|
"#{name}=",
|
667
717
|
@file_path,
|
668
|
-
loc,
|
718
|
+
Location.from_prism_location(loc, @code_units_cache),
|
669
719
|
comments,
|
670
|
-
@index.configuration.encoding,
|
671
720
|
current_visibility,
|
672
721
|
@owner_stack.last,
|
673
722
|
))
|
@@ -19,8 +19,12 @@ module RubyIndexer
|
|
19
19
|
owner: T.nilable(Entry::Namespace),
|
20
20
|
node: Prism::CallNode,
|
21
21
|
file_path: String,
|
22
|
+
code_units_cache: T.any(
|
23
|
+
T.proc.params(arg0: Integer).returns(Integer),
|
24
|
+
Prism::CodeUnitsCache,
|
25
|
+
),
|
22
26
|
).void
|
23
27
|
end
|
24
|
-
def on_call_node(index, owner, node, file_path); end
|
28
|
+
def on_call_node(index, owner, node, file_path, code_units_cache); end
|
25
29
|
end
|
26
30
|
end
|
@@ -31,30 +31,16 @@ module RubyIndexer
|
|
31
31
|
params(
|
32
32
|
name: String,
|
33
33
|
file_path: String,
|
34
|
-
location:
|
34
|
+
location: Location,
|
35
35
|
comments: T.nilable(String),
|
36
|
-
encoding: Encoding,
|
37
36
|
).void
|
38
37
|
end
|
39
|
-
def initialize(name, file_path, location, comments
|
38
|
+
def initialize(name, file_path, location, comments)
|
40
39
|
@name = name
|
41
40
|
@file_path = file_path
|
42
41
|
@comments = comments
|
43
42
|
@visibility = T.let(Visibility::PUBLIC, Visibility)
|
44
|
-
|
45
|
-
@location = T.let(
|
46
|
-
if location.is_a?(Prism::Location)
|
47
|
-
Location.new(
|
48
|
-
location.start_line,
|
49
|
-
location.end_line,
|
50
|
-
location.start_code_units_column(encoding),
|
51
|
-
location.end_code_units_column(encoding),
|
52
|
-
)
|
53
|
-
else
|
54
|
-
location
|
55
|
-
end,
|
56
|
-
RubyIndexer::Location,
|
57
|
-
)
|
43
|
+
@location = location
|
58
44
|
end
|
59
45
|
|
60
46
|
sig { returns(T::Boolean) }
|
@@ -110,6 +96,10 @@ module RubyIndexer
|
|
110
96
|
else
|
111
97
|
""
|
112
98
|
end
|
99
|
+
rescue Errno::ENOENT
|
100
|
+
# If the file was deleted, but the entry hasn't been removed yet (could happen due to concurrency), then we do
|
101
|
+
# not want to fail. Just set the comments to an empty string
|
102
|
+
""
|
113
103
|
end
|
114
104
|
end
|
115
105
|
|
@@ -148,32 +138,19 @@ module RubyIndexer
|
|
148
138
|
params(
|
149
139
|
nesting: T::Array[String],
|
150
140
|
file_path: String,
|
151
|
-
location:
|
152
|
-
name_location:
|
141
|
+
location: Location,
|
142
|
+
name_location: Location,
|
153
143
|
comments: T.nilable(String),
|
154
|
-
encoding: Encoding,
|
155
144
|
).void
|
156
145
|
end
|
157
|
-
def initialize(nesting, file_path, location, name_location, comments
|
146
|
+
def initialize(nesting, file_path, location, name_location, comments)
|
158
147
|
@name = T.let(nesting.join("::"), String)
|
159
148
|
# The original nesting where this namespace was discovered
|
160
149
|
@nesting = nesting
|
161
150
|
|
162
|
-
super(@name, file_path, location, comments
|
163
|
-
|
164
|
-
@name_location =
|
165
|
-
if name_location.is_a?(Prism::Location)
|
166
|
-
Location.new(
|
167
|
-
name_location.start_line,
|
168
|
-
name_location.end_line,
|
169
|
-
name_location.start_code_units_column(encoding),
|
170
|
-
name_location.end_code_units_column(encoding),
|
171
|
-
)
|
172
|
-
else
|
173
|
-
name_location
|
174
|
-
end,
|
175
|
-
RubyIndexer::Location,
|
176
|
-
)
|
151
|
+
super(@name, file_path, location, comments)
|
152
|
+
|
153
|
+
@name_location = name_location
|
177
154
|
end
|
178
155
|
|
179
156
|
sig { returns(T::Array[String]) }
|
@@ -210,15 +187,14 @@ module RubyIndexer
|
|
210
187
|
params(
|
211
188
|
nesting: T::Array[String],
|
212
189
|
file_path: String,
|
213
|
-
location:
|
214
|
-
name_location:
|
190
|
+
location: Location,
|
191
|
+
name_location: Location,
|
215
192
|
comments: T.nilable(String),
|
216
|
-
encoding: Encoding,
|
217
193
|
parent_class: T.nilable(String),
|
218
194
|
).void
|
219
195
|
end
|
220
|
-
def initialize(nesting, file_path, location, name_location, comments,
|
221
|
-
super(nesting, file_path, location, name_location, comments
|
196
|
+
def initialize(nesting, file_path, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
|
197
|
+
super(nesting, file_path, location, name_location, comments)
|
222
198
|
@parent_class = parent_class
|
223
199
|
end
|
224
200
|
|
@@ -233,26 +209,14 @@ module RubyIndexer
|
|
233
209
|
|
234
210
|
sig do
|
235
211
|
params(
|
236
|
-
location:
|
237
|
-
name_location:
|
212
|
+
location: Location,
|
213
|
+
name_location: Location,
|
238
214
|
comments: T.nilable(String),
|
239
|
-
encoding: Encoding,
|
240
215
|
).void
|
241
216
|
end
|
242
|
-
def update_singleton_information(location, name_location, comments
|
243
|
-
|
244
|
-
@
|
245
|
-
location.start_line,
|
246
|
-
location.end_line,
|
247
|
-
location.start_code_units_column(encoding),
|
248
|
-
location.end_code_units_column(encoding),
|
249
|
-
)
|
250
|
-
@name_location = Location.new(
|
251
|
-
name_location.start_line,
|
252
|
-
name_location.end_line,
|
253
|
-
name_location.start_code_units_column(encoding),
|
254
|
-
name_location.end_code_units_column(encoding),
|
255
|
-
)
|
217
|
+
def update_singleton_information(location, name_location, comments)
|
218
|
+
@location = location
|
219
|
+
@name_location = name_location
|
256
220
|
(@comments ||= +"") << comments if comments
|
257
221
|
end
|
258
222
|
end
|
@@ -369,15 +333,14 @@ module RubyIndexer
|
|
369
333
|
params(
|
370
334
|
name: String,
|
371
335
|
file_path: String,
|
372
|
-
location:
|
336
|
+
location: Location,
|
373
337
|
comments: T.nilable(String),
|
374
|
-
encoding: Encoding,
|
375
338
|
visibility: Visibility,
|
376
339
|
owner: T.nilable(Entry::Namespace),
|
377
340
|
).void
|
378
341
|
end
|
379
|
-
def initialize(name, file_path, location, comments,
|
380
|
-
super(name, file_path, location, comments
|
342
|
+
def initialize(name, file_path, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
343
|
+
super(name, file_path, location, comments)
|
381
344
|
@visibility = visibility
|
382
345
|
@owner = owner
|
383
346
|
end
|
@@ -437,31 +400,18 @@ module RubyIndexer
|
|
437
400
|
params(
|
438
401
|
name: String,
|
439
402
|
file_path: String,
|
440
|
-
location:
|
441
|
-
name_location:
|
403
|
+
location: Location,
|
404
|
+
name_location: Location,
|
442
405
|
comments: T.nilable(String),
|
443
|
-
encoding: Encoding,
|
444
406
|
signatures: T::Array[Signature],
|
445
407
|
visibility: Visibility,
|
446
408
|
owner: T.nilable(Entry::Namespace),
|
447
409
|
).void
|
448
410
|
end
|
449
|
-
def initialize(name, file_path, location, name_location, comments,
|
450
|
-
super(name, file_path, location, comments,
|
411
|
+
def initialize(name, file_path, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
412
|
+
super(name, file_path, location, comments, visibility, owner)
|
451
413
|
@signatures = signatures
|
452
|
-
@name_location =
|
453
|
-
if name_location.is_a?(Prism::Location)
|
454
|
-
Location.new(
|
455
|
-
name_location.start_line,
|
456
|
-
name_location.end_line,
|
457
|
-
name_location.start_code_units_column(encoding),
|
458
|
-
name_location.end_code_units_column(encoding),
|
459
|
-
)
|
460
|
-
else
|
461
|
-
name_location
|
462
|
-
end,
|
463
|
-
RubyIndexer::Location,
|
464
|
-
)
|
414
|
+
@name_location = name_location
|
465
415
|
end
|
466
416
|
end
|
467
417
|
|
@@ -490,13 +440,12 @@ module RubyIndexer
|
|
490
440
|
nesting: T::Array[String],
|
491
441
|
name: String,
|
492
442
|
file_path: String,
|
493
|
-
location:
|
443
|
+
location: Location,
|
494
444
|
comments: T.nilable(String),
|
495
|
-
encoding: Encoding,
|
496
445
|
).void
|
497
446
|
end
|
498
|
-
def initialize(target, nesting, name, file_path, location, comments
|
499
|
-
super(name, file_path, location, comments
|
447
|
+
def initialize(target, nesting, name, file_path, location, comments) # rubocop:disable Metrics/ParameterLists
|
448
|
+
super(name, file_path, location, comments)
|
500
449
|
|
501
450
|
@target = target
|
502
451
|
@nesting = nesting
|
@@ -510,14 +459,13 @@ module RubyIndexer
|
|
510
459
|
sig { returns(String) }
|
511
460
|
attr_reader :target
|
512
461
|
|
513
|
-
sig { params(target: String, unresolved_alias: UnresolvedConstantAlias
|
514
|
-
def initialize(target, unresolved_alias
|
462
|
+
sig { params(target: String, unresolved_alias: UnresolvedConstantAlias).void }
|
463
|
+
def initialize(target, unresolved_alias)
|
515
464
|
super(
|
516
465
|
unresolved_alias.name,
|
517
466
|
unresolved_alias.file_path,
|
518
467
|
unresolved_alias.location,
|
519
468
|
unresolved_alias.comments,
|
520
|
-
encoding
|
521
469
|
)
|
522
470
|
|
523
471
|
@visibility = unresolved_alias.visibility
|
@@ -525,6 +473,9 @@ module RubyIndexer
|
|
525
473
|
end
|
526
474
|
end
|
527
475
|
|
476
|
+
# Represents a global variable e.g.: $DEBUG
|
477
|
+
class GlobalVariable < Entry; end
|
478
|
+
|
528
479
|
# Represents an instance variable e.g.: @a = 1
|
529
480
|
class InstanceVariable < Entry
|
530
481
|
sig { returns(T.nilable(Entry::Namespace)) }
|
@@ -534,14 +485,13 @@ module RubyIndexer
|
|
534
485
|
params(
|
535
486
|
name: String,
|
536
487
|
file_path: String,
|
537
|
-
location:
|
488
|
+
location: Location,
|
538
489
|
comments: T.nilable(String),
|
539
|
-
encoding: Encoding,
|
540
490
|
owner: T.nilable(Entry::Namespace),
|
541
491
|
).void
|
542
492
|
end
|
543
|
-
def initialize(name, file_path, location, comments,
|
544
|
-
super(name, file_path, location, comments
|
493
|
+
def initialize(name, file_path, location, comments, owner)
|
494
|
+
super(name, file_path, location, comments)
|
545
495
|
@owner = owner
|
546
496
|
end
|
547
497
|
end
|
@@ -564,13 +514,12 @@ module RubyIndexer
|
|
564
514
|
old_name: String,
|
565
515
|
owner: T.nilable(Entry::Namespace),
|
566
516
|
file_path: String,
|
567
|
-
location:
|
517
|
+
location: Location,
|
568
518
|
comments: T.nilable(String),
|
569
|
-
encoding: Encoding,
|
570
519
|
).void
|
571
520
|
end
|
572
|
-
def initialize(new_name, old_name, owner, file_path, location, comments
|
573
|
-
super(new_name, file_path, location, comments
|
521
|
+
def initialize(new_name, old_name, owner, file_path, location, comments) # rubocop:disable Metrics/ParameterLists
|
522
|
+
super(new_name, file_path, location, comments)
|
574
523
|
|
575
524
|
@new_name = new_name
|
576
525
|
@old_name = old_name
|
@@ -589,9 +538,9 @@ module RubyIndexer
|
|
589
538
|
attr_reader :owner
|
590
539
|
|
591
540
|
sig do
|
592
|
-
params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias
|
541
|
+
params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias).void
|
593
542
|
end
|
594
|
-
def initialize(target, unresolved_alias
|
543
|
+
def initialize(target, unresolved_alias)
|
595
544
|
full_comments = +"Alias for #{target.name}\n"
|
596
545
|
full_comments << "#{unresolved_alias.comments}\n"
|
597
546
|
full_comments << target.comments
|
@@ -601,7 +550,6 @@ module RubyIndexer
|
|
601
550
|
unresolved_alias.file_path,
|
602
551
|
unresolved_alias.location,
|
603
552
|
full_comments,
|
604
|
-
encoding
|
605
553
|
)
|
606
554
|
|
607
555
|
@target = target
|
@@ -665,7 +665,6 @@ module RubyIndexer
|
|
665
665
|
attached_ancestor.location,
|
666
666
|
attached_ancestor.name_location,
|
667
667
|
nil,
|
668
|
-
@configuration.encoding,
|
669
668
|
nil,
|
670
669
|
)
|
671
670
|
add(singleton, skip_prefix_tree: true)
|
@@ -677,11 +676,13 @@ module RubyIndexer
|
|
677
676
|
sig do
|
678
677
|
type_parameters(:T).params(
|
679
678
|
path: String,
|
680
|
-
type: T::Class[T.all(T.type_parameter(:T), Entry)],
|
681
|
-
).returns(T.nilable(T::Array[T.type_parameter(:T)]))
|
679
|
+
type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]),
|
680
|
+
).returns(T.nilable(T.any(T::Array[Entry], T::Array[T.type_parameter(:T)])))
|
682
681
|
end
|
683
|
-
def entries_for(path, type)
|
682
|
+
def entries_for(path, type = nil)
|
684
683
|
entries = @files_to_entries[path]
|
684
|
+
return entries unless type
|
685
|
+
|
685
686
|
entries&.grep(type)
|
686
687
|
end
|
687
688
|
|
@@ -857,7 +858,7 @@ module RubyIndexer
|
|
857
858
|
return entry unless target
|
858
859
|
|
859
860
|
target_name = T.must(target.first).name
|
860
|
-
resolved_alias = Entry::ConstantAlias.new(target_name, entry
|
861
|
+
resolved_alias = Entry::ConstantAlias.new(target_name, entry)
|
861
862
|
|
862
863
|
# Replace the UnresolvedAlias by a resolved one so that we don't have to do this again later
|
863
864
|
original_entries = T.must(@entries[alias_name])
|
@@ -1048,7 +1049,7 @@ module RubyIndexer
|
|
1048
1049
|
target_method_entries = resolve_method(entry.old_name, receiver_name, seen_names)
|
1049
1050
|
return entry unless target_method_entries
|
1050
1051
|
|
1051
|
-
resolved_alias = Entry::MethodAlias.new(T.must(target_method_entries.first), entry
|
1052
|
+
resolved_alias = Entry::MethodAlias.new(T.must(target_method_entries.first), entry)
|
1052
1053
|
original_entries = T.must(@entries[new_name])
|
1053
1054
|
original_entries.delete(entry)
|
1054
1055
|
original_entries << resolved_alias
|
@@ -5,6 +5,28 @@ module RubyIndexer
|
|
5
5
|
class Location
|
6
6
|
extend T::Sig
|
7
7
|
|
8
|
+
class << self
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
sig do
|
12
|
+
params(
|
13
|
+
prism_location: Prism::Location,
|
14
|
+
code_units_cache: T.any(
|
15
|
+
T.proc.params(arg0: Integer).returns(Integer),
|
16
|
+
Prism::CodeUnitsCache,
|
17
|
+
),
|
18
|
+
).returns(T.attached_class)
|
19
|
+
end
|
20
|
+
def from_prism_location(prism_location, code_units_cache)
|
21
|
+
new(
|
22
|
+
prism_location.start_line,
|
23
|
+
prism_location.end_line,
|
24
|
+
prism_location.cached_start_code_units_column(code_units_cache),
|
25
|
+
prism_location.cached_end_code_units_column(code_units_cache),
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
8
30
|
sig { returns(Integer) }
|
9
31
|
attr_reader :start_line, :end_line, :start_column, :end_column
|
10
32
|
|