Skip to content

Conversation

ribru17
Copy link
Contributor

@ribru17 ribru17 commented Mar 23, 2025

This commit makes it so that diagnostic checkers no longer have to define magic public variables which will be called by a macro. Instead, they all implement a common trait which will easily enforce that all the checking data is defined. This also means compile errors will be quicker and more understandable.

This commit makes it so that diagnostic checkers no longer have to
define magic public variables which will be called by a macro. Instead,
they all implement a common trait which will easily enforce that all the
checking data is defined. This also means compile errors will be quicker and
more understandable.
@CppCXY
Copy link
Member

CppCXY commented Mar 23, 2025

When I first designed the checker, I essentially structured it in this way. The current question is whether I should redesign the checker in an oo style, and if there are other linter examples that make this change more compelling.

@ribru17
Copy link
Contributor Author

ribru17 commented Mar 23, 2025

In my opinion it makes more sense this way, but it is your decision of course. The previous macro way was essentially just manually specifying what the compiler would do anyway (with a trait)

let file_id = context.get_file_id();
let diagnostic_index = db.get_diagnostic_index();
let Some(diagnostics) = diagnostic_index.get_diagnostics(&file_id) else {
return;
Copy link
Member

Choose a reason for hiding this comment

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

Why remove Option<()>? That way I can’t '?'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but generally returning nothing is better because option introduces added complexity (must use unwrap, is_some, etc.). It doesn't make sense just to add a pointless option return value for this syntax, especially since we can just return early like in the above. Option should be used if it makes semantic sense

@CppCXY
Copy link
Member

CppCXY commented Mar 24, 2025

I referred to Clippy, which has a very similar structure, and perhaps this makes sense.
https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lifetimes.rs

@CppCXY CppCXY merged commit fefd3e5 into EmmyLuaLs:main Mar 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants