summaryrefslogtreecommitdiff
path: root/test/tclient/tests/same-prefix.lua
blob: bc2a1f9b604bba5b8a269045a4c11dbdf5241ae9 (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
local lclient = require 'lclient'
local fs      = require 'bee.filesystem'
local util    = require 'utility'
local furi    = require 'file-uri'
local ws      = require 'workspace'
local files   = require 'files'
local scope   = require 'workspace.scope'

local rootPath = LOGPATH .. '/same-prefix'
local rootUri  = furi.encode(rootPath)

for _, name in ipairs { 'ws', 'ws1' } do
    fs.create_directories(fs.path(rootPath .. '/' .. name))
end

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

    client:initialize {
        rootPath = rootPath,
        rootUri = rootUri,
        workspaceFolders = {
            {
                name = 'ws',
                uri = rootUri .. '/ws',
            },
            {
                name = 'ws1',
                uri = rootUri .. '/ws1',
            },
        }
    }

    ws.awaitReady(rootUri .. '/ws')
    ws.awaitReady(rootUri .. '/ws1')

    files.setText(rootUri .. '/ws1/test.lua', [[
    ]])

    files.setText(rootUri .. '/ws/main.lua', [[
require ''
    ]])

    local comps1 = client:awaitRequest('textDocument/completion', {
        textDocument = {
            uri = rootUri .. '/ws/main.lua',
        },
        position = {
            line = 0,
            character = 9,
        },
    })
    for _, item in ipairs(comps1.items) do
        assert(item.label ~= 'test')
    end
end)