Class: RubyLsp::Requests::BaseRequest
- Inherits:
-
SyntaxTree::Visitor
- Object
- SyntaxTree::Visitor
- RubyLsp::Requests::BaseRequest
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/ruby_lsp/requests/base_request.rb
Overview
Direct Known Subclasses
CodeActionResolve, CodeActions, Diagnostics, DocumentHighlight, DocumentLink, DocumentSymbol, FoldingRanges, Formatting, Hover, InlayHints, OnTypeFormatting, PathCompletion, SelectionRanges, SemanticHighlighting
Instance Method Summary
collapse
Constructor Details
#initialize(document, **_kwargs) ⇒ BaseRequest
Returns a new instance of BaseRequest.
18
19
20
21
22
23
24
25
26
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 18
def initialize(document, **_kwargs)
@document = document
@document.parse
super()
end
|
Instance Method Details
#full_constant_name(node) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 55
def full_constant_name(node)
name = +node.constant.value
constant = T.let(node, SyntaxTree::Node)
while constant.is_a?(SyntaxTree::ConstPathRef)
constant = constant.parent
case constant
when SyntaxTree::ConstPathRef
name.prepend("#{constant.constant.value}::")
when SyntaxTree::VarRef
name.prepend("#{constant.value.value}::")
end
end
name
end
|
#locate(node, position, node_types: []) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 80
def locate(node, position, node_types: [])
queue = T.let(node.child_nodes.compact, T::Array[T.nilable(SyntaxTree::Node)])
closest = node
until queue.empty?
candidate = queue.shift
next if candidate.nil?
queue.concat(candidate.child_nodes)
loc = candidate.location
next unless (loc.start_char...loc.end_char).cover?(position)
break if position < loc.start_char
next if node_types.any? && node_types.none? { |type| candidate.is_a?(type) }
closest_loc = closest.location
if loc.end_char - loc.start_char <= closest_loc.end_char - closest_loc.start_char
parent = T.let(closest, SyntaxTree::Node)
closest = candidate
end
end
[closest, parent]
end
|
#range_from_syntax_tree_node(node) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 40
def range_from_syntax_tree_node(node)
loc = node.location
LanguageServer::Protocol::Interface::Range.new(
start: LanguageServer::Protocol::Interface::Position.new(
line: loc.start_line - 1,
character: loc.start_column,
),
end: LanguageServer::Protocol::Interface::Position.new(line: loc.end_line - 1, character: loc.end_column),
)
end
|
#run ⇒ Object
29
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 29
def run; end
|
#visible?(node, range) ⇒ Boolean
115
116
117
118
119
120
121
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 115
def visible?(node, range)
return true if range.nil?
return false if node.nil?
loc = node.location
range.cover?(loc.start_line - 1) && range.cover?(loc.end_line - 1)
end
|
#visit_all(nodes) ⇒ Object
35
36
37
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 35
def visit_all(nodes)
nodes.each { |node| visit(node) }
end
|