Class: RubyLsp::Requests::SelectionRanges
- Inherits:
-
BaseRequest
- Object
- SyntaxTree::Visitor
- BaseRequest
- RubyLsp::Requests::SelectionRanges
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/requests/selection_ranges.rb
Overview
![Selection ranges demo](../../misc/selection_ranges.gif)
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 =
T.let([ 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, T::Array[T.class_of(SyntaxTree::Node)])
Instance Method Summary collapse
-
#initialize(document) ⇒ SelectionRanges
constructor
A new instance of SelectionRanges.
- #run ⇒ Object
Methods inherited from BaseRequest
Constructor Details
#initialize(document) ⇒ SelectionRanges
Returns a new instance of SelectionRanges.
64 65 66 67 68 69 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 64 def initialize(document) super(document) @ranges = T.let([], T::Array[Support::SelectionRange]) @stack = T.let([], T::Array[Support::SelectionRange]) end |
Instance Method Details
#run ⇒ Object
72 73 74 75 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 72 def run visit(@document.tree) @ranges.reverse! end |