From 41c0a3671ec1cc704a9414f75772542ceaaf60d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 25 Jan 2022 17:02:28 +0800 Subject: fix #925 --- test/tclient/tests/load-library.lua | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/tclient/tests/load-library.lua (limited to 'test/tclient/tests/load-library.lua') 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) -- cgit v1.2.3