Class: RubyLsp::Listeners::Hover
Constant Summary
collapse
- ResponseType =
type_member { { fixed: T.nilable(Interface::Hover) } }
- ALLOWED_TARGETS =
T.let(
[
Prism::CallNode,
Prism::ConstantReadNode,
Prism::ConstantWriteNode,
Prism::ConstantPathNode,
],
T::Array[T.class_of(Prism::Node)],
)
Instance Attribute Summary collapse
Instance Method Summary
collapse
#response
#create_code_lens, #markdown_from_index_entries, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?, #visible?
Constructor Details
#initialize(uri, nesting, index, dispatcher, typechecker_enabled) ⇒ Hover
Returns a new instance of Hover.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 34
def initialize(uri, nesting, index, dispatcher, typechecker_enabled)
@path = T.let(uri.to_standardized_path, T.nilable(String))
@nesting = nesting
@index = index
@typechecker_enabled = typechecker_enabled
@_response = T.let(nil, ResponseType)
super(dispatcher)
dispatcher.register(
self,
:on_constant_read_node_enter,
:on_constant_write_node_enter,
:on_constant_path_node_enter,
:on_call_node_enter,
)
end
|
Instance Attribute Details
#_response ⇒ Object
Returns the value of attribute _response.
23
24
25
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 23
def _response
@_response
end
|
Instance Method Details
#on_call_node_enter(node) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 73
def on_call_node_enter(node)
return unless self_receiver?(node)
if @path && File.basename(@path) == GEMFILE_NAME && node.name == :gem
generate_gem_hover(node)
return
end
return if @typechecker_enabled
message = node.message
return unless message
target_method = @index.resolve_method(message, @nesting.join("::"))
return unless target_method
location = target_method.location
@_response = Interface::Hover.new(
range: range_from_location(location),
contents: markdown_from_index_entries(message, target_method),
)
end
|
#on_constant_path_node_enter(node) ⇒ Object
66
67
68
69
70
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 66
def on_constant_path_node_enter(node)
return if DependencyDetector.instance.typechecker
generate_hover(node.slice, node.location)
end
|
#on_constant_read_node_enter(node) ⇒ Object
52
53
54
55
56
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 52
def on_constant_read_node_enter(node)
return if @typechecker_enabled
generate_hover(node.slice, node.location)
end
|
#on_constant_write_node_enter(node) ⇒ Object
59
60
61
62
63
|
# File 'lib/ruby_lsp/listeners/hover.rb', line 59
def on_constant_write_node_enter(node)
return if DependencyDetector.instance.typechecker
generate_hover(node.name.to_s, node.name_loc)
end
|