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

local libraryPath     = LOGPATH .. '/load-library'
local libraryFilePath = LOGPATH .. '/load-library/library-file.lua'

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

    client:register('workspace/configuration', function ()
        return {
            {
                ['workspace.library'] = { libraryPath }
            },
        }
    end)

    fs.create_directories(fs.path(libraryPath))
    if not fs.exists(fs.path(libraryFilePath)) then
        util.saveFile(libraryFilePath, 'LIBRARY_FILE = true')
    end

    client:initialize {
        capabilities = {
            workspace = {
                configuration = true,
            }
        }
    }

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = furi.encode('abc/1.lua'),
            languageId = 'lua',
            version = 0,
            text = [[
require 'library-file'
print(LIBRARY_FILE)
]]
        }
    })

    ws.awaitReady()

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

    assert(util.equal(locations, {
        {
            uri = furi.encode(libraryFilePath),
            range = {
                start   = { line = 0, character = 0 },
                ['end'] = { line = 0, character = 0 },
            }
        }
    }))
end)