diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-08-01 15:39:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-08-01 15:39:13 +0800 |
commit | c2340047debdfa00c1946a113008f7982f68dcb7 (patch) | |
tree | 9d388739cb0809f7fc93f0ed1ff1610d3328e7f8 | |
parent | f18a56604200f7ac19a785f6ce52cb7be67979e6 (diff) | |
download | lua-language-server-c2340047debdfa00c1946a113008f7982f68dcb7.zip |
fix #1418
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 13 | ||||
-rw-r--r-- | script/vm/function.lua | 2 | ||||
-rw-r--r-- | test/full/projects.lua | 2 | ||||
-rw-r--r-- | test/tclient/init.lua | 1 | ||||
-rw-r--r-- | test/tclient/tests/hover-set-local.lua | 45 |
7 files changed, 63 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md index c26cfd80..48af11bd 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ * `FIX` [#1403](https://github.com/sumneko/lua-language-server/issues/1403) * `FIX` [#1405](https://github.com/sumneko/lua-language-server/issues/1405) * `FIX` [#1406](https://github.com/sumneko/lua-language-server/issues/1406) +* `FIX` [#1418](https://github.com/sumneko/lua-language-server/issues/1418) ## 3.5.1 `2022-7-26` diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 762b8d50..46ea600f 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -515,6 +515,7 @@ function m.diagnosticsScope(uri, force) local id = 'diagnosticsScope:' .. scp:getName() await.close(id) await.call(function () ---@async + await.sleep(0.0) m.awaitDiagnosticsScope(uri, function (fileUri) xpcall(m.doDiagnostic, log.error, fileUri, true) end) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index a33eee1f..150ed16f 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -6,6 +6,8 @@ local files = require 'files' ---@class vm local vm = require 'vm.vm' +local LOCK = {} + ---@class parser.object ---@field _compiledNodes boolean ---@field _node vm.node @@ -1161,6 +1163,15 @@ local compilerSwitch = util.switch() vm.setNode(src, vm.createNode(src.value)) vm.setNode(src, node:copy():asTable()) else + guide.eachSource(src.value, function (child) + if child.type == 'getlocal' + and child.node == source then + return + end + if LOCK[child] then + vm.removeNode(child) + end + end) vm.setNode(src, vm.compileNode(src.value), true) end else @@ -1811,9 +1822,11 @@ function vm.compileNode(source) ---@cast source parser.object vm.setNode(source, vm.createNode(), true) + LOCK[source] = true compileByGlobal(source) compileByNode(source) matchCall(source) + LOCK[source] = nil local node = vm.getNode(source) ---@cast node -? diff --git a/script/vm/function.lua b/script/vm/function.lua index f64b2262..148211be 100644 --- a/script/vm/function.lua +++ b/script/vm/function.lua @@ -201,7 +201,7 @@ end ---@return parser.object[] function vm.getMatchedFunctions(func, args, mark) local funcs = {} - local node = vm.compileNode(func) + local node = vm.getNode(func) or vm.compileNode(func) for n in node:eachObject() do if n.type == 'function' or n.type == 'doc.type.function' then diff --git a/test/full/projects.lua b/test/full/projects.lua index dedb42e5..dacc101c 100644 --- a/test/full/projects.lua +++ b/test/full/projects.lua @@ -57,4 +57,4 @@ local function doProjects(pathname) end --doProjects [[C:\SSSEditor\client\Output\Lua]] -doProjects [[C:\W3-Server\script]] +--doProjects [[C:\W3-Server\script]] diff --git a/test/tclient/init.lua b/test/tclient/init.lua index 828b5d6f..6f861142 100644 --- a/test/tclient/init.lua +++ b/test/tclient/init.lua @@ -10,4 +10,5 @@ require 'tclient.tests.hover-pairs' require 'tclient.tests.change-workspace-folder' require 'tclient.tests.jump-source' require 'tclient.tests.load-relative-library' +require 'tclient.tests.hover-set-local' require 'tclient.tests.build-meta' diff --git a/test/tclient/tests/hover-set-local.lua b/test/tclient/tests/hover-set-local.lua new file mode 100644 index 00000000..cf99aebc --- /dev/null +++ b/test/tclient/tests/hover-set-local.lua @@ -0,0 +1,45 @@ +local lclient = require 'lclient' +local ws = require 'workspace' +local await = require 'await' + +---@async +lclient():start(function (client) + client:registerFakers() + client:initialize() + + client:notify('textDocument/didOpen', { + textDocument = { + uri = 'file://test.lua', + languageId = 'lua', + version = 0, + text = [[ +---@class Class +local m + +---@return Class +function m:f() end + +---@type Class +local v +v = v:f() +]] + } + }) + + ws.awaitReady() + + await.sleep(0.1) + + local hover1 = client:awaitRequest('textDocument/hover', { + textDocument = { uri = 'file://test.lua' }, + position = { line = 7, character = 6 }, + }) + + local hover2 = client:awaitRequest('textDocument/hover', { + textDocument = { uri = 'file://test.lua' }, + position = { line = 8, character = 0 }, + }) + + assert(hover1.contents.value:find 'Class') + assert(hover2.contents.value:find 'Class') +end) |