Class: Yoda::Server::HoverProvider

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ HoverProvider

Returns a new instance of HoverProvider.

Parameters:



7
8
9
# File 'lib/yoda/server/hover_provider.rb', line 7

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



4
5
6
# File 'lib/yoda/server/hover_provider.rb', line 4

def session
  @session
end

Instance Method Details

#create_hover(signature) ⇒ Object

Parameters:

  • signature (Evaluation::NodeSignature)


24
25
26
27
28
29
# File 'lib/yoda/server/hover_provider.rb', line 24

def create_hover(signature)
  LSP::Interface::Hover.new(
    contents: signature.descriptions.map { |value| create_hover_text(value) },
    range: LSP::Interface::Range.new(signature.node_range.to_language_server_protocol_range),
  )
end

#create_hover_text(description) ⇒ String

Parameters:

  • description (Evaluation::Descriptions::Base)

Returns:

  • (String)


33
34
35
# File 'lib/yoda/server/hover_provider.rb', line 33

def create_hover_text(description)
  description.to_markdown
end

#request_hover(uri, position) ⇒ Object

Parameters:

  • uri (String)
  • position ({Symbol => Integer})


13
14
15
16
17
18
19
20
21
# File 'lib/yoda/server/hover_provider.rb', line 13

def request_hover(uri, position)
  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)

  current_node_signature = node_worker.current_node_signature
  create_hover(current_node_signature) if current_node_signature
end