summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-07-15 14:10:29 +0800
committerGitHub <noreply@github.com>2024-07-15 14:10:29 +0800
commit33ba77542e0dcec40a847d9e7430bc3c949fde87 (patch)
treed348141df25632d5d44b035be39b87fdd43b8eae
parentb7730378a3af41acc15fcd9312fcbce549c0911a (diff)
parentbfafcefd307ebc05e9c40dcc872be8e23e5ba7c5 (diff)
downloadlua-language-server-33ba77542e0dcec40a847d9e7430bc3c949fde87.zip
Merge pull request #2747 from NeOzay/master
fix: add a missing check for 'inject-field' diagnostics
-rw-r--r--changelog.md1
-rw-r--r--script/core/diagnostics/inject-field.lua3
-rw-r--r--test/diagnostics/inject-field.lua13
3 files changed, 17 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index e38ccdb7..3590906e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,7 @@
* `NEW` Add support for lambda style functions, `|paramList| expr` is syntactic sugar for `function(paramList) return expr end`
* `FIX` Respect `completion.showParams` config for local function completion
* `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic
+* `FIX` Bad triggering of the `inject-field` diagnostic, when the fields are declared at the creation of the object [#2746](https://github.com/LuaLS/lua-language-server/issues/2746)
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
## 3.9.3
diff --git a/script/core/diagnostics/inject-field.lua b/script/core/diagnostics/inject-field.lua
index 2866eef8..e1ef02a3 100644
--- a/script/core/diagnostics/inject-field.lua
+++ b/script/core/diagnostics/inject-field.lua
@@ -68,6 +68,9 @@ return function (uri, callback)
if def.type == 'doc.field' then
return
end
+ if def.type == 'tablefield' and not isExact then
+ return
+ end
end
local howToFix = ''
diff --git a/test/diagnostics/inject-field.lua b/test/diagnostics/inject-field.lua
index 9bb0f8fc..d5b49701 100644
--- a/test/diagnostics/inject-field.lua
+++ b/test/diagnostics/inject-field.lua
@@ -82,3 +82,16 @@ function m:init() -- OK
end
end
]]
+
+TEST [[
+---@class Class
+local m = {
+ xx = 1, -- OK
+}
+
+---@type Class
+local m
+
+m.xx = 1 -- OK
+m.<!yy!> = 1 -- Warning
+]]