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

more emmylua enhancements #1457

Open
4 of 10 tasks
somebody1234 opened this issue Aug 11, 2022 · 8 comments
Open
4 of 10 tasks

more emmylua enhancements #1457

somebody1234 opened this issue Aug 11, 2022 · 8 comments
Labels
enhancement New feature or request
Milestone

Comments

@somebody1234
Copy link

somebody1234 commented Aug 11, 2022

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

  • (if possible) support for nice highlighting for ffi.cdef([[]]), not just the version without parens
    • (edit: i don't think it's reasonable, seems like it's the builtin highlighting that's doing this)
  • erroring on string + anything, table + anything, anything + string, anything + table
  • adding enum members to autocomplete
  • taking into account the implicit return at the end of a function, into the signature:
-- inferred: nil, string (incorrect)
local function bad()
  if 0 > 0 then return nil, "an error" end
end
-- inferred: nil, string | nil (correct), however:
local function bad()
  if 0 > 0 then return nil, "an error" end
  return -- marked as a redundant return
end
  • keeping warning about missing return value for these cases:
    • i realize this may be disabled because the user might still be writing the function, but i'd prefer it if it always has the warning, so i can be sure that 0 warnings === it's definitely going to run correctly. so maybe it could be an option
function foo()
end
function foo() end
  • 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)
  • better typechecking in general? examples:
--- @class foo
--- @class bar

--- @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:
--- @class foo
function f()
end
  • 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
  • disallowing comparisons between incompatible types
    • i understand this may be hard, but imo it's useful even in a simple form - e.g. checking if unions have no members that are compatible with each other (somehow...?)
      • in my specific case it's just between string|string[] and number so even just handling it only for primitives and arrays would be quite helpful
  • recursive types (not necessarily generic) - in my case i have an @alias tree_node table<string, tree_leaf | tree_node>
  • allow @type my_function_alias as an alternative to @param + @return
    • this may be useful for e.g. request handlers for a web framework fun(req: request, res: response): nil
    • it seems to kind of work for local foo = function and local function foo. doesn't seem to work for return function
      • by "kind of work" - the type of the variable seems to be fine, but it doesn't copy the argument types to the function definition:
--- @type fun(a: integer, b: integer): nil
local function foo(a, b)
  --               ^  ^ a: any, b: any
end
  • check for missing properties - for example this currently shows no warnings:
--- @type { a: number, b: string }
local foo = {}
  • i understand that this may be difficult to do in some cases, but like above, i think even partial support (comparing type to shape at the end of scope, or type at return, etc) would go a long way
@sumneko sumneko added the enhancement New feature or request label Aug 11, 2022
@somebody1234
Copy link
Author

somebody1234 commented Aug 29, 2022

(added a new suggestion)

@sumneko sumneko added this to the 3.6.0 milestone Sep 19, 2022
@sumneko
Copy link
Collaborator

sumneko commented Sep 19, 2022

  • @class suppresses "global variable in lowercase initial" warning:

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

@somebody1234
Copy link
Author

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
Copy link
Collaborator

sumneko commented Sep 20, 2022

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
Copy link
Collaborator

sumneko commented Nov 4, 2022

  • 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
Copy link
Collaborator

sumneko commented Nov 4, 2022

  • @class suppresses "global variable in lowercase initial" warning:
--- @class foo
function f()
end

As design

@sumneko
Copy link
Collaborator

sumneko commented Nov 4, 2022

[ ] 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 added a commit that referenced this issue Nov 4, 2022
@sumneko
Copy link
Collaborator

sumneko commented Nov 7, 2022

  • 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

@sumneko sumneko modified the milestones: 3.6.0, 3.7.0 Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants