summaryrefslogtreecommitdiff
path: root/test/tclient/tests/resolve-completion.lua
blob: a7cf2c2f28e4f2bc563cd2ef79fce7e47d6ee03b (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local lclient   = require 'lclient'
local ws        = require 'workspace'
local util      = require 'utility'

---@async
lclient():start(function (client)
    client:registerFakers()
    client:initialize()

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = 'file://test.lua',
            languageId = 'lua',
            version = 0,
            text = [[
---@type integer
local xxxx

x
]]
        }
    })

    ws.awaitReady()

    local completions = client:awaitRequest('textDocument/completion', {
        textDocument = { uri = 'file://test.lua' },
        position = { line = 3, character = 1 },
    })

    client:awaitRequest('textDocument/didChange',
    {
        textDocument = { uri = 'file://test.lua' },
        contentChanges = {
            {
                range = {
                    start = { line = 3, character = 1 },
                    ['end'] = { line = 3, character = 1 },
                },
                text = 'x'
            }
        }
    })

    local targetItem
    for _, item in ipairs(completions.items) do
        if item.label == 'xxxx' then
            targetItem = item
            break
        end
    end

    assert(targetItem ~= nil)

    local newItem = client:awaitRequest('completionItem/resolve', targetItem)

    assert(newItem.detail == 'integer')
end)