summaryrefslogtreecommitdiff
path: root/script/method/completionItem/resolve.lua
blob: 0e55d311a58c5bf5f45368d32efef7de371e08e7 (plain)
1
2
3
4
5
6
7
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
local config = require 'config'

return function (lsp, item)
    local context = config.config.completion.displayContext
    if context <= 0 then
        return item
    end
    if not item.data then
        return item
    end
    local offset = item.data.offset
    local uri   = item.data.uri
    local _, lines, text = lsp:getVM(uri)
    if not lines then
        return item
    end
    local row = lines:rowcol(offset)
    local firstRow = lines[row]
    local lastRow = lines[math.min(row + context - 1, #lines)]
    local snip = text:sub(firstRow.start, lastRow.finish)
    local document = ([[
%s

------------
```lua
%s
```
]]):format(item.documentation and item.documentation.value or '', snip)
    item.documentation = {
        kind  = 'markdown',
        value = document,
    }
    return item
end