Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature Request: Deprecate fields and parameters #1313

Open
Rouneq opened this issue Jul 10, 2022 · 5 comments
Open

Feature Request: Deprecate fields and parameters #1313

Rouneq opened this issue Jul 10, 2022 · 5 comments
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)

Comments

@Rouneq
Copy link

Rouneq commented Jul 10, 2022

Could really use a clean way to mark specific field and parameters as deprecated. Currently I'm adding @**[DEPRECATED]** to the start of the comments for the field/parameter, but this doesn't change the name with a strike-through (as happens with functions).

@sumneko sumneko added enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels Jul 11, 2022
@sumneko
Copy link
Collaborator

sumneko commented Sep 19, 2022

You can use ---@deprecated for field.
But there is no way for parameter.

@johannesrld
Copy link

You can use ---@deprecated for field.

how 🤔 im trying

---@class foo
---@deprecated
---@field example string
foo = {}

but it does not work

@bavalpey
Copy link
Contributor

bavalpey commented Feb 7, 2024

Would like to see this as well.

@TIMONz1535
Copy link
Contributor

I see that it partially works because you can use on ---@type, but it has an issues - the behavior completely changes for the local defined classes

Lua code
---@deprecated -- does nothing
---@class foo
---@field example string
local foo = {}

---@deprecated
---@type string
foo.example2 = nil

print(foo)
print(foo.example) -- cant mark as deprecated
print(foo.example2)


---@class foo2
---@deprecated -- breaks the local class declaration, and does nothing
---@field example string -- field must be defined after class
local foo = {}

---@deprecated
---@type string
foo.example2 = nil

print(foo)
print(foo.example) -- cant mark as deprecated
print(foo.example2)


---@class foo3
---@field example string
---@deprecated -- breaks the local class declaration, and does nothing
local foo = {}

---@deprecated
---@type string
foo.example2 = nil

print(foo)
print(foo.example) -- cant mark as deprecated
print(foo.example2)


---@deprecated
---@class gfoo
---@field example string
gfoo = {}

---@deprecated
---@type string
gfoo.example2 = nil

print(gfoo)
print(gfoo.example) -- cant mark as deprecated
print(gfoo.example2) -- deprecated as expected, but the whole class deprecated, so field is skipped visually


---@class gfoo2
---@deprecated -- still works for class
---@field example string -- field must be defined after class
gfoo = {}

---@deprecated
---@type string
gfoo.example2 = nil

print(gfoo)
print(gfoo.example) -- cant mark as deprecated
print(gfoo.example2) -- deprecated as expected, but the whole class deprecated, so field is skipped visually


---@class gfoo3
---@field example string
---@deprecated -- still works for class
gfoo = {}

---@deprecated
---@type string
gfoo.example2 = nil

print(gfoo)
print(gfoo.example) -- cant mark as deprecated
print(gfoo.example2) -- deprecated as expected, but the whole class deprecated, so field is skipped visually

Image

Image

@tomlau10
Copy link
Contributor

tomlau10 commented Feb 4, 2025

From luals wiki, the @deprecated only (officially) supports marking functions: https://luals.github.io/wiki/annotations/#deprecated

Though it works on table fields to some extend:

---@class foo
---@field example string
local foo = {}
foo.example = nil   ---@deprecated this is the deprecate msg

print(foo.example)  --> Deprecated.(this is the deprecate msg)
--> no need @type, it's already `(field) foo.example: string`

However there is another greater problem 😕

  • if that field has another assignment statement without the @deprecate
  • => the whole field becomes non-deprecate ...
---@class foo
---@field example string
local foo = {}
foo.example = nil   ---@deprecated this is the deprecate msg

print(foo.example)  --> the deprecate warning is gone ...

-- because the follow assignment statement to that field doesn't have @deprecate
foo.example = nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

6 participants