Class: RubyLsp::Requests::SelectionRanges
- Inherits:
-
BaseRequest
- Object
- SyntaxTree::Visitor
- BaseRequest
- RubyLsp::Requests::SelectionRanges
- Defined in:
- lib/ruby_lsp/requests/selection_ranges.rb
Overview
The [selection ranges](microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange) request informs the editor of ranges that the user may want to select based on the location(s) of their cursor(s).
Trigger this request with: Ctrl + Shift + -> or Ctrl + Shift + <-
# Example
“‘ruby def foo # –> The next selection range encompasses the entire method definition.
puts "Hello, world!" # --> Cursor is on this line
end “‘
Constant Summary collapse
- NODES_THAT_CAN_BE_PARENTS =
[ SyntaxTree::Assign, SyntaxTree::ArrayLiteral, SyntaxTree::Begin, SyntaxTree::BraceBlock, SyntaxTree::Call, SyntaxTree::Case, SyntaxTree::ClassDeclaration, SyntaxTree::Command, SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::DoBlock, SyntaxTree::Elsif, SyntaxTree::Else, SyntaxTree::EmbDoc, SyntaxTree::Ensure, SyntaxTree::FCall, SyntaxTree::For, SyntaxTree::HashLiteral, SyntaxTree::Heredoc, SyntaxTree::HeredocBeg, SyntaxTree::HshPtn, SyntaxTree::If, SyntaxTree::In, SyntaxTree::Lambda, SyntaxTree::MethodAddBlock, SyntaxTree::ModuleDeclaration, SyntaxTree::Params, SyntaxTree::Rescue, SyntaxTree::RescueEx, SyntaxTree::StringConcat, SyntaxTree::StringLiteral, SyntaxTree::Unless, SyntaxTree::Until, SyntaxTree::VCall, SyntaxTree::When, SyntaxTree::While, ].freeze
Instance Method Summary collapse
-
#initialize(document) ⇒ SelectionRanges
constructor
A new instance of SelectionRanges.
- #run ⇒ Object
Methods inherited from BaseRequest
#range_from_syntax_tree_node, run
Constructor Details
#initialize(document) ⇒ SelectionRanges
Returns a new instance of SelectionRanges.
59 60 61 62 63 64 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 59 def initialize(document) super(document) @ranges = [] @stack = [] end |
Instance Method Details
#run ⇒ Object
66 67 68 69 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 66 def run visit(@document.tree) @ranges.reverse! end |