Sha256: a74c0000bc5d973d79891ecc9449bd042db9a31aa0a98e07a548a9ee860ad574

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module RSpec
    class Definition
      extend T::Sig

      include ::RubyLsp::Requests::Support::Common

      sig do
        params(
          response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
            Interface::Location,
            Interface::LocationLink,
          )],
          uri: URI::Generic,
          node_context: NodeContext,
          index: RubyIndexer::Index,
          dispatcher: Prism::Dispatcher,
        ).void
      end
      def initialize(response_builder, uri, node_context, index, dispatcher)
        @response_builder = response_builder
        @uri = uri
        @node_context = node_context
        @index = index
        dispatcher.register(self, :on_call_node_enter)
      end

      sig { params(node: Prism::CallNode).void }
      def on_call_node_enter(node)
        message = node.message
        return unless message

        return if @node_context.locals_for_scope.include?(message)

        entries = @index[message]
        return unless entries
        return if entries.empty?

        entries.each do |entry|
          # Technically, let can be defined in a different file, but we're not going to handle that case yet
          next unless entry.file_path == @uri.to_standardized_path

          @response_builder << Interface::LocationLink.new(
            target_uri: URI::Generic.from_path(path: entry.file_path).to_s,
            target_range: range_from_location(entry.location),
            target_selection_range: range_from_location(entry.name_location),
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-lsp-rspec-0.1.19 lib/ruby_lsp/ruby_lsp_rspec/definition.rb
ruby-lsp-rspec-0.1.18 lib/ruby_lsp/ruby_lsp_rspec/definition.rb
ruby-lsp-rspec-0.1.17 lib/ruby_lsp/ruby_lsp_rspec/definition.rb
ruby-lsp-rspec-0.1.16 lib/ruby_lsp/ruby_lsp_rspec/definition.rb
ruby-lsp-rspec-0.1.15 lib/ruby_lsp/ruby_lsp_rspec/definition.rb