Skip to content

Fix missing-fields diagnostic not warning about missing inherited fields #2970

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

SereneRuby12
Copy link
Contributor

@SereneRuby12 SereneRuby12 commented Nov 28, 2024

Should close #2337, close #2598, close #2740, close #2966

@tomlau10
Copy link
Contributor

Hi @estebanfer, when closing multiple issues, you have to write the close keyword for each of them.
Otherwise github will only link the first one 😄

Should close #2337, close #2598, close #2740, close #2966

(just edit your existing PR description is enough)


You can verify this on the right hand side section of this PR page: Successfully merging this pull request may close these issues.

@sumneko sumneko merged commit 7b2d585 into LuaLS:master Dec 6, 2024
11 checks passed
@sumneko
Copy link
Collaborator

sumneko commented Dec 6, 2024

Thank you!

@dpetka2001
Copy link

dpetka2001 commented Dec 11, 2024

Is there a setting to explicitly disable the warning about inherited fields? Or you have to disable missing-fields globally?

@tomlau10
Copy link
Contributor

It is considered as a bug by not reporting missing inherited fields before, so there is no option to disable only missing inherited fields
=> it's just one of the fields that your class object needs to have, unless it is annotated as optional in the parent class

Consider the following example:

---@class Parent1
---@field parent1 string

---@class Child1: Parent1

---@type Child1
local c1 = {}
--> missing-fields: Missing required fields in type `Child1`: `parent1`
-- `parent1` is shown because it is a required field

---

---@class Parent2
---@field parent2? string

---@class Child2: Parent2

---@type Child2
local c2 = {}
--> no warning, as `parent2` is optional

Can you elaborate on the use case in why you want to explicitly disable this warning 🤔 ?

@dpetka2001
Copy link

It's really nothing. I've just started learning programming at the start of this year and I try to contribute a little bit in Neovim plugins, since that is the editor I use.

As an example a plugin has the following ---@field wo? vim.wo but while developing it shows all the warnings about missing fields from inherited values, which I'm guessing comes from Neovim itself not having optional fields for vim.wo? I don't want to see these warnings, so I just add ---@diagnostic disable-next-line: missing-fields.

So, not a big deal and I understand they should be shown, but if I'm working with other types not implemented in the plugin itself, then I really don't want to see the warnings about those inherited values. Just a personal preference.

@tomlau10
Copy link
Contributor

Ah~ I see the examples in the cross linked issue now.

And as commented in that issue, this feature is called partial class and currently not implemented in LuaLS. 🤔
Before this PR, seems that lua community utilize this bug as a hack, in which missing fields check will not check for parent fields, to achieve the concept of partial class: #2561 (comment)

---@class Config
---@field a string
---@field b string

---@class Config.P: Config
---@field c string

---@type Config.P
local partialConfig = {}    -- now every in `Config` is optional, will only warn for missing `c`

If this PR is not going to be reverted, then I guess we must wait for someone to implement partial class.
Say the syntax maybe like this:

---@class (partial) Config.P: Config
---@field c string

And then in the missing-field check logic:

  • if the class has this partial attribute => use the original checking logic, which only checks for @field in that class
  • otherwise check all fields, including those in parent class

This maybe the minimum requirement for the partial class feature.


cc @sumneko
貌似這個 bugfix PR 把現有的1種 partial class hack實現方式,給封掉了 🙈

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
4 participants