Class: Solargraph::LanguageServer::Message::TextDocument::Hover

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/language_server/message/text_document/hover.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

decode, encode, 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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/solargraph/language_server/message/text_document/hover.rb', line 8

def process
  line = params['position']['line']
  col = params['position']['character']
  contents = []
  suggestions = host.definitions_at(params['textDocument']['uri'], line, col)
  last_link = nil
  suggestions.each do |pin|
    parts = []
    this_link = host.options['enablePages'] ? pin.link_documentation : pin.text_documentation
    if !this_link.nil? && this_link != last_link
      parts.push this_link
    end
    parts.push "`#{pin.detail}`" unless pin.is_a?(Pin::Namespace) || pin.detail.nil?
    parts.push pin.documentation unless pin.documentation.nil? || pin.documentation.empty?
    unless parts.empty?
      data = parts.join("\n\n")
      next if contents.last && contents.last.end_with?(data)
      contents.push data
    end
    last_link = this_link unless this_link.nil?
  end
  set_result(
    contents: {
      kind: 'markdown',
      value: contents.join("\n\n")
    }
  )
rescue FileNotFoundError => e
  Logging.logger.warn "[#{e.class}] #{e.message}"
  Logging.logger.warn e.backtrace.join("\n")
  set_result nil
end