fix(parser): Support cond generic literals true, false, and nil.#976
fix(parser): Support cond generic literals true, false, and nil.#976xuhuanzy wants to merge 1 commit intoEmmyLuaLs:mainfrom
true, false, and nil.#976Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the EmmyLua parser to support Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to add parser support for true, false, and nil as literals in conditional generics. The changes are a good step in the right direction. I've left a couple of specific comments on the code.
Most importantly, the implementation appears to be incomplete. While the lexer is updated to produce a TkNil token, the parser in crates/emmylua_parser/src/grammar/doc/types.rs (specifically parse_primary_type) does not seem to be updated to handle this token as a literal type. This will likely cause parsing to fail when nil is used.
Additionally, the new test case only covers true, and it would be beneficial to expand it to cover false and nil to fully validate the feature. There's also an opportunity to reduce some code duplication in the lexer. Please see my detailed comments.
| fn test_extends_true() { | ||
| let mut ws = VirtualWorkspace::new(); | ||
| assert!(ws.check_code_for( | ||
| DiagnosticCode::TypeNotFound, | ||
| r#" | ||
| ---@alias TestA<T> T extends "test" and number or string | ||
| ---@alias TestB<T> T extends true and number or string | ||
| ---@alias TestC<T> T extends 111 and number or string | ||
| "#, | ||
| )); | ||
| } |
There was a problem hiding this comment.
The test name test_extends_true is a bit specific given it also tests string and number literals. To fully validate the changes in this PR, which aims to support true, false, and nil, it would be beneficial to expand this test to include cases for false and nil as well. Also, consider renaming the test to something more general like test_extends_literal.
Here's a suggested update:
#[test]
fn test_extends_literal() {
let mut ws = VirtualWorkspace::new();
assert!(ws.check_code_for(
DiagnosticCode::TypeNotFound,
r#"
---@alias TestA<T> T extends "test" and number or string
---@alias TestB<T> T extends true and number or string
---@alias TestC<T> T extends 111 and number or string
---@alias TestD<T> T extends false and number or string
---@alias TestE<T> T extends nil and number or string
"#,
));
}Note that for the nil case to pass, the parser will also need to be updated to recognize TkNil as a literal type, which seems to be missing from this PR.
#[test]
fn test_extends_literal() {
let mut ws = VirtualWorkspace::new();
assert!(ws.check_code_for(
DiagnosticCode::TypeNotFound,
r#"
---@alias TestA<T> T extends "test" and number or string
---@alias TestB<T> T extends true and number or string
---@alias TestC<T> T extends 111 and number or string
---@alias TestD<T> T extends false and number or string
---@alias TestE<T> T extends nil and number or string
"#,
));
}
No description provided.