Sha256: ad721194660134f190c0d69a4eac115a4ce29d841a723caf65376dafa551790c
Contents?: true
Size: 1.65 KB
Versions: 9
Compression:
Stored size: 1.65 KB
Contents
# typed: strict # frozen_string_literal: true module RubyLsp module Requests # ![Selection ranges demo](../../selection_ranges.gif) # # The [selection ranges](https://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. # # # Example # # ```ruby # def foo # --> The next selection range encompasses the entire method definition. # puts "Hello, world!" # --> Cursor is on this line # end # ``` class SelectionRanges < Request extend T::Sig include Support::Common sig { params(document: Document).void } def initialize(document) super() @document = document @ranges = T.let([], T::Array[Support::SelectionRange]) @stack = T.let([], T::Array[Support::SelectionRange]) end sig { override.returns(T.all(T::Array[Support::SelectionRange], Object)) } def perform # [node, parent] queue = [[@document.parse_result.value, nil]] until queue.empty? node, parent = queue.shift next unless node range = Support::SelectionRange.new(range: range_from_location(node.location), parent: parent) T.unsafe(queue).unshift(*node.child_nodes.map { |child| [child, range] }) @ranges.unshift(range) end @ranges end end end end
Version data entries
9 entries across 9 versions & 1 rubygems