diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/global.lua | 43 | ||||
-rw-r--r-- | script/workspace/scope.lua | 14 | ||||
-rw-r--r-- | test/tclient/tests/single-mode.lua | 18 |
4 files changed, 51 insertions, 25 deletions
diff --git a/changelog.md b/changelog.md index e204cd74..b6c4df17 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ * `FIX` [#1033](https://github.com/sumneko/lua-language-server/issues/1033) * `FIX` [#1034](https://github.com/sumneko/lua-language-server/issues/1034) * `FIX` [#1035](https://github.com/sumneko/lua-language-server/issues/1035) +* `FIX` [#1036](https://github.com/sumneko/lua-language-server/issues/1036) ## 3.0.0 `2022-4-10` diff --git a/script/vm/global.lua b/script/vm/global.lua index 218e09db..5ac18ced 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -21,6 +21,9 @@ local ID_SPLITE = '\x1F' ---@param source parser.object function mt:addSet(uri, source) local link = self.links[uri] + if not link.sets then + link.sets = {} + end link.sets[#link.sets+1] = source self.setsCache = nil end @@ -29,6 +32,9 @@ end ---@param source parser.object function mt:addGet(uri, source) local link = self.links[uri] + if not link.gets then + link.gets = {} + end link.gets[#link.gets+1] = source self.getsCache = nil end @@ -38,20 +44,19 @@ function mt:getSets(suri) if not self.setsCache then self.setsCache = {} end - ---@type scope - local scp = suri and scope.getScope(suri) or nil - local cacheUri = scp and scp.uri or '<fallback>' + local scp = scope.getScope(suri) + local cacheUri = scp.uri or '<callback>' if self.setsCache[cacheUri] then return self.setsCache[cacheUri] end self.setsCache[cacheUri] = {} local cache = self.setsCache[cacheUri] for uri, link in pairs(self.links) do - if not scp - or scp:isChildUri(uri) - or scp:isLinkedUri(uri) then - for _, source in ipairs(link.sets) do - cache[#cache+1] = source + if link.sets then + if scp:isVisible(uri) then + for _, source in ipairs(link.sets) do + cache[#cache+1] = source + end end end end @@ -63,20 +68,19 @@ function mt:getGets(suri) if not self.getsCache then self.getsCache = {} end - ---@type scope - local scp = suri and scope.getScope(suri) or nil - local cacheUri = scp and scp.uri or '<fallback>' + local scp = scope.getScope(suri) + local cacheUri = scp.uri or '<callback>' if self.getsCache[cacheUri] then return self.getsCache[cacheUri] end self.getsCache[cacheUri] = {} local cache = self.getsCache[cacheUri] for uri, link in pairs(self.links) do - if not scp - or scp:isChildUri(uri) - or scp:isLinkedUri(uri) then - for _, source in ipairs(link.gets) do - cache[#cache+1] = source + if link.gets then + if scp:isVisible(uri) then + for _, source in ipairs(link.gets) do + cache[#cache+1] = source + end end end end @@ -111,11 +115,6 @@ return function (name, cate) return setmetatable({ name = name, cate = cate, - links = util.defaultTable(function () - return { - sets = {}, - gets = {}, - } - end), + links = util.multiTable(2), }, mt) end diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index be112af2..a0f4fbf7 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -1,5 +1,8 @@ local gc = require 'gc' +---@class scope.manager +local m = {} + ---@alias scope.type '"override"'|'"folder"'|'"fallback"' ---@class scope @@ -60,6 +63,14 @@ function mt:isLinkedUri(uri) end ---@param uri uri +---@return boolean +function mt:isVisible(uri) + return self:isChildUri(uri) + or self:isLinkedUri(uri) + or self == m.getScope(uri) +end + +---@param uri uri ---@return uri? function mt:getLinkedUri(uri) if not uri then @@ -122,9 +133,6 @@ local function createScope(scopeType) return scope end ----@class scope.manager -local m = {} - function m.reset() ---@type scope[] m.folders = {} diff --git a/test/tclient/tests/single-mode.lua b/test/tclient/tests/single-mode.lua index 4e14415b..25463f55 100644 --- a/test/tclient/tests/single-mode.lua +++ b/test/tclient/tests/single-mode.lua @@ -15,6 +15,9 @@ lclient():start(function (client) text = [[ local x print(x) + +TEST = 1 +print(TEST) ]] } }) @@ -42,4 +45,19 @@ print(x) }) assert(#locations > 0) + + local locations = client:awaitRequest('textDocument/definition', { + textDocument = { uri = 'file://single-file.lua' }, + position = { line = 3, character = 0 }, + }) + + assert(util.equal(locations, { + { + uri = 'file://single-file.lua', + range = { + start = { line = 3, character = 0 }, + ['end'] = { line = 3, character = 4 }, + } + } + })) end) |