summaryrefslogtreecommitdiff
path: root/test/tclient
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-25 17:02:28 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-25 17:02:28 +0800
commit41c0a3671ec1cc704a9414f75772542ceaaf60d4 (patch)
tree8193c57282dda1e87795e497194eb7a54648f7d4 /test/tclient
parentbccfab54e367efe4d2b3e34fabb28bf1c481434e (diff)
downloadlua-language-server-41c0a3671ec1cc704a9414f75772542ceaaf60d4.zip
fix #925
Diffstat (limited to 'test/tclient')
-rw-r--r--test/tclient/init.lua1
-rw-r--r--test/tclient/tests/load-library.lua58
2 files changed, 59 insertions, 0 deletions
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index b9054a00..99b34867 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -2,3 +2,4 @@ require 'tclient.tests.single-mode'
require 'tclient.tests.library-ignore-limit'
require 'tclient.tests.multi-workspace'
require 'tclient.tests.folders-with-single-file'
+require 'tclient.tests.load-library'
diff --git a/test/tclient/tests/load-library.lua b/test/tclient/tests/load-library.lua
new file mode 100644
index 00000000..f128dee4
--- /dev/null
+++ b/test/tclient/tests/load-library.lua
@@ -0,0 +1,58 @@
+local lclient = require 'tclient.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()
+
+ 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)