LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.34k stars 317 forks source link

more emmylua enhancements #1457

Open somebody1234 opened 2 years ago

somebody1234 commented 2 years ago

(it's okay to close this if they're not possible, just wondering if they're possible)

--- @param foo foo local function fn(foo) end --- @param foos foo[] local function fn2(foos) end local f --- @type foo local b --- @type bar fn(f) -- ok fn(b) -- error fn({ f }) -- ok (incorrect) fn2({ f }) -- ok fn2(f) -- ok (incorrect) fn2(b) -- ok (incorrect)

- `@class` suppresses "global variable in lowercase initial" warning:
```lua
--- @class foo
function f()
end
somebody1234 commented 2 years ago

(added a new suggestion)

sumneko commented 2 years ago
  • @class suppresses "global variable in lowercase initial" warning:

Do you want ---@class do not suppress warnings?

somebody1234 commented 2 years ago

on second thought, i guess it depends? so maybe an option may be the way to go here... or just treat it as [wontfix]

it's just something i noticed, i usually use modules so in my case at least, there should never ever be global variables

sumneko commented 2 years ago

on second thought, i guess it depends? so maybe an option may be the way to go here... or just treat it as [wontfix]

it's just something i noticed, i usually use modules so in my case at least, there should never ever be global variables

You can try to color global variables with striking color with server on latest master:

// color global variables to red
"editor.semanticTokenColorCustomizations": {
    "rules": {
        "variable.global": "#ff0000"
    }
}

It can also set font style.

sumneko commented 1 year ago
  • retaining flow typing for declarations with initializers:
--- @type foo | nil
local x
x = { foo = 1 }
x.foo -- works
--- @type foo | nil
local x = { foo = 1 }
x.foo -- need check nil (| nil overrides flow typing from the initializer)

Won't fix

sumneko commented 1 year ago
  • [ ] @class suppresses "global variable in lowercase initial" warning:
--- @class foo
function f()
end

As design

sumneko commented 1 year ago

[ ] recursive types (not necessarily generic) - in my case i have an @alias tree_node table<string, tree_leaf | tree_node>

Alias need to be expanded, so I can not support recursive alias.

sumneko commented 1 year ago
  • disallowing assigning decimal literals to integer variables, and numbers to different numbers (it already does this between string/number/table/string literals/integer literals etc.):

    • [ ] i guess the real issue is not having decimal literal types?
--- @type integer
local foo = 1.1
--- @type 10
local foo = 1.1 -- this should error at least

You need set Lua.type.castNumberToInteger to false