summaryrefslogtreecommitdiff
path: root/test/tclient/tests/folders-with-single-file.lua
blob: e77535c955840397388f6a84c9b95175f34a6b48 (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
59
60
61
62
63
64
65
66
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'

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

    client:initialize {
        rootUri = 'abc',
    }

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = furi.encode('abc/1.lua'),
            languageId = 'lua',
            version = 0,
            text = [[
local x
print(x)
]]
        }
    })

    ws.awaitReady('abc')

    local locations = client:awaitRequest('textDocument/definition', {
        textDocument = { uri = furi.encode('abc/1.lua') },
        position = { line = 1, character = 7 },
    })

    assert(util.equal(locations, {
        {
            uri = furi.encode('abc/1.lua'),
            range = {
                start   = { line = 0, character = 6 },
                ['end'] = { line = 0, character = 7 },
            }
        }
    }))

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = 'test://single-file.lua',
            languageId = 'lua',
            version = 0,
            text = [[
local x
print(x)
]]
        }
    })

    ws.awaitReady(nil)

    local locations = client:awaitRequest('textDocument/definition', {
        textDocument = { uri = 'test://single-file.lua' },
        position = { line = 1, character = 0 },
    })

    assert(#locations > 0)
end)