Class: Yoda::Server::DefinitionProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/server/definition_provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ DefinitionProvider

Returns a new instance of DefinitionProvider.

Parameters:



8
9
10
# File 'lib/yoda/server/definition_provider.rb', line 8

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



5
6
7
# File 'lib/yoda/server/definition_provider.rb', line 5

def session
  @session
end

Instance Method Details

#create_location(path, line, column) ⇒ Object

Parameters:

  • path (String)
  • line (Integer)
  • column (Integer)


27
28
29
30
31
32
33
# File 'lib/yoda/server/definition_provider.rb', line 27

def create_location(path, line, column)
  location = Parsing::Location.new(row: line - 1, column: column)
  LSP::Interface::Location.new(
    uri: session.uri_of_path(path),
    range: LSP::Interface::Range.new(Parsing::Range.new(location, location).to_language_server_protocol_range),
  )
end

#provide(uri, position, include_declaration = false) ⇒ Object

Parameters:

  • uri (String)
  • position ({Symbol => Integer})
  • include_declaration (Boolean) (defaults to: false)


15
16
17
18
19
20
21
22
# File 'lib/yoda/server/definition_provider.rb', line 15

def provide(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