summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-29 17:32:39 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-29 17:32:39 +0800
commitf4493d69bd682307d88599804723543bd25b17df (patch)
tree487cebbd5eec54494fed61b1d4a7053bff17bf08 /test
parentf78d4944b4d811956b6b1493b8a022f633babfdd (diff)
downloadlua-language-server-f4493d69bd682307d88599804723543bd25b17df.zip
fix #1405
Diffstat (limited to 'test')
-rw-r--r--test/tclient/init.lua1
-rw-r--r--test/tclient/tests/load-relative-library.lua63
2 files changed, 64 insertions, 0 deletions
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index 80aae53a..828b5d6f 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -9,4 +9,5 @@ require 'tclient.tests.performance-jass-common'
require 'tclient.tests.hover-pairs'
require 'tclient.tests.change-workspace-folder'
require 'tclient.tests.jump-source'
+require 'tclient.tests.load-relative-library'
require 'tclient.tests.build-meta'
diff --git a/test/tclient/tests/load-relative-library.lua b/test/tclient/tests/load-relative-library.lua
new file mode 100644
index 00000000..ad3ebb4a
--- /dev/null
+++ b/test/tclient/tests/load-relative-library.lua
@@ -0,0 +1,63 @@
+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 workspacePath = LOGPATH .. '/not-exist/not-exist/not-exist'
+local libraryPath = '../../../load-relative-library'
+local libraryFilePath = LOGPATH .. '/load-relative-library/library-file.lua'
+
+---@async
+lclient():start(function (client)
+ client:registerFakers()
+
+ client:initialize {
+ rootUri = furi.encode(workspacePath),
+ }
+
+ client:register('workspace/configuration', function ()
+ return {
+ {
+ ['workspace.library'] = { libraryPath }
+ },
+ }
+ end)
+
+ fs.create_directories(fs.path(libraryFilePath):parent_path())
+ if not fs.exists(fs.path(libraryFilePath)) then
+ util.saveFile(libraryFilePath, 'LIBRARY_FILE = true')
+ end
+
+ client:initialize()
+
+ client:notify('textDocument/didOpen', {
+ textDocument = {
+ uri = furi.encode(workspacePath .. '/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(workspacePath .. '/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)