diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-02 20:32:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-02 20:32:24 +0800 |
commit | 112788ca2c7d73ab5a261e1333090b08c6ac4fc4 (patch) | |
tree | a1e23ef226c5424c66d3d46946c863de7467aa20 /test | |
parent | be0d11df2d89b8cb8cf24190ccfbd273256f4c74 (diff) | |
parent | 25d3e051095ff1f1b7da58e591b2455a25d19328 (diff) | |
download | lua-language-server-112788ca2c7d73ab5a261e1333090b08c6ac4fc4.zip |
Merge remote-tracking branch 'origin/master' into 3.0
Diffstat (limited to 'test')
-rw-r--r-- | test/completion/common.lua | 9 | ||||
-rw-r--r-- | test/tclient/init.lua | 1 | ||||
-rw-r--r-- | test/tclient/lclient.lua | 219 | ||||
-rw-r--r-- | test/tclient/tests/files-associations.lua | 48 | ||||
-rw-r--r-- | test/tclient/tests/folders-with-single-file.lua | 2 | ||||
-rw-r--r-- | test/tclient/tests/library-ignore-limit.lua | 2 | ||||
-rw-r--r-- | test/tclient/tests/load-library.lua | 2 | ||||
-rw-r--r-- | test/tclient/tests/multi-workspace.lua | 2 | ||||
-rw-r--r-- | test/tclient/tests/single-mode.lua | 2 |
9 files changed, 63 insertions, 224 deletions
diff --git a/test/completion/common.lua b/test/completion/common.lua index 818d0ac5..787549f7 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3079,3 +3079,12 @@ TEST [[ if<??> ]] (EXISTS) + +TEST [[ +local t = x[<??>] +]] +(function (results) + for _, res in ipairs(results) do + assert(res.label ~= 'do') + end +end) diff --git a/test/tclient/init.lua b/test/tclient/init.lua index 99b34867..7c8d70ef 100644 --- a/test/tclient/init.lua +++ b/test/tclient/init.lua @@ -3,3 +3,4 @@ require 'tclient.tests.library-ignore-limit' require 'tclient.tests.multi-workspace' require 'tclient.tests.folders-with-single-file' require 'tclient.tests.load-library' +require 'tclient.tests.files-associations' diff --git a/test/tclient/lclient.lua b/test/tclient/lclient.lua deleted file mode 100644 index 8da8d138..00000000 --- a/test/tclient/lclient.lua +++ /dev/null @@ -1,219 +0,0 @@ -local gc = require 'gc' -local util = require 'utility' -local proto = require 'proto' -local await = require 'await' -local timer = require 'timer' -local pub = require 'pub' -local json = require 'json' - -require 'provider' - -local counter = util.counter() - ----@class languageClient ----@field _outs table ----@field _gc gc ----@field _waiting table ----@field _methods table -local mt = {} -mt.__index = mt - -function mt:__close() - self:remove() -end - -function mt:_fakeProto() - proto.send = function (data) - self._outs[#self._outs+1] = data - end -end - -function mt:_flushServer() - -- reset scopes - local ws = require 'workspace' - local scope = require 'workspace.scope' - local files = require 'files' - ws.reset() - scope.reset() - files.reset() -end - -function mt:_localLoadFile() - local awaitTask = pub.awaitTask - ---@async - ---@param name string - ---@param params any - pub.awaitTask = function (name, params) - if name == 'loadFile' then - local path = params - return util.loadFile(path) - end - return awaitTask(name, params) - end - self:gc(function () - pub.awaitTask = awaitTask - end) -end - ----@async -function mt:initialize(params) - self:awaitRequest('initialize', params or {}) - self:notify('initialized') -end - -function mt:reportHangs() - local hangs = {} - hangs[#hangs+1] = ('====== C -> S ======') - for _, waiting in util.sortPairs(self._waiting) do - hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method) - end - hangs[#hangs+1] = ('====== S -> C ======') - for _, waiting in util.sortPairs(proto.waiting) do - hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method) - end - hangs[#hangs+1] = ('====================') - return table.concat(hangs, '\n') -end - ----@param callback async fun(client: languageClient) -function mt:start(callback) - self:_fakeProto() - self:_flushServer() - self:_localLoadFile() - - local finished = false - - await.setErrorHandle(function (...) - local msg = log.error(...) - error(msg) - end) - - ---@async - await.call(function () - callback(self) - finished = true - end) - - local jumpedTime = 0 - - while true do - if finished then - break - end - if await.step() then - goto CONTINUE - end - timer.update() - if await.step() then - goto CONTINUE - end - if self:update() then - goto CONTINUE - end - timer.timeJump(1.0) - jumpedTime = jumpedTime + 1.0 - if jumpedTime > 2 * 60 * 60 then - error('two hours later ...\n' .. self:reportHangs()) - end - ::CONTINUE:: - end - - self:remove() -end - -function mt:gc(obj) - return self._gc:add(obj) -end - -function mt:remove() - self._gc:remove() -end - -function mt:notify(method, params) - proto.doMethod { - method = method, - params = params, - } -end - -function mt:request(method, params, callback) - local id = counter() - self._waiting[id] = { - id = id, - params = params, - callback = callback, - } - proto.doMethod { - id = id, - method = method, - params = params, - } -end - ----@async -function mt:awaitRequest(method, params) - return await.wait(function (waker) - self:request(method, params, function (result) - if result == json.null then - result = nil - end - waker(result) - end) - end) -end - -function mt:update() - local outs = self._outs - if #outs == 0 then - return false - end - self._outs = {} - for _, out in ipairs(outs) do - if out.method then - local callback = self._methods[out.method] - if callback then - proto.doResponse { - id = out.id, - result = callback(out.params), - } - elseif out.method:sub(1, 2) ~= '$/' then - error('Unknown method: ' .. out.method) - end - else - local callback = self._waiting[out.id].callback - self._waiting[out.id] = nil - callback(out.result, out.error) - end - end - return true -end - -function mt:register(method, callback) - self._methods[method] = callback -end - -function mt:registerFakers() - for _, method in ipairs { - 'textDocument/publishDiagnostics', - 'workspace/configuration', - 'workspace/semanticTokens/refresh', - 'window/workDoneProgress/create', - 'window/showMessage', - 'window/logMessage', - } do - self:register(method, function () - return nil - end) - end -end - ----@return languageClient -return function () - local self = setmetatable({ - _gc = gc(), - _outs = {}, - _waiting = {}, - _methods = {}, - }, mt) - return self -end diff --git a/test/tclient/tests/files-associations.lua b/test/tclient/tests/files-associations.lua new file mode 100644 index 00000000..12c04926 --- /dev/null +++ b/test/tclient/tests/files-associations.lua @@ -0,0 +1,48 @@ +local lclient = require 'lclient' +local ws = require 'workspace' +local files = require 'files' +local furi = require 'file-uri' +local util = require 'utility' +local fs = require 'bee.filesystem' + +local rootPath = LOGPATH .. '/files-associations' +local rootUri = furi.encode(rootPath) + +fs.create_directories(fs.path(rootPath)) + +local filePath = rootPath .. '/test.lua.txt' +local fileUri = furi.encode(filePath) +util.saveFile(filePath, '') + +---@async +lclient():start(function (client) + client:registerFakers() + + client:register('workspace/configuration', function () + return { + {}, + { + ["*.lua.txt"] = "lua", + } + } + end) + + client:initialize { + rootPath = rootPath, + rootUri = rootUri, + workspaceFolders = { + { + name = 'ws', + uri = rootUri, + }, + } + } + + ws.awaitReady(rootUri) + + assert(files.isLua(furi.encode 'aaa.lua.txt') == true) + assert(files.isLua(furi.encode '/aaa.lua.txt') == true) + assert(files.isLua(furi.encode 'D:\\aaa.lua.txt') == true) + assert(files.isLua(fileUri) == true) + assert(files.exists(fileUri) == true) +end) diff --git a/test/tclient/tests/folders-with-single-file.lua b/test/tclient/tests/folders-with-single-file.lua index 326dd623..e77535c9 100644 --- a/test/tclient/tests/folders-with-single-file.lua +++ b/test/tclient/tests/folders-with-single-file.lua @@ -1,4 +1,4 @@ -local lclient = require 'tclient.lclient' +local lclient = require 'lclient' local fs = require 'bee.filesystem' local util = require 'utility' local furi = require 'file-uri' diff --git a/test/tclient/tests/library-ignore-limit.lua b/test/tclient/tests/library-ignore-limit.lua index dcf8717a..3f30a4e9 100644 --- a/test/tclient/tests/library-ignore-limit.lua +++ b/test/tclient/tests/library-ignore-limit.lua @@ -1,4 +1,4 @@ -local lclient = require 'tclient.lclient' +local lclient = require 'lclient' local util = require 'utility' local ws = require 'workspace' local files = require 'files' diff --git a/test/tclient/tests/load-library.lua b/test/tclient/tests/load-library.lua index f128dee4..cbd1492a 100644 --- a/test/tclient/tests/load-library.lua +++ b/test/tclient/tests/load-library.lua @@ -1,4 +1,4 @@ -local lclient = require 'tclient.lclient' +local lclient = require 'lclient' local util = require 'utility' local ws = require 'workspace' local files = require 'files' diff --git a/test/tclient/tests/multi-workspace.lua b/test/tclient/tests/multi-workspace.lua index 02ebacbd..dde59322 100644 --- a/test/tclient/tests/multi-workspace.lua +++ b/test/tclient/tests/multi-workspace.lua @@ -1,4 +1,4 @@ -local lclient = require 'tclient.lclient' +local lclient = require 'lclient' local fs = require 'bee.filesystem' local util = require 'utility' local furi = require 'file-uri' diff --git a/test/tclient/tests/single-mode.lua b/test/tclient/tests/single-mode.lua index 10f3e2da..f79fa2e8 100644 --- a/test/tclient/tests/single-mode.lua +++ b/test/tclient/tests/single-mode.lua @@ -1,4 +1,4 @@ -local lclient = require 'tclient.lclient' +local lclient = require 'lclient' local ws = require 'workspace' local util = require 'utility' |