ruby-lsp 0.23.11 → 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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-launcher +12 -11
  5. data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
  6. data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
  7. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +81 -115
  8. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +117 -166
  9. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
  10. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +88 -200
  11. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +56 -192
  12. data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
  13. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +14 -16
  14. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
  15. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +42 -60
  16. data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
  17. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
  18. data/lib/ruby_indexer/test/configuration_test.rb +42 -3
  19. data/lib/ruby_indexer/test/method_test.rb +28 -2
  20. data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
  21. data/lib/ruby_lsp/addon.rb +44 -71
  22. data/lib/ruby_lsp/base_server.rb +29 -32
  23. data/lib/ruby_lsp/client_capabilities.rb +10 -12
  24. data/lib/ruby_lsp/document.rb +34 -45
  25. data/lib/ruby_lsp/erb_document.rb +24 -36
  26. data/lib/ruby_lsp/global_state.rb +51 -56
  27. data/lib/ruby_lsp/internal.rb +2 -0
  28. data/lib/ruby_lsp/listeners/code_lens.rb +81 -88
  29. data/lib/ruby_lsp/listeners/completion.rb +36 -55
  30. data/lib/ruby_lsp/listeners/definition.rb +37 -51
  31. data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
  32. data/lib/ruby_lsp/listeners/document_link.rb +43 -62
  33. data/lib/ruby_lsp/listeners/document_symbol.rb +35 -49
  34. data/lib/ruby_lsp/listeners/folding_ranges.rb +32 -39
  35. data/lib/ruby_lsp/listeners/hover.rb +81 -100
  36. data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
  37. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +42 -51
  38. data/lib/ruby_lsp/listeners/signature_help.rb +6 -25
  39. data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
  40. data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
  41. data/lib/ruby_lsp/listeners/test_style.rb +160 -88
  42. data/lib/ruby_lsp/node_context.rb +12 -39
  43. data/lib/ruby_lsp/rbs_document.rb +8 -6
  44. data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
  45. data/lib/ruby_lsp/requests/code_actions.rb +14 -26
  46. data/lib/ruby_lsp/requests/code_lens.rb +6 -17
  47. data/lib/ruby_lsp/requests/completion.rb +7 -20
  48. data/lib/ruby_lsp/requests/completion_resolve.rb +5 -5
  49. data/lib/ruby_lsp/requests/definition.rb +8 -17
  50. data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
  51. data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
  52. data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
  53. data/lib/ruby_lsp/requests/document_link.rb +6 -17
  54. data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
  55. data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
  56. data/lib/ruby_lsp/requests/formatting.rb +6 -9
  57. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
  58. data/lib/ruby_lsp/requests/hover.rb +8 -18
  59. data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
  60. data/lib/ruby_lsp/requests/on_type_formatting.rb +28 -38
  61. data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
  62. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
  63. data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
  64. data/lib/ruby_lsp/requests/references.rb +6 -36
  65. data/lib/ruby_lsp/requests/rename.rb +11 -37
  66. data/lib/ruby_lsp/requests/request.rb +7 -19
  67. data/lib/ruby_lsp/requests/selection_ranges.rb +5 -5
  68. data/lib/ruby_lsp/requests/semantic_highlighting.rb +12 -31
  69. data/lib/ruby_lsp/requests/show_syntax_tree.rb +5 -6
  70. data/lib/ruby_lsp/requests/signature_help.rb +8 -26
  71. data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
  72. data/lib/ruby_lsp/requests/support/common.rb +13 -50
  73. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
  74. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +9 -12
  75. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
  76. data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
  77. data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
  78. data/lib/ruby_lsp/requests/support/source_uri.rb +16 -30
  79. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
  80. data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
  81. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
  82. data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
  83. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
  84. data/lib/ruby_lsp/response_builders/document_symbol.rb +10 -16
  85. data/lib/ruby_lsp/response_builders/hover.rb +10 -13
  86. data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
  87. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +59 -87
  88. data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
  89. data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
  90. data/lib/ruby_lsp/ruby_document.rb +22 -60
  91. data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +109 -0
  92. data/lib/ruby_lsp/scope.rb +7 -11
  93. data/lib/ruby_lsp/server.rb +133 -74
  94. data/lib/ruby_lsp/setup_bundler.rb +58 -57
  95. data/lib/ruby_lsp/static_docs.rb +4 -7
  96. data/lib/ruby_lsp/store.rb +21 -40
  97. data/lib/ruby_lsp/test_helper.rb +3 -12
  98. data/lib/ruby_lsp/test_reporter.rb +207 -0
  99. data/lib/ruby_lsp/test_unit_test_runner.rb +98 -0
  100. data/lib/ruby_lsp/type_inferrer.rb +9 -13
  101. data/lib/ruby_lsp/utils.rb +37 -81
  102. metadata +9 -3
@@ -33,21 +33,20 @@ module RubyIndexer
33
33
  #
34
34
  # See https://en.wikipedia.org/wiki/Trie for more information
35
35
  class PrefixTree
36
- extend T::Sig
37
36
  extend T::Generic
38
37
 
39
38
  Value = type_member
40
39
 
41
- sig { void }
40
+ #: -> void
42
41
  def initialize
43
- @root = T.let(Node.new("", ""), Node[Value])
42
+ @root = Node.new("", "") #: Node[Value]
44
43
  end
45
44
 
46
45
  # Search the PrefixTree based on a given `prefix`. If `foo` is an entry in the tree, then searching for `fo` will
47
46
  # return it as a result. The result is always an array of the type of value attribute to the generic `Value` type.
48
47
  # Notice that if the `Value` is an array, this method will return an array of arrays, where each entry is the array
49
48
  # of values for a given match
50
- sig { params(prefix: String).returns(T::Array[Value]) }
49
+ #: (String prefix) -> Array[Value]
51
50
  def search(prefix)
52
51
  node = find_node(prefix)
53
52
  return [] unless node
@@ -56,7 +55,7 @@ module RubyIndexer
56
55
  end
57
56
 
58
57
  # Inserts a `value` using the given `key`
59
- sig { params(key: String, value: Value).void }
58
+ #: (String key, Value value) -> void
60
59
  def insert(key, value)
61
60
  node = @root
62
61
 
@@ -73,13 +72,13 @@ module RubyIndexer
73
72
 
74
73
  # Deletes the entry identified by `key` from the tree. Notice that a partial match will still delete all entries
75
74
  # that match it. For example, if the tree contains `foo` and we ask to delete `fo`, then `foo` will be deleted
76
- sig { params(key: String).void }
75
+ #: (String key) -> void
77
76
  def delete(key)
78
77
  node = find_node(key)
79
78
  return unless node
80
79
 
81
80
  # Remove the node from the tree and then go up the parents to remove any of them with empty children
82
- parent = T.let(T.must(node.parent), T.nilable(Node[Value]))
81
+ parent = T.must(node.parent) #: Node[Value]?
83
82
 
84
83
  while parent
85
84
  parent.children.delete(node.key)
@@ -93,7 +92,7 @@ module RubyIndexer
93
92
  private
94
93
 
95
94
  # Find a node that matches the given `key`
96
- sig { params(key: String).returns(T.nilable(Node[Value])) }
95
+ #: (String key) -> Node[Value]?
97
96
  def find_node(key)
98
97
  node = @root
99
98
 
@@ -108,27 +107,26 @@ module RubyIndexer
108
107
  end
109
108
 
110
109
  class Node
111
- extend T::Sig
112
110
  extend T::Generic
113
111
 
114
112
  Value = type_member
115
113
 
116
- sig { returns(T::Hash[String, Node[Value]]) }
114
+ #: Hash[String, Node[Value]]
117
115
  attr_reader :children
118
116
 
119
- sig { returns(String) }
117
+ #: String
120
118
  attr_reader :key
121
119
 
122
- sig { returns(Value) }
120
+ #: Value
123
121
  attr_accessor :value
124
122
 
125
- sig { returns(T::Boolean) }
123
+ #: bool
126
124
  attr_accessor :leaf
127
125
 
128
- sig { returns(T.nilable(Node[Value])) }
126
+ #: Node[Value]?
129
127
  attr_reader :parent
130
128
 
131
- sig { params(key: String, value: Value, parent: T.nilable(Node[Value])).void }
129
+ #: (String key, Value value, ?Node[Value]? parent) -> void
132
130
  def initialize(key, value, parent = nil)
133
131
  @key = key
134
132
  @value = value
@@ -137,7 +135,7 @@ module RubyIndexer
137
135
  @leaf = false
138
136
  end
139
137
 
140
- sig { returns(T::Array[Value]) }
138
+ #: -> Array[Value]
141
139
  def collect
142
140
  result = []
143
141
  result << @value if @leaf
@@ -3,16 +3,14 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class RBSIndexer
6
- extend T::Sig
6
+ HAS_UNTYPED_FUNCTION = !!defined?(RBS::Types::UntypedFunction) #: bool
7
7
 
8
- HAS_UNTYPED_FUNCTION = T.let(!!defined?(RBS::Types::UntypedFunction), T::Boolean)
9
-
10
- sig { params(index: Index).void }
8
+ #: (Index index) -> void
11
9
  def initialize(index)
12
10
  @index = index
13
11
  end
14
12
 
15
- sig { void }
13
+ #: -> void
16
14
  def index_ruby_core
17
15
  loader = RBS::EnvironmentLoader.new
18
16
  RBS::Environment.from_loader(loader).resolve_type_names
@@ -22,12 +20,7 @@ module RubyIndexer
22
20
  end
23
21
  end
24
22
 
25
- sig do
26
- params(
27
- pathname: Pathname,
28
- declarations: T::Array[RBS::AST::Declarations::Base],
29
- ).void
30
- end
23
+ #: (Pathname pathname, Array[RBS::AST::Declarations::Base] declarations) -> void
31
24
  def process_signature(pathname, declarations)
32
25
  declarations.each do |declaration|
33
26
  process_declaration(declaration, pathname)
@@ -36,7 +29,7 @@ module RubyIndexer
36
29
 
37
30
  private
38
31
 
39
- sig { params(declaration: RBS::AST::Declarations::Base, pathname: Pathname).void }
32
+ #: (RBS::AST::Declarations::Base declaration, Pathname pathname) -> void
40
33
  def process_declaration(declaration, pathname)
41
34
  case declaration
42
35
  when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
@@ -51,9 +44,7 @@ module RubyIndexer
51
44
  end
52
45
  end
53
46
 
54
- sig do
55
- params(declaration: T.any(RBS::AST::Declarations::Class, RBS::AST::Declarations::Module), pathname: Pathname).void
56
- end
47
+ #: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module) declaration, Pathname pathname) -> void
57
48
  def handle_class_or_module_declaration(declaration, pathname)
58
49
  nesting = [declaration.name.name.to_s]
59
50
  uri = URI::Generic.from_path(path: pathname.to_s)
@@ -83,7 +74,7 @@ module RubyIndexer
83
74
  end
84
75
  end
85
76
 
86
- sig { params(rbs_location: RBS::Location).returns(RubyIndexer::Location) }
77
+ #: (RBS::Location rbs_location) -> RubyIndexer::Location
87
78
  def to_ruby_indexer_location(rbs_location)
88
79
  RubyIndexer::Location.new(
89
80
  rbs_location.start_line,
@@ -93,12 +84,7 @@ module RubyIndexer
93
84
  )
94
85
  end
95
86
 
96
- sig do
97
- params(
98
- declaration: T.any(RBS::AST::Declarations::Class, RBS::AST::Declarations::Module),
99
- entry: Entry::Namespace,
100
- ).void
101
- end
87
+ #: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module) declaration, Entry::Namespace entry) -> void
102
88
  def add_declaration_mixins_to_entry(declaration, entry)
103
89
  declaration.each_mixin do |mixin|
104
90
  name = mixin.name.name.to_s
@@ -114,7 +100,7 @@ module RubyIndexer
114
100
  end
115
101
  end
116
102
 
117
- sig { params(member: RBS::AST::Members::MethodDefinition, owner: Entry::Namespace).void }
103
+ #: (RBS::AST::Members::MethodDefinition member, Entry::Namespace owner) -> void
118
104
  def handle_method(member, owner)
119
105
  name = member.name.name
120
106
  uri = URI::Generic.from_path(path: member.location.buffer.name)
@@ -144,7 +130,7 @@ module RubyIndexer
144
130
  ))
145
131
  end
146
132
 
147
- sig { params(member: RBS::AST::Members::MethodDefinition).returns(T::Array[Entry::Signature]) }
133
+ #: (RBS::AST::Members::MethodDefinition member) -> Array[Entry::Signature]
148
134
  def signatures(member)
149
135
  member.overloads.map do |overload|
150
136
  parameters = process_overload(overload)
@@ -152,7 +138,7 @@ module RubyIndexer
152
138
  end
153
139
  end
154
140
 
155
- sig { params(overload: RBS::AST::Members::MethodDefinition::Overload).returns(T::Array[Entry::Parameter]) }
141
+ #: (RBS::AST::Members::MethodDefinition::Overload overload) -> Array[Entry::Parameter]
156
142
  def process_overload(overload)
157
143
  function = overload.method_type.type
158
144
 
@@ -173,7 +159,7 @@ module RubyIndexer
173
159
  end
174
160
  end
175
161
 
176
- sig { params(function: RBS::Types::Function).returns(T::Array[Entry::Parameter]) }
162
+ #: (RBS::Types::Function function) -> Array[Entry::Parameter]
177
163
  def parse_arguments(function)
178
164
  parameters = []
179
165
  parameters.concat(process_required_and_optional_positionals(function))
@@ -185,7 +171,7 @@ module RubyIndexer
185
171
  parameters
186
172
  end
187
173
 
188
- sig { params(function: RBS::Types::Function).returns(T::Array[Entry::RequiredParameter]) }
174
+ #: (RBS::Types::Function function) -> Array[Entry::RequiredParameter]
189
175
  def process_required_and_optional_positionals(function)
190
176
  argument_offset = 0
191
177
 
@@ -209,14 +195,14 @@ module RubyIndexer
209
195
  required + optional
210
196
  end
211
197
 
212
- sig { params(function: RBS::Types::Function).returns(T::Array[Entry::OptionalParameter]) }
198
+ #: (RBS::Types::Function function) -> Array[Entry::OptionalParameter]
213
199
  def process_trailing_positionals(function)
214
200
  function.trailing_positionals.map do |param|
215
201
  Entry::OptionalParameter.new(name: param.name)
216
202
  end
217
203
  end
218
204
 
219
- sig { params(function: RBS::Types::Function).returns(Entry::RestParameter) }
205
+ #: (RBS::Types::Function function) -> Entry::RestParameter
220
206
  def process_rest_positionals(function)
221
207
  rest = function.rest_positionals
222
208
 
@@ -225,21 +211,21 @@ module RubyIndexer
225
211
  Entry::RestParameter.new(name: rest_name)
226
212
  end
227
213
 
228
- sig { params(function: RBS::Types::Function).returns(T::Array[Entry::KeywordParameter]) }
214
+ #: (RBS::Types::Function function) -> Array[Entry::KeywordParameter]
229
215
  def process_required_keywords(function)
230
216
  function.required_keywords.map do |name, _param|
231
217
  Entry::KeywordParameter.new(name: name)
232
218
  end
233
219
  end
234
220
 
235
- sig { params(function: RBS::Types::Function).returns(T::Array[Entry::OptionalKeywordParameter]) }
221
+ #: (RBS::Types::Function function) -> Array[Entry::OptionalKeywordParameter]
236
222
  def process_optional_keywords(function)
237
223
  function.optional_keywords.map do |name, _param|
238
224
  Entry::OptionalKeywordParameter.new(name: name)
239
225
  end
240
226
  end
241
227
 
242
- sig { params(function: RBS::Types::Function).returns(Entry::KeywordRestParameter) }
228
+ #: (RBS::Types::Function function) -> Entry::KeywordRestParameter
243
229
  def process_rest_keywords(function)
244
230
  param = function.rest_keywords
245
231
 
@@ -262,7 +248,7 @@ module RubyIndexer
262
248
  # Complex::I = ... # Complex::I is a top-level constant
263
249
  #
264
250
  # And we need to handle their nesting differently.
265
- sig { params(declaration: RBS::AST::Declarations::Constant, nesting: T::Array[String], uri: URI::Generic).void }
251
+ #: (RBS::AST::Declarations::Constant declaration, Array[String] nesting, URI::Generic uri) -> void
266
252
  def handle_constant(declaration, nesting, uri)
267
253
  fully_qualified_name = [*nesting, declaration.name.name.to_s].join("::")
268
254
  @index.add(Entry::Constant.new(
@@ -273,7 +259,7 @@ module RubyIndexer
273
259
  ))
274
260
  end
275
261
 
276
- sig { params(declaration: RBS::AST::Declarations::Global, pathname: Pathname).void }
262
+ #: (RBS::AST::Declarations::Global declaration, Pathname pathname) -> void
277
263
  def handle_global_variable(declaration, pathname)
278
264
  name = declaration.name.to_s
279
265
  uri = URI::Generic.from_path(path: pathname.to_s)
@@ -288,7 +274,7 @@ module RubyIndexer
288
274
  ))
289
275
  end
290
276
 
291
- sig { params(member: RBS::AST::Members::Alias, owner_entry: Entry::Namespace).void }
277
+ #: (RBS::AST::Members::Alias member, Entry::Namespace owner_entry) -> void
292
278
  def handle_signature_alias(member, owner_entry)
293
279
  uri = URI::Generic.from_path(path: member.location.buffer.name)
294
280
  comments = comments_to_string(member)
@@ -305,16 +291,7 @@ module RubyIndexer
305
291
  @index.add(entry)
306
292
  end
307
293
 
308
- sig do
309
- params(declaration: T.any(
310
- RBS::AST::Declarations::Class,
311
- RBS::AST::Declarations::Module,
312
- RBS::AST::Declarations::Constant,
313
- RBS::AST::Declarations::Global,
314
- RBS::AST::Members::MethodDefinition,
315
- RBS::AST::Members::Alias,
316
- )).returns(T.nilable(String))
317
- end
294
+ #: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module | RBS::AST::Declarations::Constant | RBS::AST::Declarations::Global | RBS::AST::Members::MethodDefinition | RBS::AST::Members::Alias) declaration) -> String?
318
295
  def comments_to_string(declaration)
319
296
  declaration.comment&.string
320
297
  end
@@ -3,8 +3,6 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class ReferenceFinder
6
- extend T::Sig
7
-
8
6
  class Target
9
7
  extend T::Helpers
10
8
 
@@ -12,12 +10,10 @@ module RubyIndexer
12
10
  end
13
11
 
14
12
  class ConstTarget < Target
15
- extend T::Sig
16
-
17
- sig { returns(String) }
13
+ #: String
18
14
  attr_reader :fully_qualified_name
19
15
 
20
- sig { params(fully_qualified_name: String).void }
16
+ #: (String fully_qualified_name) -> void
21
17
  def initialize(fully_qualified_name)
22
18
  super()
23
19
  @fully_qualified_name = fully_qualified_name
@@ -25,12 +21,10 @@ module RubyIndexer
25
21
  end
26
22
 
27
23
  class MethodTarget < Target
28
- extend T::Sig
29
-
30
- sig { returns(String) }
24
+ #: String
31
25
  attr_reader :method_name
32
26
 
33
- sig { params(method_name: String).void }
27
+ #: (String method_name) -> void
34
28
  def initialize(method_name)
35
29
  super()
36
30
  @method_name = method_name
@@ -38,12 +32,10 @@ module RubyIndexer
38
32
  end
39
33
 
40
34
  class InstanceVariableTarget < Target
41
- extend T::Sig
42
-
43
- sig { returns(String) }
35
+ #: String
44
36
  attr_reader :name
45
37
 
46
- sig { params(name: String).void }
38
+ #: (String name) -> void
47
39
  def initialize(name)
48
40
  super()
49
41
  @name = name
@@ -51,18 +43,16 @@ module RubyIndexer
51
43
  end
52
44
 
53
45
  class Reference
54
- extend T::Sig
55
-
56
- sig { returns(String) }
46
+ #: String
57
47
  attr_reader :name
58
48
 
59
- sig { returns(Prism::Location) }
49
+ #: Prism::Location
60
50
  attr_reader :location
61
51
 
62
- sig { returns(T::Boolean) }
52
+ #: bool
63
53
  attr_reader :declaration
64
54
 
65
- sig { params(name: String, location: Prism::Location, declaration: T::Boolean).void }
55
+ #: (String name, Prism::Location location, declaration: bool) -> void
66
56
  def initialize(name, location, declaration:)
67
57
  @name = name
68
58
  @location = location
@@ -70,22 +60,14 @@ module RubyIndexer
70
60
  end
71
61
  end
72
62
 
73
- sig do
74
- params(
75
- target: Target,
76
- index: RubyIndexer::Index,
77
- dispatcher: Prism::Dispatcher,
78
- uri: URI::Generic,
79
- include_declarations: T::Boolean,
80
- ).void
81
- end
63
+ #: (Target target, RubyIndexer::Index index, Prism::Dispatcher dispatcher, URI::Generic uri, ?include_declarations: bool) -> void
82
64
  def initialize(target, index, dispatcher, uri, include_declarations: true)
83
65
  @target = target
84
66
  @index = index
85
67
  @uri = uri
86
68
  @include_declarations = include_declarations
87
- @stack = T.let([], T::Array[String])
88
- @references = T.let([], T::Array[Reference])
69
+ @stack = [] #: Array[String]
70
+ @references = [] #: Array[Reference]
89
71
 
90
72
  dispatcher.register(
91
73
  self,
@@ -119,34 +101,34 @@ module RubyIndexer
119
101
  )
120
102
  end
121
103
 
122
- sig { returns(T::Array[Reference]) }
104
+ #: -> Array[Reference]
123
105
  def references
124
106
  return @references if @include_declarations
125
107
 
126
108
  @references.reject(&:declaration)
127
109
  end
128
110
 
129
- sig { params(node: Prism::ClassNode).void }
111
+ #: (Prism::ClassNode node) -> void
130
112
  def on_class_node_enter(node)
131
113
  @stack << node.constant_path.slice
132
114
  end
133
115
 
134
- sig { params(node: Prism::ClassNode).void }
116
+ #: (Prism::ClassNode node) -> void
135
117
  def on_class_node_leave(node)
136
118
  @stack.pop
137
119
  end
138
120
 
139
- sig { params(node: Prism::ModuleNode).void }
121
+ #: (Prism::ModuleNode node) -> void
140
122
  def on_module_node_enter(node)
141
123
  @stack << node.constant_path.slice
142
124
  end
143
125
 
144
- sig { params(node: Prism::ModuleNode).void }
126
+ #: (Prism::ModuleNode node) -> void
145
127
  def on_module_node_leave(node)
146
128
  @stack.pop
147
129
  end
148
130
 
149
- sig { params(node: Prism::SingletonClassNode).void }
131
+ #: (Prism::SingletonClassNode node) -> void
150
132
  def on_singleton_class_node_enter(node)
151
133
  expression = node.expression
152
134
  return unless expression.is_a?(Prism::SelfNode)
@@ -154,12 +136,12 @@ module RubyIndexer
154
136
  @stack << "<Class:#{@stack.last}>"
155
137
  end
156
138
 
157
- sig { params(node: Prism::SingletonClassNode).void }
139
+ #: (Prism::SingletonClassNode node) -> void
158
140
  def on_singleton_class_node_leave(node)
159
141
  @stack.pop
160
142
  end
161
143
 
162
- sig { params(node: Prism::ConstantPathNode).void }
144
+ #: (Prism::ConstantPathNode node) -> void
163
145
  def on_constant_path_node_enter(node)
164
146
  name = Index.constant_name(node)
165
147
  return unless name
@@ -167,7 +149,7 @@ module RubyIndexer
167
149
  collect_constant_references(name, node.location)
168
150
  end
169
151
 
170
- sig { params(node: Prism::ConstantReadNode).void }
152
+ #: (Prism::ConstantReadNode node) -> void
171
153
  def on_constant_read_node_enter(node)
172
154
  name = Index.constant_name(node)
173
155
  return unless name
@@ -175,7 +157,7 @@ module RubyIndexer
175
157
  collect_constant_references(name, node.location)
176
158
  end
177
159
 
178
- sig { params(node: Prism::MultiWriteNode).void }
160
+ #: (Prism::MultiWriteNode node) -> void
179
161
  def on_multi_write_node_enter(node)
180
162
  [*node.lefts, *node.rest, *node.rights].each do |target|
181
163
  case target
@@ -185,7 +167,7 @@ module RubyIndexer
185
167
  end
186
168
  end
187
169
 
188
- sig { params(node: Prism::ConstantPathWriteNode).void }
170
+ #: (Prism::ConstantPathWriteNode node) -> void
189
171
  def on_constant_path_write_node_enter(node)
190
172
  target = node.target
191
173
  return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
@@ -196,7 +178,7 @@ module RubyIndexer
196
178
  collect_constant_references(name, target.location)
197
179
  end
198
180
 
199
- sig { params(node: Prism::ConstantPathOrWriteNode).void }
181
+ #: (Prism::ConstantPathOrWriteNode node) -> void
200
182
  def on_constant_path_or_write_node_enter(node)
201
183
  target = node.target
202
184
  return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
@@ -207,7 +189,7 @@ module RubyIndexer
207
189
  collect_constant_references(name, target.location)
208
190
  end
209
191
 
210
- sig { params(node: Prism::ConstantPathOperatorWriteNode).void }
192
+ #: (Prism::ConstantPathOperatorWriteNode node) -> void
211
193
  def on_constant_path_operator_write_node_enter(node)
212
194
  target = node.target
213
195
  return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
@@ -218,7 +200,7 @@ module RubyIndexer
218
200
  collect_constant_references(name, target.location)
219
201
  end
220
202
 
221
- sig { params(node: Prism::ConstantPathAndWriteNode).void }
203
+ #: (Prism::ConstantPathAndWriteNode node) -> void
222
204
  def on_constant_path_and_write_node_enter(node)
223
205
  target = node.target
224
206
  return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
@@ -229,27 +211,27 @@ module RubyIndexer
229
211
  collect_constant_references(name, target.location)
230
212
  end
231
213
 
232
- sig { params(node: Prism::ConstantWriteNode).void }
214
+ #: (Prism::ConstantWriteNode node) -> void
233
215
  def on_constant_write_node_enter(node)
234
216
  collect_constant_references(node.name.to_s, node.name_loc)
235
217
  end
236
218
 
237
- sig { params(node: Prism::ConstantOrWriteNode).void }
219
+ #: (Prism::ConstantOrWriteNode node) -> void
238
220
  def on_constant_or_write_node_enter(node)
239
221
  collect_constant_references(node.name.to_s, node.name_loc)
240
222
  end
241
223
 
242
- sig { params(node: Prism::ConstantAndWriteNode).void }
224
+ #: (Prism::ConstantAndWriteNode node) -> void
243
225
  def on_constant_and_write_node_enter(node)
244
226
  collect_constant_references(node.name.to_s, node.name_loc)
245
227
  end
246
228
 
247
- sig { params(node: Prism::ConstantOperatorWriteNode).void }
229
+ #: (Prism::ConstantOperatorWriteNode node) -> void
248
230
  def on_constant_operator_write_node_enter(node)
249
231
  collect_constant_references(node.name.to_s, node.name_loc)
250
232
  end
251
233
 
252
- sig { params(node: Prism::DefNode).void }
234
+ #: (Prism::DefNode node) -> void
253
235
  def on_def_node_enter(node)
254
236
  if @target.is_a?(MethodTarget) && (name = node.name.to_s) == @target.method_name
255
237
  @references << Reference.new(name, node.name_loc, declaration: true)
@@ -260,44 +242,44 @@ module RubyIndexer
260
242
  end
261
243
  end
262
244
 
263
- sig { params(node: Prism::DefNode).void }
245
+ #: (Prism::DefNode node) -> void
264
246
  def on_def_node_leave(node)
265
247
  if node.receiver.is_a?(Prism::SelfNode)
266
248
  @stack.pop
267
249
  end
268
250
  end
269
251
 
270
- sig { params(node: Prism::InstanceVariableReadNode).void }
252
+ #: (Prism::InstanceVariableReadNode node) -> void
271
253
  def on_instance_variable_read_node_enter(node)
272
254
  collect_instance_variable_references(node.name.to_s, node.location, false)
273
255
  end
274
256
 
275
- sig { params(node: Prism::InstanceVariableWriteNode).void }
257
+ #: (Prism::InstanceVariableWriteNode node) -> void
276
258
  def on_instance_variable_write_node_enter(node)
277
259
  collect_instance_variable_references(node.name.to_s, node.name_loc, true)
278
260
  end
279
261
 
280
- sig { params(node: Prism::InstanceVariableAndWriteNode).void }
262
+ #: (Prism::InstanceVariableAndWriteNode node) -> void
281
263
  def on_instance_variable_and_write_node_enter(node)
282
264
  collect_instance_variable_references(node.name.to_s, node.name_loc, true)
283
265
  end
284
266
 
285
- sig { params(node: Prism::InstanceVariableOperatorWriteNode).void }
267
+ #: (Prism::InstanceVariableOperatorWriteNode node) -> void
286
268
  def on_instance_variable_operator_write_node_enter(node)
287
269
  collect_instance_variable_references(node.name.to_s, node.name_loc, true)
288
270
  end
289
271
 
290
- sig { params(node: Prism::InstanceVariableOrWriteNode).void }
272
+ #: (Prism::InstanceVariableOrWriteNode node) -> void
291
273
  def on_instance_variable_or_write_node_enter(node)
292
274
  collect_instance_variable_references(node.name.to_s, node.name_loc, true)
293
275
  end
294
276
 
295
- sig { params(node: Prism::InstanceVariableTargetNode).void }
277
+ #: (Prism::InstanceVariableTargetNode node) -> void
296
278
  def on_instance_variable_target_node_enter(node)
297
279
  collect_instance_variable_references(node.name.to_s, node.location, true)
298
280
  end
299
281
 
300
- sig { params(node: Prism::CallNode).void }
282
+ #: (Prism::CallNode node) -> void
301
283
  def on_call_node_enter(node)
302
284
  if @target.is_a?(MethodTarget) && (name = node.name.to_s) == @target.method_name
303
285
  @references << Reference.new(name, T.must(node.message_loc), declaration: false)
@@ -306,7 +288,7 @@ module RubyIndexer
306
288
 
307
289
  private
308
290
 
309
- sig { params(name: String, location: Prism::Location).void }
291
+ #: (String name, Prism::Location location) -> void
310
292
  def collect_constant_references(name, location)
311
293
  return unless @target.is_a?(ConstTarget)
312
294
 
@@ -335,7 +317,7 @@ module RubyIndexer
335
317
  @references << Reference.new(name, location, declaration: declaration)
336
318
  end
337
319
 
338
- sig { params(name: String, location: Prism::Location, declaration: T::Boolean).void }
320
+ #: (String name, Prism::Location location, bool declaration) -> void
339
321
  def collect_instance_variable_references(name, location, declaration)
340
322
  return unless @target.is_a?(InstanceVariableTarget) && name == @target.name
341
323
 
@@ -1,26 +1,19 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "uri"
5
+
4
6
  module URI
5
7
  class Generic
6
- extend T::Sig
7
-
8
8
  # Avoid a deprecation warning with Ruby 3.4 where the default parser was changed to RFC3986.
9
9
  # This condition must remain even after support for 3.4 has been dropped for users that have
10
10
  # `uri` in their lockfile, decoupling it from the ruby version.
11
- PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
12
11
 
13
- class << self
14
- extend T::Sig
12
+ # NOTE: We also define this in the shim
13
+ PARSER = const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER
15
14
 
16
- sig do
17
- params(
18
- path: String,
19
- fragment: T.nilable(String),
20
- scheme: String,
21
- load_path_entry: T.nilable(String),
22
- ).returns(URI::Generic)
23
- end
15
+ class << self
16
+ #: (path: String, ?fragment: String?, ?scheme: String, ?load_path_entry: String?) -> URI::Generic
24
17
  def from_path(path:, fragment: nil, scheme: "file", load_path_entry: nil)
25
18
  # On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
26
19
  escaped_path = if /^[A-Z]:/i.match?(path)
@@ -42,10 +35,10 @@ module URI
42
35
  end
43
36
  end
44
37
 
45
- sig { returns(T.nilable(String)) }
38
+ #: String?
46
39
  attr_accessor :require_path
47
40
 
48
- sig { params(load_path_entry: String).void }
41
+ #: (String load_path_entry) -> void
49
42
  def add_require_path_from_load_entry(load_path_entry)
50
43
  path = to_standardized_path
51
44
  return unless path
@@ -53,7 +46,7 @@ module URI
53
46
  self.require_path = path.delete_prefix("#{load_path_entry}/").delete_suffix(".rb")
54
47
  end
55
48
 
56
- sig { returns(T.nilable(String)) }
49
+ #: -> String?
57
50
  def to_standardized_path
58
51
  parsed_path = path
59
52
  return unless parsed_path