diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 21:13:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 21:13:58 +0800 |
commit | 4c71c56f925246618cce854ab9773311a7812055 (patch) | |
tree | 45721d5321668cf5b749caab322a84b414e587fb /test/tclient/tests/change-workspace-folder.lua | |
parent | d50a75aac341d6b87caadb3eb9b863cb8ebe2751 (diff) | |
download | lua-language-server-4c71c56f925246618cce854ab9773311a7812055.zip |
support change workspace folders
TODO: has memory leak after remove folders
Diffstat (limited to 'test/tclient/tests/change-workspace-folder.lua')
-rw-r--r-- | test/tclient/tests/change-workspace-folder.lua | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/test/tclient/tests/change-workspace-folder.lua b/test/tclient/tests/change-workspace-folder.lua new file mode 100644 index 00000000..abd385cb --- /dev/null +++ b/test/tclient/tests/change-workspace-folder.lua @@ -0,0 +1,101 @@ +local lclient = require 'lclient' +local fs = require 'bee.filesystem' +local util = require 'utility' +local furi = require 'file-uri' +local ws = require 'workspace' +local files = require 'files' +local scope = require 'workspace.scope' + +local rootPath = LOGPATH .. '/change-workspace-folder' +local rootUri = furi.encode(rootPath) + +for _, name in ipairs { 'ws1', 'ws2', 'ws3' } do + fs.create_directories(fs.path(rootPath .. '/' .. name)) + util.saveFile(rootPath .. '/' .. name .. '/test.lua', '') +end + +---@async +lclient():start(function (client) + client:registerFakers() + + client:initialize { + rootPath = rootPath, + rootUri = rootUri, + workspaceFolders = { + { + name = 'ws1', + uri = rootUri .. '/ws1', + }, + } + } + + ws.awaitReady(rootUri .. '/ws1') + assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws2/test.lua') == nil) + assert(files.getState(rootUri .. '/ws3/test.lua') == nil) + + client:notify('workspace/didChangeWorkspaceFolders', { + event = { + added = { + { + name = 'ws2', + uri = rootUri .. '/ws2', + }, + }, + removed = {}, + }, + }) + + ws.awaitReady(rootUri .. '/ws2') + assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws3/test.lua') == nil) + + client:notify('workspace/didChangeWorkspaceFolders', { + event = { + added = { + { + name = 'ws3', + uri = rootUri .. '/ws3', + }, + }, + removed = {}, + }, + }) + ws.awaitReady(rootUri .. '/ws3') + assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws3/test.lua') ~= nil) + + client:notify('workspace/didChangeWorkspaceFolders', { + event = { + added = {}, + removed = { + { + name = 'ws2', + uri = rootUri .. '/ws2', + }, + }, + }, + }) + + assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil) + assert(files.getState(rootUri .. '/ws2/test.lua') == nil) + assert(files.getState(rootUri .. '/ws3/test.lua') ~= nil) + + client:notify('workspace/didChangeWorkspaceFolders', { + event = { + added = {}, + removed = { + { + name = 'ws1', + uri = rootUri .. '/ws1', + }, + }, + }, + }) + + assert(files.getState(rootUri .. '/ws1/test.lua') == nil) + assert(files.getState(rootUri .. '/ws2/test.lua') == nil) + assert(files.getState(rootUri .. '/ws3/test.lua') ~= nil) +end) |