Sha256: 5a36c4f6fb254217c8b06c3bcc0acaf20493dcd2c749150565955adb6e8deddd

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module Requests
    # The
    # [prepare_rename](https://microsoft.github.io/language-server-protocol/specification#textDocument_prepareRename)
    # # request checks the validity of a rename operation at a given location.
    class PrepareRename < Request
      extend T::Sig
      include Support::Common

      sig do
        params(
          document: RubyDocument,
          position: T::Hash[Symbol, T.untyped],
        ).void
      end
      def initialize(document, position)
        super()
        @document = document
        @position = T.let(position, T::Hash[Symbol, Integer])
      end

      sig { override.returns(T.nilable(Interface::Range)) }
      def perform
        char_position, _ = @document.find_index_by_position(@position)

        node_context = RubyDocument.locate(
          @document.parse_result.value,
          char_position,
          node_types: [Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode],
          code_units_cache: @document.code_units_cache,
        )
        target = node_context.node
        parent = node_context.parent
        return if !target || target.is_a?(Prism::ProgramNode)

        if target.is_a?(Prism::ConstantReadNode) && parent.is_a?(Prism::ConstantPathNode)
          target = determine_target(
            target,
            parent,
            @position,
          )
        end

        range_from_location(target.location)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-lsp-0.23.6 lib/ruby_lsp/requests/prepare_rename.rb
ruby-lsp-0.23.5 lib/ruby_lsp/requests/prepare_rename.rb
ruby-lsp-0.23.4 lib/ruby_lsp/requests/prepare_rename.rb
ruby-lsp-0.23.3 lib/ruby_lsp/requests/prepare_rename.rb
ruby-lsp-0.23.2 lib/ruby_lsp/requests/prepare_rename.rb