summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-22 17:51:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-22 17:51:15 +0800
commit05a098f7ed731b2a3a6d068d5e9d7dfeacc67be0 (patch)
tree7f14a20db22167613559ea154f90fdc9d6cdf042
parent65706920bff73e2d50048b977da65e7ede06f6f8 (diff)
downloadlua-language-server-05a098f7ed731b2a3a6d068d5e9d7dfeacc67be0.zip
fix #1363 don't lookup globals in blocks
-rw-r--r--changelog.md1
-rw-r--r--script/core/diagnostics/unreachable-code.lua3
-rw-r--r--script/vm/compiler.lua4
-rw-r--r--test/diagnostics/common.lua22
4 files changed, 25 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 1cc80b85..94b1f760 100644
--- a/changelog.md
+++ b/changelog.md
@@ -5,6 +5,7 @@
* `CHG` improve supports for multi-workspace
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
* `FIX` [#1355](https://github.com/sumneko/lua-language-server/issues/1355)
+* `FIX` [#1363](https://github.com/sumneko/lua-language-server/issues/1363)
* `FIX` [#1368](https://github.com/sumneko/lua-language-server/issues/1368)
## 3.5.0
diff --git a/script/core/diagnostics/unreachable-code.lua b/script/core/diagnostics/unreachable-code.lua
index 84b25b45..772a1764 100644
--- a/script/core/diagnostics/unreachable-code.lua
+++ b/script/core/diagnostics/unreachable-code.lua
@@ -50,9 +50,6 @@ return function (uri, callback)
---@async
guide.eachSourceTypes(state.ast, {'main', 'function'}, function (source)
await.delay()
- if not source.returns then
- return
- end
for i, action in ipairs(source) do
if guide.isBlockType(action)
and hasReturn(action) then
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index fbc358a6..3d0464a4 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1736,7 +1736,7 @@ local function compileByGlobal(source)
if global.cate == 'variable' then
local hasMarkDoc
for _, set in ipairs(global:getSets(uri)) do
- if set.bindDocs then
+ if set.bindDocs and set.parent.type == 'main' then
if bindDocs(set) then
globalNode:merge(vm.compileNode(set))
hasMarkDoc = true
@@ -1751,7 +1751,7 @@ local function compileByGlobal(source)
vm.setNode(set, globalNode, true)
end
for _, set in ipairs(global:getSets(uri)) do
- if set.value and set.value.type ~= 'nil' then
+ if set.value and set.value.type ~= 'nil' and set.parent.type == 'main' then
if not hasMarkDoc or guide.isLiteral(set.value) then
globalNode:merge(vm.compileNode(set.value))
end
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 34164a9a..05656db5 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1988,6 +1988,28 @@ end
]]
TEST [[
+while true do
+end
+
+<!print(1)!>
+]]
+
+TEST [[
+while true do
+end
+
+<!print(1)!>
+]]
+
+TEST [[
+while X do
+ X = 1
+end
+
+print(1)
+]]
+
+TEST [[
---@diagnostic disable: undefined-global
while true do