Skip to content

update - #1017

Merged
CppCXY merged 37 commits into
EmmyLuaLs:mainfrom
xuhuanzy:fix
May 6, 2026
Merged

update#1017
CppCXY merged 37 commits into
EmmyLuaLs:mainfrom
xuhuanzy:fix

Conversation

@xuhuanzy

@xuhuanzy xuhuanzy commented Apr 5, 2026

Copy link
Copy Markdown
Member
  1. refactor(visibility): improve type visibility #1004
  2. constructor特性第四个参数从return_self更改为return_mode以支持返回值使用泛型
  3. 泛型参数现在支持默认值
---@class A<T = number>
---@class B<T : number = number>
---@class C<T extends number = number> -- `extends` 关键词等效于 `:`, 但更清晰且更容易被大模型识别
  1. 条件类型完善, 现在条件类型的行为更接近 TS 了

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant changes to the EmmyLua analysis engine, including a new module visibility system, improved workspace path configuration, and a new diagnostic check for inconsistent type access modifiers. The export tag has been removed in favor of a more robust visibility system. I have reviewed the changes and suggest removing the commented-out code block in crates/emmylua_code_analysis/src/compilation/analyzer/doc/property_tags.rs to maintain code cleanliness.

Comment on lines +28 to +38
// 返回变量不能附加可见性
// LuaExpr::NameExpr(name_expr) => {
// let name = name_expr.get_name_text()?;
// let tree = analyzer
// .db
// .get_decl_index()
// .get_decl_tree(&analyzer.file_id)?;
// let decl = tree.find_local_decl(&name, name_expr.get_position())?;

// Some(LuaSemanticDeclId::LuaDecl(decl.get_id()))
// }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code is commented out. If it's no longer needed, it should be removed to improve code clarity.

@xuhuanzy xuhuanzy linked an issue Apr 6, 2026 that may be closed by this pull request
Extends generic declarations to support `= default` syntax and tokenization.

Splits generic parsing into constraint vs default type accessors so type inference uses only constraints and ignores defaults, preventing misinterpreting defaults as bounds.

Adds parser and syntax-level tests to cover default types and combined constraint+default cases.
@xuhuanzy xuhuanzy linked an issue Apr 30, 2026 that may be closed by this pull request
@CppCXY
CppCXY merged commit da58e0d into EmmyLuaLs:main May 6, 2026
16 checks passed
@clason

clason commented May 6, 2026

Copy link
Copy Markdown
Contributor

f407e4b introduced a regression that persists on HEAD. The commit message is meaningless to me unfortunately, but I now get a slew of warnings on nvim-treesitter like

-- lua/nvim-treesitter/util.lua [2 warnings]
warning: expected `string? ...` but found `string?`.  [param-type-mismatch]
  -->: lua/nvim-treesitter/util.lua:6:23

  5 │ function M.read_file(filename)
  6 │   local file = assert(io.open(filename, 'r'))
  7 │   local r = file:read('*a')

warning: expected `string? ...` but found `string?`.  [param-type-mismatch]
  -->: lua/nvim-treesitter/util.lua:15:23

  14 │ function M.write_file(filename, content)
  15 │   local file = assert(io.open(filename, 'w'))
  16 │   file:write(content)

@lewis6991

@xuhuanzy

xuhuanzy commented May 6, 2026

Copy link
Copy Markdown
Member Author

@clason This is a breaking change. Earlier, I mistakenly treated extends Type as a default value constraint, but now it must be written in a syntax similar to TypeScript's extends Type = Type. I think this might be the issue.
Could you provide some reproduction code?

@clason

clason commented May 6, 2026

Copy link
Copy Markdown
Contributor

https://github.com/nvim-treesitter/nvim-treesitter

It's enough to clone this repo and run VIMRUNTIME=/usr/local/share/nvim/runtime/ emmylua_check . at the root (assuming you have Neovim installed to /usr/local; adjust to taste, e.g., point the VIMRUNTIME variable to a local clone of https://github.com/neovim/neovim instead of /usr/local/share/nvim).

I am not aware of using type extensions at all.

@xuhuanzy

xuhuanzy commented May 6, 2026

Copy link
Copy Markdown
Member Author

f407e4b introduced a regression that persists on HEAD. The commit message is meaningless to me unfortunately, but I now get a slew of warnings on nvim-treesitter like

This issue has nothing to do with generics.

--- @type string?
local message

--- @param ... (string?) ...
function test(...) end

test(message)

@clason

clason commented May 6, 2026

Copy link
Copy Markdown
Contributor

That may be (and what I assume); nevertheless, I bisected the regression to that commit. Note that the examples I listed deliberately do not involve any user-defined functions; only LuaJIT builtins that emmyluals defines the annotations for.

@CppCXY

CppCXY commented May 6, 2026

Copy link
Copy Markdown
Member

That may be (and what I assume); nevertheless, I bisected the regression to that commit. Note that the examples I listed deliberately do not involve any user-defined functions; only LuaJIT builtins that emmyluals defines the annotations for.

I have time to look into this issue; by the way, why this project was archived?

@clason

clason commented May 6, 2026

Copy link
Copy Markdown
Contributor

why this project was archived?

Long story I don't want to go much into right now; some people were very vocal in their dislike of the way I handled things, and I didn't want to have to deal with that anymore. The important thing is that it's still available and doing what it was designed to do.

@xuhuanzy

xuhuanzy commented May 6, 2026

Copy link
Copy Markdown
Member Author

f407e4b introduced a regression that persists on HEAD. The commit message is meaningless to me unfortunately, but I now get a slew of warnings on nvim-treesitter like

Confirmed it's a generic issue. A long time ago, I used a workaround to treat all such cases as 'any', and this operation has been removed in this commit.

--- @type string?
local message

--- @param ... (string?) ...
function test(...) end

test(message)

This is an incorrect notation; ---@param ... (string?) ... should not appear. ... should only appear after generics. I am considering whether to add a diagnostic or simply remove the ... keyword, as its semantics are highly unintuitive and cause many processing difficulties.

@lewis6991

Copy link
Copy Markdown
Collaborator

... should be a keyword. How else would you type annotate varargs?

@xuhuanzy

xuhuanzy commented May 6, 2026

Copy link
Copy Markdown
Member Author

... should be a keyword. How else would you type annotate varargs?

I am referring to T..., and currently, the handling of T... is very confusing. Please refer to fn test_variadic_base().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants