Closed thalesmello closed 2 months ago
Just out of curiosity, what linter are you using? I can't seem to be able to replicate this using LuaLS and selene. I'm not opposed to merging this in, but I'm also curious about how the placement of ?
matters, i.e. ---@field var? type
vs. ---@field var type?
. I suspect the former means field not required and the latter means field required, but may be nil
, but I would like clarification on that.
Hi.
I'm using LuaLS + neodev, and I had warnings in my nvim-surround config that motivated me to try to find a way to make the fields optional.
I'm not a Lua expert, so I'm not sure I'm doing the right thing here. I tried adding the field?
question mark, and it got rid of the warnings in the way I was expecting, and it still provides completion, so it at least it works.
I tried to look for official documentation, but I couldn't find any info about optional fields, only optional params, and optional type?
. I'm wondering whether field?
could be undocumented behavior, of it might even be the same thing as type?
considering table.field = nil
is how you delete a field in Lua.
Also, would you mind also testing this branch to make sure it also works in another setup?
Hmm strange, I've also been using neodev. I believe this should be a LuaLS issue, but I've been unable to reproduce it for myself, despite best efforts. I tried adding the ?
to keymaps, and see this in my autocomplete:
However, I don't get any warnings/errors about missing fields etc. Have you updated nvim-surround/LuaLS to their latest respective versions?
Type linter complains that missing options should be valid in configuration, when in fact they're optional. This marks the fields as optional.