diff --git a/changelog.md b/changelog.md index e38ccdb7d..3590906ea 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 2866eef8f..e1ef02a33 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 9bb0f8fcf..d5b497010 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. = 1 -- Warning +]]