diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-05 11:27:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-05 11:27:05 +0800 |
commit | 9b7a246d397aff61bc29837c40a1317ff18c7887 (patch) | |
tree | 7a2f18d7dd0b590a3aee32cdcaaa0d4bfb91759f | |
parent | 8f505a0b999d1432dfc107133e7ac2ba591cbed2 (diff) | |
download | lua-language-server-9b7a246d397aff61bc29837c40a1317ff18c7887.zip |
支持重定义局部变量
-rw-r--r-- | server-beta/src/core/diagnostics/redefined-local.lua | 2 | ||||
-rw-r--r-- | server-beta/src/parser/ast.lua | 2 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 12 |
3 files changed, 9 insertions, 7 deletions
diff --git a/server-beta/src/core/diagnostics/redefined-local.lua b/server-beta/src/core/diagnostics/redefined-local.lua index a1b0e77a..f6176794 100644 --- a/server-beta/src/core/diagnostics/redefined-local.lua +++ b/server-beta/src/core/diagnostics/redefined-local.lua @@ -13,7 +13,7 @@ return function (uri, callback) or name == '_ENV' then return end - local exist = guide.getLocal(source, name, source.start) + local exist = guide.getLocal(source, name, source.start-1) if exist then callback { start = source.start, diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua index ae8f9a7a..39e7d871 100644 --- a/server-beta/src/parser/ast.lua +++ b/server-beta/src/parser/ast.lua @@ -862,7 +862,7 @@ local Defs = { return end - local loc = createLocal(name, start, actions) + local loc = createLocal(name, name.start, actions) loc.localfunction = true return loc diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index d8dd873e..02284b1e 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -316,12 +316,14 @@ function m.eachSourceType(ast, type, callback) if not cache then cache = {} ast.typeCache[type] = cache + local mark = {} + m.eachSource(ast, function (source) + if source.type == type and not mark[source] then + mark[source] = true + cache[#cache+1] = source + end + end) end - m.eachSource(ast, function (source) - if source.type == type then - cache[#cache+1] = source - end - end) for i = 1, #cache do callback(cache[i]) end |