diff options
-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 [[ |