Class: RubyLsp::Requests::SelectionRanges
- Includes:
- RubyLsp::Requests::Support::Common
- 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 + <-
Note that if using VSCode Neovim, you will need to be in Insert mode for this to work correctly.
Instance Method Summary collapse
-
#initialize(document) ⇒ SelectionRanges
constructor
: ((RubyDocument | ERBDocument) document) -> void.
-
#perform ⇒ Object
: -> (Array & Object).
Methods included from RubyLsp::Requests::Support::Common
#categorized_markdown_from_index_entries, #constant_name, #create_code_lens, #each_constant_path_part, #kind_for_entry, #markdown_from_index_entries, #namespace_constant_name, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?
Constructor Details
#initialize(document) ⇒ SelectionRanges
: ((RubyDocument | ERBDocument) document) -> void
17 18 19 20 21 22 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 17 def initialize(document) super() @document = document @ranges = [] #: Array[Support::SelectionRange] @stack = [] #: Array[Support::SelectionRange] end |
Instance Method Details
#perform ⇒ Object
: -> (Array & Object)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_lsp/requests/selection_ranges.rb', line 26 def perform # [node, parent] queue = [[@document.ast, nil]] until queue.empty? node, parent = queue.shift next unless node range = Support::SelectionRange.new(range: range_from_location(node.location), parent: parent) queue.unshift(*node.child_nodes.map { |child| [child, range] }) @ranges.unshift(range) end @ranges end |