Class: Solargraph::LanguageServer::Message::TextDocument::Definition

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/language_server/message/text_document/definition.rb

Instance Attribute Summary

Attributes inherited from Base

#filename

Attributes inherited from Base

#error, #host, #id, #method, #params, #request, #result

Instance Method Summary collapse

Methods inherited from Base

#post_initialize

Methods included from UriHelpers

file_to_uri, uri_to_file

Methods inherited from Base

#initialize, #post_initialize, #send_response, #set_error, #set_result

Constructor Details

This class inherits a constructor from Solargraph::LanguageServer::Message::Base

Instance Method Details

#processObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/solargraph/language_server/message/text_document/definition.rb', line 5

def process
  # source = host.read(params['textDocument']['uri'])
  # code_map = Solargraph::CodeMap.from_source(source, host.api_map)
  # offset = code_map.get_offset(params['position']['line'], params['position']['character'])
  # suggestions = code_map.define_symbol_at(offset)
  filename = uri_to_file(params['textDocument']['uri'])
  line = params['position']['line']
  col = params['position']['character']
  suggestions = host.definitions_at(filename, line, col)
  locations = suggestions.reject{|pin| pin.location.nil?}.map do |pin|
    {
      uri: file_to_uri(pin.location.filename),
      range: pin.location.range.to_hash
    }
  end
  set_result locations
end