ruby-lsp 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-check +1 -1
  5. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +35 -5
  6. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +141 -5
  7. data/lib/ruby_indexer/lib/ruby_indexer/visitor.rb +66 -18
  8. data/lib/ruby_indexer/test/classes_and_modules_test.rb +39 -16
  9. data/lib/ruby_indexer/test/configuration_test.rb +2 -0
  10. data/lib/ruby_indexer/test/constant_test.rb +213 -11
  11. data/lib/ruby_indexer/test/index_test.rb +20 -0
  12. data/lib/ruby_lsp/{extension.rb → addon.rb} +27 -25
  13. data/lib/ruby_lsp/check_docs.rb +7 -8
  14. data/lib/ruby_lsp/document.rb +35 -38
  15. data/lib/ruby_lsp/event_emitter.rb +239 -77
  16. data/lib/ruby_lsp/executor.rb +45 -55
  17. data/lib/ruby_lsp/internal.rb +2 -3
  18. data/lib/ruby_lsp/listener.rb +8 -7
  19. data/lib/ruby_lsp/parameter_scope.rb +33 -0
  20. data/lib/ruby_lsp/requests/base_request.rb +3 -3
  21. data/lib/ruby_lsp/requests/code_action_resolve.rb +14 -14
  22. data/lib/ruby_lsp/requests/code_lens.rb +39 -63
  23. data/lib/ruby_lsp/requests/completion.rb +54 -32
  24. data/lib/ruby_lsp/requests/definition.rb +30 -27
  25. data/lib/ruby_lsp/requests/diagnostics.rb +26 -3
  26. data/lib/ruby_lsp/requests/document_highlight.rb +18 -19
  27. data/lib/ruby_lsp/requests/document_link.rb +53 -10
  28. data/lib/ruby_lsp/requests/document_symbol.rb +82 -75
  29. data/lib/ruby_lsp/requests/folding_ranges.rb +199 -222
  30. data/lib/ruby_lsp/requests/formatting.rb +5 -6
  31. data/lib/ruby_lsp/requests/hover.rb +33 -22
  32. data/lib/ruby_lsp/requests/inlay_hints.rb +2 -3
  33. data/lib/ruby_lsp/requests/selection_ranges.rb +65 -40
  34. data/lib/ruby_lsp/requests/semantic_highlighting.rb +187 -145
  35. data/lib/ruby_lsp/requests/show_syntax_tree.rb +3 -4
  36. data/lib/ruby_lsp/requests/support/annotation.rb +18 -17
  37. data/lib/ruby_lsp/requests/support/common.rb +17 -26
  38. data/lib/ruby_lsp/requests/support/dependency_detector.rb +67 -42
  39. data/lib/ruby_lsp/requests/support/highlight_target.rb +64 -45
  40. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -4
  41. data/lib/ruby_lsp/requests/support/selection_range.rb +5 -4
  42. data/lib/ruby_lsp/requests/support/sorbet.rb +2 -57
  43. data/lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb +7 -1
  44. data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -1
  45. data/lib/ruby_lsp/server.rb +6 -44
  46. data/lib/ruby_lsp/setup_bundler.rb +22 -11
  47. data/lib/ruby_lsp/utils.rb +2 -12
  48. metadata +11 -30
@@ -15,288 +15,265 @@ module RubyLsp
15
15
  # puts "Hello"
16
16
  # end # <-- folding range end
17
17
  # ```
18
- class FoldingRanges < BaseRequest
18
+ class FoldingRanges < Listener
19
19
  extend T::Sig
20
-
21
- SIMPLE_FOLDABLES = T.let(
22
- [
23
- SyntaxTree::ArrayLiteral,
24
- SyntaxTree::BlockNode,
25
- SyntaxTree::Case,
26
- SyntaxTree::ClassDeclaration,
27
- SyntaxTree::For,
28
- SyntaxTree::HashLiteral,
29
- SyntaxTree::Heredoc,
30
- SyntaxTree::ModuleDeclaration,
31
- SyntaxTree::SClass,
32
- SyntaxTree::UnlessNode,
33
- SyntaxTree::UntilNode,
34
- SyntaxTree::WhileNode,
35
- SyntaxTree::Else,
36
- SyntaxTree::Ensure,
37
- SyntaxTree::Begin,
38
- ].freeze,
39
- T::Array[T.class_of(SyntaxTree::Node)],
40
- )
41
-
42
- NODES_WITH_STATEMENTS = T.let(
43
- [
44
- SyntaxTree::IfNode,
45
- SyntaxTree::Elsif,
46
- SyntaxTree::In,
47
- SyntaxTree::Rescue,
48
- SyntaxTree::When,
49
- ].freeze,
50
- T::Array[T.class_of(SyntaxTree::Node)],
51
- )
52
-
53
- StatementNode = T.type_alias do
54
- T.any(
55
- SyntaxTree::IfNode,
56
- SyntaxTree::Elsif,
57
- SyntaxTree::In,
58
- SyntaxTree::Rescue,
59
- SyntaxTree::When,
20
+ extend T::Generic
21
+
22
+ ResponseType = type_member { { fixed: T::Array[Interface::FoldingRange] } }
23
+
24
+ sig { params(comments: T::Array[YARP::Comment], emitter: EventEmitter, queue: Thread::Queue).void }
25
+ def initialize(comments, emitter, queue)
26
+ super(emitter, queue)
27
+
28
+ @_response = T.let([], ResponseType)
29
+ @requires = T.let([], T::Array[YARP::CallNode])
30
+ @finalized_response = T.let(false, T::Boolean)
31
+ @comments = comments
32
+
33
+ emitter.register(
34
+ self,
35
+ :on_if,
36
+ :on_in,
37
+ :on_rescue,
38
+ :on_when,
39
+ :on_interpolated_string,
40
+ :on_array,
41
+ :on_block,
42
+ :on_case,
43
+ :on_class,
44
+ :on_module,
45
+ :on_for,
46
+ :on_hash,
47
+ :on_singleton_class,
48
+ :on_unless,
49
+ :on_until,
50
+ :on_while,
51
+ :on_else,
52
+ :on_ensure,
53
+ :on_begin,
54
+ :on_string_concat,
55
+ :on_def,
56
+ :on_call,
60
57
  )
61
58
  end
62
59
 
63
- sig { params(document: Document).void }
64
- def initialize(document)
65
- super
60
+ sig { override.returns(ResponseType) }
61
+ def _response
62
+ unless @finalized_response
63
+ push_comment_ranges
64
+ emit_requires_range
65
+ @finalized_response = true
66
+ end
66
67
 
67
- @ranges = T.let([], T::Array[Interface::FoldingRange])
68
- @partial_range = T.let(nil, T.nilable(PartialRange))
68
+ @_response
69
69
  end
70
70
 
71
- sig { override.returns(T.all(T::Array[Interface::FoldingRange], Object)) }
72
- def run
73
- if @document.parsed?
74
- visit(@document.tree)
75
- emit_partial_range
76
- end
71
+ sig { params(node: YARP::IfNode).void }
72
+ def on_if(node)
73
+ add_statements_range(node)
74
+ end
77
75
 
78
- @ranges
76
+ sig { params(node: YARP::InNode).void }
77
+ def on_in(node)
78
+ add_statements_range(node)
79
79
  end
80
80
 
81
- private
81
+ sig { params(node: YARP::RescueNode).void }
82
+ def on_rescue(node)
83
+ add_statements_range(node)
84
+ end
82
85
 
83
- sig { override.params(node: T.nilable(SyntaxTree::Node)).void }
84
- def visit(node)
85
- return unless handle_partial_range(node)
86
+ sig { params(node: YARP::WhenNode).void }
87
+ def on_when(node)
88
+ add_statements_range(node)
89
+ end
86
90
 
87
- case node
88
- when *SIMPLE_FOLDABLES
89
- location = T.must(node).location
90
- add_lines_range(location.start_line, location.end_line - 1)
91
- when *NODES_WITH_STATEMENTS
92
- add_statements_range(T.must(node), T.cast(node, StatementNode).statements)
93
- when SyntaxTree::CallNode, SyntaxTree::CommandCall
94
- # If there is a receiver, it may be a chained invocation,
95
- # so we need to process it in special way.
96
- if node.receiver.nil?
97
- location = node.location
98
- add_lines_range(location.start_line, location.end_line - 1)
99
- else
100
- add_call_range(node)
101
- return
102
- end
103
- when SyntaxTree::Command
104
- unless same_lines_for_command_and_block?(node)
105
- location = node.location
106
- add_lines_range(location.start_line, location.end_line - 1)
107
- end
108
- when SyntaxTree::DefNode
109
- add_def_range(node)
110
- when SyntaxTree::StringConcat
111
- add_string_concat(node)
112
- return
113
- end
91
+ sig { params(node: YARP::InterpolatedStringNode).void }
92
+ def on_interpolated_string(node)
93
+ opening_loc = node.opening_loc
94
+ closing_loc = node.closing_loc
114
95
 
115
- super
96
+ add_lines_range(opening_loc.start_line, closing_loc.end_line - 1) if opening_loc && closing_loc
116
97
  end
117
98
 
118
- # This is to prevent duplicate ranges
119
- sig { params(node: T.any(SyntaxTree::Command, SyntaxTree::CommandCall)).returns(T::Boolean) }
120
- def same_lines_for_command_and_block?(node)
121
- node_block = node.block
122
- return false unless node_block
99
+ sig { params(node: YARP::ArrayNode).void }
100
+ def on_array(node)
101
+ add_simple_range(node)
102
+ end
123
103
 
124
- location = node.location
125
- block_location = node_block.location
126
- block_location.start_line == location.start_line && block_location.end_line == location.end_line
104
+ sig { params(node: YARP::BlockNode).void }
105
+ def on_block(node)
106
+ add_simple_range(node)
127
107
  end
128
108
 
129
- class PartialRange
130
- extend T::Sig
109
+ sig { params(node: YARP::CaseNode).void }
110
+ def on_case(node)
111
+ add_simple_range(node)
112
+ end
131
113
 
132
- sig { returns(String) }
133
- attr_reader :kind
114
+ sig { params(node: YARP::ClassNode).void }
115
+ def on_class(node)
116
+ add_simple_range(node)
117
+ end
134
118
 
135
- sig { returns(Integer) }
136
- attr_reader :end_line
119
+ sig { params(node: YARP::ModuleNode).void }
120
+ def on_module(node)
121
+ add_simple_range(node)
122
+ end
137
123
 
138
- class << self
139
- extend T::Sig
124
+ sig { params(node: YARP::ForNode).void }
125
+ def on_for(node)
126
+ add_simple_range(node)
127
+ end
140
128
 
141
- sig { params(node: SyntaxTree::Node, kind: String).returns(PartialRange) }
142
- def from(node, kind)
143
- new(node.location.start_line - 1, node.location.end_line - 1, kind)
144
- end
145
- end
129
+ sig { params(node: YARP::HashNode).void }
130
+ def on_hash(node)
131
+ add_simple_range(node)
132
+ end
146
133
 
147
- sig { params(start_line: Integer, end_line: Integer, kind: String).void }
148
- def initialize(start_line, end_line, kind)
149
- @start_line = start_line
150
- @end_line = end_line
151
- @kind = kind
152
- end
134
+ sig { params(node: YARP::SingletonClassNode).void }
135
+ def on_singleton_class(node)
136
+ add_simple_range(node)
137
+ end
153
138
 
154
- sig { params(node: SyntaxTree::Node).returns(PartialRange) }
155
- def extend_to(node)
156
- @end_line = node.location.end_line - 1
157
- self
158
- end
139
+ sig { params(node: YARP::UnlessNode).void }
140
+ def on_unless(node)
141
+ add_simple_range(node)
142
+ end
159
143
 
160
- sig { params(node: SyntaxTree::Node).returns(T::Boolean) }
161
- def new_section?(node)
162
- node.is_a?(SyntaxTree::Comment) && @end_line + 1 != node.location.start_line - 1
163
- end
144
+ sig { params(node: YARP::UntilNode).void }
145
+ def on_until(node)
146
+ add_simple_range(node)
147
+ end
164
148
 
165
- sig { returns(Interface::FoldingRange) }
166
- def to_range
167
- Interface::FoldingRange.new(
168
- start_line: @start_line,
169
- end_line: @end_line,
170
- kind: @kind,
171
- )
172
- end
149
+ sig { params(node: YARP::WhileNode).void }
150
+ def on_while(node)
151
+ add_simple_range(node)
152
+ end
173
153
 
174
- sig { returns(T::Boolean) }
175
- def multiline?
176
- @end_line > @start_line
177
- end
154
+ sig { params(node: YARP::ElseNode).void }
155
+ def on_else(node)
156
+ add_simple_range(node)
178
157
  end
179
158
 
180
- sig { params(node: T.nilable(SyntaxTree::Node)).returns(T::Boolean) }
181
- def handle_partial_range(node)
182
- kind = partial_range_kind(node)
159
+ sig { params(node: YARP::EnsureNode).void }
160
+ def on_ensure(node)
161
+ add_simple_range(node)
162
+ end
183
163
 
184
- if kind.nil?
185
- emit_partial_range
186
- return true
187
- end
164
+ sig { params(node: YARP::BeginNode).void }
165
+ def on_begin(node)
166
+ add_simple_range(node)
167
+ end
188
168
 
189
- target_node = T.must(node)
190
- @partial_range = if @partial_range.nil?
191
- PartialRange.from(target_node, kind)
192
- elsif @partial_range.kind != kind || @partial_range.new_section?(target_node)
193
- emit_partial_range
194
- PartialRange.from(target_node, kind)
195
- else
196
- @partial_range.extend_to(target_node)
197
- end
169
+ sig { params(node: YARP::Node).void }
170
+ def on_node(node)
171
+ emit_requires_range unless node.is_a?(YARP::CallNode)
172
+ end
198
173
 
199
- false
174
+ sig { params(node: YARP::StringConcatNode).void }
175
+ def on_string_concat(node)
176
+ left = T.let(node.left, YARP::Node)
177
+ left = left.left while left.is_a?(YARP::StringConcatNode)
178
+
179
+ add_lines_range(left.location.start_line, node.right.location.end_line - 1)
200
180
  end
201
181
 
202
- sig { params(node: T.nilable(SyntaxTree::Node)).returns(T.nilable(String)) }
203
- def partial_range_kind(node)
204
- case node
205
- when SyntaxTree::Comment
206
- "comment"
207
- when SyntaxTree::Command
208
- if node.message.value == "require" || node.message.value == "require_relative"
209
- "imports"
210
- end
182
+ sig { params(node: YARP::DefNode).void }
183
+ def on_def(node)
184
+ params = node.parameters
185
+ parameter_loc = params&.location
186
+ location = node.location
187
+
188
+ if params && parameter_loc.end_line > location.start_line
189
+ # Multiline parameters
190
+ add_lines_range(location.start_line, parameter_loc.end_line)
191
+ add_lines_range(parameter_loc.end_line + 1, location.end_line - 1)
192
+ else
193
+ add_lines_range(location.start_line, location.end_line - 1)
211
194
  end
212
195
  end
213
196
 
214
- sig { void }
215
- def emit_partial_range
216
- return if @partial_range.nil?
197
+ sig { params(node: YARP::CallNode).void }
198
+ def on_call(node)
199
+ # If we find a require, don't visit the child nodes (prevent `super`), so that we can keep accumulating into
200
+ # the `@requires` array and then push the range whenever we find a node that isn't a CallNode
201
+ if require?(node)
202
+ @requires << node
203
+ return
204
+ end
217
205
 
218
- @ranges << @partial_range.to_range if @partial_range.multiline?
219
- @partial_range = nil
206
+ location = node.location
207
+ add_lines_range(location.start_line, location.end_line - 1)
220
208
  end
221
209
 
222
- sig { params(node: T.any(SyntaxTree::CallNode, SyntaxTree::CommandCall)).void }
223
- def add_call_range(node)
224
- receiver = T.let(node.receiver, T.nilable(SyntaxTree::Node))
225
-
226
- loop do
227
- case receiver
228
- when SyntaxTree::CallNode
229
- visit(receiver.arguments)
230
- receiver = receiver.receiver
231
- when SyntaxTree::MethodAddBlock
232
- visit(receiver.block)
233
- receiver = receiver.call
234
-
235
- if receiver.is_a?(SyntaxTree::CallNode) || receiver.is_a?(SyntaxTree::CommandCall)
236
- receiver = receiver.receiver
237
- end
238
- else
239
- break
240
- end
210
+ private
211
+
212
+ sig { void }
213
+ def push_comment_ranges
214
+ # Group comments that are on consecutive lines and then push ranges for each group that has at least 2 comments
215
+ @comments.chunk_while do |this, other|
216
+ this.location.end_line + 1 == other.location.start_line
217
+ end.each do |chunk|
218
+ next if chunk.length == 1
219
+
220
+ @_response << Interface::FoldingRange.new(
221
+ start_line: T.must(chunk.first).location.start_line - 1,
222
+ end_line: T.must(chunk.last).location.end_line - 1,
223
+ kind: "comment",
224
+ )
241
225
  end
226
+ end
242
227
 
243
- if receiver
244
- unless node.is_a?(SyntaxTree::CommandCall) && same_lines_for_command_and_block?(node)
245
- add_lines_range(
246
- receiver.location.start_line,
247
- node.location.end_line - 1,
248
- )
249
- end
228
+ sig { void }
229
+ def emit_requires_range
230
+ if @requires.length > 1
231
+ @_response << Interface::FoldingRange.new(
232
+ start_line: T.must(@requires.first).location.start_line - 1,
233
+ end_line: T.must(@requires.last).location.end_line - 1,
234
+ kind: "imports",
235
+ )
250
236
  end
251
237
 
252
- visit(node.arguments)
253
- visit(node.block) if node.is_a?(SyntaxTree::CommandCall)
238
+ @requires.clear
254
239
  end
255
240
 
256
- sig { params(node: SyntaxTree::DefNode).void }
257
- def add_def_range(node)
258
- # For an endless method with no arguments, `node.params` returns `nil` for Ruby 3.0, but a `Syntax::Params`
259
- # for Ruby 3.1
260
- params = node.params
261
- return unless params
241
+ sig { params(node: YARP::CallNode).returns(T::Boolean) }
242
+ def require?(node)
243
+ message = node.message
244
+ return false unless message == "require" || message == "require_relative"
262
245
 
263
- params_location = params.location
246
+ receiver = node.receiver
247
+ return false unless receiver.nil? || receiver.slice == "Kernel"
264
248
 
265
- if params_location.start_line < params_location.end_line
266
- add_lines_range(params_location.end_line, node.location.end_line - 1)
267
- else
268
- location = node.location
269
- add_lines_range(location.start_line, location.end_line - 1)
270
- end
249
+ arguments = node.arguments&.arguments
250
+ return false unless arguments
271
251
 
272
- bodystmt = node.bodystmt
273
- if bodystmt.is_a?(SyntaxTree::BodyStmt)
274
- visit(bodystmt.statements)
275
- else
276
- visit(bodystmt)
277
- end
252
+ arguments.length == 1 && arguments.first.is_a?(YARP::StringNode)
278
253
  end
279
254
 
280
- sig { params(node: SyntaxTree::Node, statements: SyntaxTree::Statements).void }
281
- def add_statements_range(node, statements)
282
- return if statements.empty?
255
+ sig { params(node: T.any(YARP::IfNode, YARP::InNode, YARP::RescueNode, YARP::WhenNode)).void }
256
+ def add_statements_range(node)
257
+ statements = node.statements
258
+ return unless statements
283
259
 
284
- add_lines_range(node.location.start_line, T.must(statements.body.last).location.end_line)
285
- end
260
+ body = statements.body
261
+ return if body.empty?
286
262
 
287
- sig { params(node: SyntaxTree::StringConcat).void }
288
- def add_string_concat(node)
289
- left = T.let(node.left, SyntaxTree::Node)
290
- left = left.left while left.is_a?(SyntaxTree::StringConcat)
263
+ add_lines_range(node.location.start_line, T.must(body.last).location.end_line)
264
+ end
291
265
 
292
- add_lines_range(left.location.start_line, node.right.location.end_line - 1)
266
+ sig { params(node: YARP::Node).void }
267
+ def add_simple_range(node)
268
+ location = node.location
269
+ add_lines_range(location.start_line, location.end_line - 1)
293
270
  end
294
271
 
295
272
  sig { params(start_line: Integer, end_line: Integer).void }
296
273
  def add_lines_range(start_line, end_line)
297
274
  return if start_line >= end_line
298
275
 
299
- @ranges << Interface::FoldingRange.new(
276
+ @_response << Interface::FoldingRange.new(
300
277
  start_line: start_line - 1,
301
278
  end_line: end_line - 1,
302
279
  kind: "region",
@@ -29,12 +29,7 @@ module RubyLsp
29
29
  class Error < StandardError; end
30
30
  class InvalidFormatter < StandardError; end
31
31
 
32
- @formatters = T.let(
33
- {
34
- "syntax_tree" => Support::SyntaxTreeFormattingRunner.instance,
35
- },
36
- T::Hash[String, Support::FormatterRunner],
37
- )
32
+ @formatters = T.let({}, T::Hash[String, Support::FormatterRunner])
38
33
 
39
34
  class << self
40
35
  extend T::Sig
@@ -52,6 +47,10 @@ module RubyLsp
52
47
  register_formatter("rubocop", Support::RuboCopFormattingRunner.instance)
53
48
  end
54
49
 
50
+ if defined?(Support::SyntaxTreeFormattingRunner)
51
+ register_formatter("syntax_tree", Support::SyntaxTreeFormattingRunner.instance)
52
+ end
53
+
55
54
  extend T::Sig
56
55
 
57
56
  sig { params(document: Document, formatter: String).void }
@@ -21,12 +21,12 @@ module RubyLsp
21
21
 
22
22
  ALLOWED_TARGETS = T.let(
23
23
  [
24
- SyntaxTree::Const,
25
- SyntaxTree::Command,
26
- SyntaxTree::CallNode,
27
- SyntaxTree::ConstPathRef,
24
+ YARP::CallNode,
25
+ YARP::ConstantReadNode,
26
+ YARP::ConstantWriteNode,
27
+ YARP::ConstantPathNode,
28
28
  ],
29
- T::Array[T.class_of(SyntaxTree::Node)],
29
+ T::Array[T.class_of(YARP::Node)],
30
30
  )
31
31
 
32
32
  sig { override.returns(ResponseType) }
@@ -41,17 +41,17 @@ module RubyLsp
41
41
  ).void
42
42
  end
43
43
  def initialize(index, nesting, emitter, message_queue)
44
- @nesting = nesting
45
44
  @index = index
45
+ @nesting = nesting
46
46
  @_response = T.let(nil, ResponseType)
47
47
 
48
48
  super(emitter, message_queue)
49
- emitter.register(self, :on_const_path_ref, :on_const)
49
+ emitter.register(self, :on_constant_read, :on_constant_write, :on_constant_path)
50
50
  end
51
51
 
52
- sig { override.params(extension: RubyLsp::Extension).returns(T.nilable(Listener[ResponseType])) }
53
- def initialize_external_listener(extension)
54
- extension.create_hover_listener(@emitter, @message_queue)
52
+ sig { override.params(addon: Addon).returns(T.nilable(Listener[ResponseType])) }
53
+ def initialize_external_listener(addon)
54
+ addon.create_hover_listener(@nesting, @index, @emitter, @message_queue)
55
55
  end
56
56
 
57
57
  # Merges responses from other hover listeners
@@ -69,30 +69,41 @@ module RubyLsp
69
69
  self
70
70
  end
71
71
 
72
- sig { params(node: SyntaxTree::ConstPathRef).void }
73
- def on_const_path_ref(node)
74
- return if DependencyDetector::HAS_TYPECHECKER
72
+ sig { params(node: YARP::ConstantReadNode).void }
73
+ def on_constant_read(node)
74
+ return if DependencyDetector.instance.typechecker
75
+
76
+ generate_hover(node.slice, node.location)
77
+ end
78
+
79
+ sig { params(node: YARP::ConstantWriteNode).void }
80
+ def on_constant_write(node)
81
+ return if DependencyDetector.instance.typechecker
75
82
 
76
- name = full_constant_name(node)
77
- generate_hover(name, node)
83
+ generate_hover(node.name.to_s, node.name_loc)
78
84
  end
79
85
 
80
- sig { params(node: SyntaxTree::Const).void }
81
- def on_const(node)
82
- return if DependencyDetector::HAS_TYPECHECKER
86
+ sig { params(node: YARP::ConstantPathNode).void }
87
+ def on_constant_path(node)
88
+ return if DependencyDetector.instance.typechecker
83
89
 
84
- generate_hover(node.value, node)
90
+ generate_hover(node.slice, node.location)
85
91
  end
86
92
 
87
93
  private
88
94
 
89
- sig { params(name: String, node: SyntaxTree::Node).void }
90
- def generate_hover(name, node)
95
+ sig { params(name: String, location: YARP::Location).void }
96
+ def generate_hover(name, location)
91
97
  entries = @index.resolve(name, @nesting)
92
98
  return unless entries
93
99
 
100
+ # We should only show hover for private constants if the constant is defined in the same namespace as the
101
+ # reference
102
+ first_entry = T.must(entries.first)
103
+ return if first_entry.visibility == :private && first_entry.name != "#{@nesting.join("::")}::#{name}"
104
+
94
105
  @_response = Interface::Hover.new(
95
- range: range_from_syntax_tree_node(node),
106
+ range: range_from_location(location),
96
107
  contents: markdown_from_index_entries(name, entries),
97
108
  )
98
109
  end
@@ -39,10 +39,9 @@ module RubyLsp
39
39
  emitter.register(self, :on_rescue)
40
40
  end
41
41
 
42
- sig { params(node: SyntaxTree::Rescue).void }
42
+ sig { params(node: YARP::RescueNode).void }
43
43
  def on_rescue(node)
44
- exception = node.exception
45
- return unless exception.nil? || exception.exceptions.nil?
44
+ return unless node.exceptions.empty?
46
45
 
47
46
  loc = node.location
48
47
  return unless visible?(node, @range)