Class: RubyLsp::Requests::Hover
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/ruby_lsp/requests/hover.rb
Overview

The [hover request](microsoft.github.io/language-server-protocol/specification#textDocument_hover) renders a clickable link to the code’s official documentation. It currently only supports Rails’ documentation: when hovering over Rails DSLs/constants under certain paths, like ‘before_save :callback` in `models/post.rb`, it generates a link to `before_save`’s API documentation.
# Example
“‘ruby class Post < ApplicationRecord
before_save :do_something # when hovering on before_save, the link will be rendered
end “‘
Constant Summary collapse
- ResponseType =
type_member { { fixed: T.nilable(Interface::Hover) } }
- ALLOWED_TARGETS =
T.let( [ SyntaxTree::Command, SyntaxTree::CallNode, SyntaxTree::ConstPathRef, ], T::Array[T.class_of(SyntaxTree::Node)], )
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(emitter, message_queue) ⇒ Hover
constructor
A new instance of Hover.
- #merge_response!(other) ⇒ Object
- #on_call(node) ⇒ Object
- #on_command(node) ⇒ Object
- #on_const_path_ref(node) ⇒ Object
Methods inherited from Listener
Methods included from Support::Common
#create_code_lens, #full_constant_name, #range_from_syntax_tree_node, #visible?
Constructor Details
#initialize(emitter, message_queue) ⇒ Hover
Returns a new instance of Hover.
39 40 41 42 43 44 |
# File 'lib/ruby_lsp/requests/hover.rb', line 39 def initialize(emitter, ) super @response = T.let(nil, ResponseType) emitter.register(self, :on_command, :on_const_path_ref, :on_call) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
36 37 38 |
# File 'lib/ruby_lsp/requests/hover.rb', line 36 def response @response end |
Instance Method Details
#merge_response!(other) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_lsp/requests/hover.rb', line 48 def merge_response!(other) other_response = other.response return self unless other_response if @response.nil? @response = other.response else @response.contents.value << other_response.contents.value << "\n\n" end self end |
#on_call(node) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/ruby_lsp/requests/hover.rb', line 73 def on_call(node) = node. return if .is_a?(Symbol) @response = generate_rails_document_link_hover(.value, ) end |
#on_command(node) ⇒ Object
62 63 64 65 |
# File 'lib/ruby_lsp/requests/hover.rb', line 62 def on_command(node) = node. @response = generate_rails_document_link_hover(.value, ) end |
#on_const_path_ref(node) ⇒ Object
68 69 70 |
# File 'lib/ruby_lsp/requests/hover.rb', line 68 def on_const_path_ref(node) @response = generate_rails_document_link_hover(full_constant_name(node), node) end |