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
CodeActions, Diagnostics, DocumentHighlight, DocumentLink, DocumentSymbol, FoldingRanges, Formatting, Hover, InlayHints, OnTypeFormatting, SelectionRanges, SemanticHighlighting
Instance Method Summary
collapse
Constructor Details
#initialize(document) ⇒ BaseRequest
Returns a new instance of BaseRequest.
14
15
16
17
18
19
20
21
22
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 14
def initialize(document)
@document = document
@document.parse
super()
end
|
Instance Method Details
#full_constant_name(node) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 39
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_and_parent(parent, target_nodes, position) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 64
def locate_node_and_parent(parent, target_nodes, position)
matched = parent.child_nodes.compact.bsearch do |child|
if (child.location.start_char...child.location.end_char).cover?(position)
0
else
position <=> child.location.start_char
end
end
case matched
when *target_nodes
[matched, parent]
when SyntaxTree::Node
locate_node_and_parent(matched, target_nodes, position)
else
[]
end
end
|
#range_from_syntax_tree_node(node) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 28
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
25
|
# File 'lib/ruby_lsp/requests/base_request.rb', line 25
def run; end
|