howl.lsp.lsp.hover

to_markdown(contents)

returns markdown MarkupContent as is

assert.equals '**x**', hover.to_markdown kind: 'markdown', value: '**x**'

fences plaintext MarkupContent

assert.equals '```\nx: int\n```', hover.to_markdown kind: 'plaintext', value: 'x: int'

returns a MarkedString string as is

assert.equals '*x*', hover.to_markdown '*x*'

fences a MarkedString with a language

assert.equals '```python\ndef f()\n```', hover.to_markdown language: 'python', value: 'def f()'

joins a list of MarkedStrings with blank lines

text = hover.to_markdown { { language: 'lua', value: 'x' }, '', 'doc' }
assert.equals '```lua\nx\n```\n\ndoc', text

returns nil for missing or blank contents

assert.is_nil hover.to_markdown nil
assert.is_nil hover.to_markdown kind: 'markdown', value: '  '
assert.is_nil hover.to_markdown {}

doc_for(buffer, pos)

local buffer, client, response

before_each ->
  response = contents: { kind: 'markdown', value: 'The **doc**' }
  client = {
    initialized: true,
    capabilities: { hoverProvider: true },
    request: spy.new -> response
  }
  buffer = Buffer {}
  buffer.text = 'åäö\nfoo'
  buffer.data.lsp = { :client, uri: 'file:///tmp/x.py', version: 1, dirty: false, changes: {}, full: false }

requests the hover for the uri and position

hover.doc_for buffer, 6
assert.spy(client.request).was_called_with client, 'textDocument/hover', {
  textDocument: { uri: 'file:///tmp/x.py' },
  position: { line: 1, character: 1 }
}

returns a buffer with the rendered documentation

doc = hover.doc_for buffer, 6
assert.equals 'The doc', doc.text
assert.equals 'strong', howl.ui.style.at_pos(doc, 5)

returns nil when there is no documentation

response = nil
assert.is_nil hover.doc_for buffer, 6
response = contents: { kind: 'markdown', value: '' }
assert.is_nil hover.doc_for buffer, 6

does not request anything when the server has no hoverProvider

client.capabilities = {}
assert.is_nil hover.doc_for buffer, 6
assert.spy(client.request).was_not_called!

returns nil for buffers without a language server

buffer.data.lsp = nil
assert.is_nil hover.doc_for buffer, 6