diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 11:14:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 11:14:57 +0800 |
commit | 73f30b560a2bfe8c0fe3d3f50b581ffca306ed75 (patch) | |
tree | fb55c3e4df468684398a50a14f28eb754c3010dc /server | |
parent | dedd889cb24357a443d4991eae6cb25e4fd830d6 (diff) | |
download | lua-language-server-73f30b560a2bfe8c0fe3d3f50b581ffca306ed75.zip |
重定义变量不提示第一个
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/diagnostics.lua | 11 | ||||
-rw-r--r-- | server/test/diagnostics/init.lua | 11 |
2 files changed, 20 insertions, 2 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua index 3593acd9..f4160f13 100644 --- a/server/src/matcher/diagnostics.lua +++ b/server/src/matcher/diagnostics.lua @@ -91,6 +91,7 @@ local function serachSpaces(lines, callback) end local function searchRedefinition(results, uri, callback) + local used = {} for _, var in ipairs(results.locals) do if var.key == '_' or var.key == '_ENV' @@ -101,8 +102,12 @@ local function searchRedefinition(results, uri, callback) if not shadow then goto NEXT_VAR end + if used[shadow] then + goto NEXT_VAR + end + used[shadow] = true -- 如果多次重定义,则不再警告 - if #shadow >= 3 then + if #shadow >= 4 then goto NEXT_VAR end local related = {} @@ -113,7 +118,9 @@ local function searchRedefinition(results, uri, callback) uri = uri, } end - callback(var.source.start, var.source.finish, var.key, related) + for i = 2, #shadow do + callback(shadow[i].source.start, shadow[i].source.finish, shadow[i].key, related) + end ::NEXT_VAR:: end end diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua index 8cfbe4f2..8ae721c1 100644 --- a/server/test/diagnostics/init.lua +++ b/server/test/diagnostics/init.lua @@ -86,6 +86,15 @@ x = 1<! !> ]] TEST [[ +local x +print(x) +local <!x!> +print(x) +]] + +TEST [[ +local x +print(x) local <!x!> print(x) local <!x!> @@ -99,6 +108,8 @@ local x print(x) local x print(x) +local x +print(x) ]] TEST [[ |