Sha256: 2c40cc87af6cbf6a4b78e0953f21cfc3127093ed4ddbdd201488a04b6388abc4

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module Yoda
  class Server
    module Providers
      class Definition < Base
        def self.provider_method
          :'textDocument/definition'
        end

        def provide(params)
          calculate(params[:text_document][:uri], params[:position])
        end

        def timeout
          10
        end

        private

        # @param uri      [String]
        # @param position [{Symbol => Integer}]
        # @param include_declaration [Boolean]
        def calculate(uri, position, include_declaration = false)
          source = session.file_store.get(uri)
          location = Parsing::Location.of_language_server_protocol_position(line: position[:line], character: position[:character])

          node_worker = Evaluation::CurrentNodeExplain.new(session.registry, source, location)
          references = node_worker.defined_files
          references.map { |(path, line, column)| create_location(path, line, column) }
        end

        # @param path [String]
        # @param line [Integer]
        # @param column [Integer]
        def create_location(path, line, column)
          location = Parsing::Location.new(row: line - 1, column: column)
          LanguageServer::Protocol::Interface::Location.new(
            uri: session.uri_of_path(path),
            range: LanguageServer::Protocol::Interface::Range.new(Parsing::Range.new(location, location).to_language_server_protocol_range),
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yoda-language-server-0.7.2 lib/yoda/server/providers/definition.rb
yoda-language-server-0.7.1 lib/yoda/server/providers/definition.rb
yoda-language-server-0.7.0 lib/yoda/server/providers/definition.rb