diff options
-rw-r--r-- | script/vm/compiler.lua | 12 | ||||
-rw-r--r-- | script/vm/def.lua | 3 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 2 | ||||
-rw-r--r-- | script/vm/infer.lua | 2 | ||||
-rw-r--r-- | script/vm/ref.lua | 3 | ||||
-rw-r--r-- | test/tclient/tests/multi-workspace.lua | 26 |
6 files changed, 36 insertions, 12 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 87306550..0becbbf0 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -150,7 +150,7 @@ function m.getClassFields(suri, node, key, pushResult) return end mark[name] = true - for _, set in ipairs(class:getSets()) do + for _, set in ipairs(class:getSets(suri)) do if set.type == 'doc.class' then -- check ---@field local hasFounded @@ -1408,9 +1408,9 @@ local function compileByNode(source) end ---@param source vm.node -local function compileByGlobal(source) +local function compileByGlobal(uri, source) + uri = uri or guide.getUri(source) if source.type == 'global' then - local uri = guide.getUri(source) nodeMgr.setNode(source, source) if source.cate == 'variable' then local hasMarkDoc @@ -1453,7 +1453,7 @@ local function compileByGlobal(source) return end if source._globalNode then - nodeMgr.setNode(source, m.compileNode(source._globalNode)) + nodeMgr.setNode(source, m.compileNode(source._globalNode, uri)) return end end @@ -1478,7 +1478,7 @@ end ---@param source parser.object ---@return vm.node -function m.compileNode(source) +function m.compileNode(source, uri) if not source then return false end @@ -1493,7 +1493,7 @@ function m.compileNode(source) end nodeMgr.nodeCache[source] = false - compileByGlobal(source) + compileByGlobal(uri, source) compileByNode(source) --localMgr.subscribeLocal(source, source._node) diff --git a/script/vm/def.lua b/script/vm/def.lua index 887da8e9..81d23854 100644 --- a/script/vm/def.lua +++ b/script/vm/def.lua @@ -200,9 +200,10 @@ local function searchByNode(source, pushResult) if not node then return end + local suri = guide.getUri(source) for n in nodeMgr.eachNode(node) do if n.type == 'global' then - for _, set in ipairs(n:getSets()) do + for _, set in ipairs(n:getSets(suri)) do pushResult(set) end else diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index 317b128b..bb4498ff 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -269,7 +269,7 @@ function m.getGlobalSets(suri, cate) local globals = m.getGlobals(cate) local result = {} for _, global in ipairs(globals) do - local sets = global:getSets() + local sets = global:getSets(suri) for _, set in ipairs(sets) do result[#result+1] = set end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 1ccc54aa..04fd01ca 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -201,7 +201,7 @@ function mt:_eraseAlias() local expandAlias = config.get(self.uri, 'Lua.hover.expandAlias') for n in nodeMgr.eachNode(self.node) do if n.type == 'global' and n.cate == 'type' then - for _, set in ipairs(n:getSets()) do + for _, set in ipairs(n:getSets(self.uri)) do if set.type == 'doc.alias' then if expandAlias then self.views[n.name] = nil diff --git a/script/vm/ref.lua b/script/vm/ref.lua index e1bdf81d..472b3b49 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -259,9 +259,10 @@ local function searchByNode(source, pushResult) if not node then return end + local uri = guide.getUri(source) for n in nodeMgr.eachNode(node) do if n.type == 'global' then - for _, get in ipairs(n:getGets()) do + for _, get in ipairs(n:getGets(uri)) do pushResult(get) end end diff --git a/test/tclient/tests/multi-workspace.lua b/test/tclient/tests/multi-workspace.lua index 95b53a0b..c4636c53 100644 --- a/test/tclient/tests/multi-workspace.lua +++ b/test/tclient/tests/multi-workspace.lua @@ -82,13 +82,13 @@ lclient():start(function (client) files.setText(rootUri .. '/ws1/unittest.lua', [[ GLOBAL = 1 ---@class ZAAA ----@type +---@type Z ]]) files.setText(rootUri .. '/ws2/unittest.lua', [[ GLOBAL = 2 ---@class ZBBB ----@type +---@type Z ]]) local defs1 = client:awaitRequest('textDocument/definition', { @@ -112,4 +112,26 @@ GLOBAL = 2 }, }) assert(#defs2 == 1) + + local comps1 = client:awaitRequest('textDocument/completion', { + textDocument = { + uri = rootUri .. '/ws1/unittest.lua', + }, + position = { + line = 2, + character = 10, + }, + }) + assert(#comps1.items == 1) + + local comps2 = client:awaitRequest('textDocument/completion', { + textDocument = { + uri = rootUri .. '/ws2/unittest.lua', + }, + position = { + line = 2, + character = 10, + }, + }) + assert(#comps2.items == 1) end) |