Skip to content

Commit

Permalink
Migrate inlay hints to yarp (#871)
Browse files Browse the repository at this point in the history
* Migrate inlay hint

* Changes for YARP

---------

Co-authored-by: Vinicius Stock <[email protected]>
Co-authored-by: Andy Waite <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2023
1 parent ab53375 commit 4f4ff35
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/ruby_lsp/event_emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def emit_for_target(node)

# Visit dispatchers are below. Notice that for nodes that create a new scope (e.g.: classes, modules, method defs)
# we need both an `on_*` and `after_*` event. This is because some requests must know when we exit the scope
sig { override.params(node: T.nilable(SyntaxTree::Node)).void }
sig { override.params(node: T.nilable(YARP::Node)).void }
def visit(node)
@listeners[:on_node]&.each { |l| T.unsafe(l).on_node(node) }
super
Expand Down Expand Up @@ -125,8 +125,8 @@ def visit_comment(node)
super
end

sig { override.params(node: SyntaxTree::Rescue).void }
def visit_rescue(node)
sig { override.params(node: YARP::RescueNode).void }
def visit_rescue_node(node)
@listeners[:on_rescue]&.each { |l| T.unsafe(l).on_rescue(node) }
super
end
Expand Down
1 change: 0 additions & 1 deletion lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ def document_highlight(uri, position)
sig { params(uri: URI::Generic, range: Document::RangeShape).returns(T.nilable(T::Array[Interface::InlayHint])) }
def inlay_hint(uri, range)
document = @store.get(uri)
return if document.syntax_error?

start_line = range.dig(:start, :line)
end_line = range.dig(:end, :line)
Expand Down
5 changes: 2 additions & 3 deletions lib/ruby_lsp/requests/inlay_hints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def initialize(range, emitter, message_queue)
emitter.register(self, :on_rescue)
end

sig { params(node: SyntaxTree::Rescue).void }
sig { params(node: YARP::RescueNode).void }
def on_rescue(node)
exception = node.exception
return unless exception.nil? || exception.exceptions.nil?
return unless node.exceptions.empty?

loc = node.location
return unless visible?(node, @range)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/requests/support/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def full_constant_name(node)
name
end

sig { params(node: T.nilable(SyntaxTree::Node), range: T.nilable(T::Range[Integer])).returns(T::Boolean) }
sig { params(node: T.nilable(YARP::Node), range: T.nilable(T::Range[Integer])).returns(T::Boolean) }
def visible?(node, range)
return true if range.nil?
return false if node.nil?
Expand Down
5 changes: 5 additions & 0 deletions sorbet/rbi/shims/yarp.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ module YARP
sig { returns(ConstantPathNode) }
def constant_path; end
end

class RescueNode
sig { returns(T::Array[YARP::Node]) }
def exceptions; end
end
end

0 comments on commit 4f4ff35

Please sign in to comment.