From 731cd23ec82385ea64bb2ab4811e0d8ebca30812 Mon Sep 17 00:00:00 2001 From: Joseph Liu Date: Fri, 29 Aug 2025 22:50:23 -0400 Subject: [PATCH] dev: fix lint warnings introduced by #2062 (#2096) > Hm. Sorry about the lint failures here, they slipped my attention locally since they show up as warnings, not errors, in my editor. I'm happy to put a PR fixing them later unless you get to it first. > > Not too sure how to deal with the unused DiagWorker::check method, since it is used, just in a test-only module. We can certainly mark it as #[cfg(test)] but that feels a little nasty. https://github.com/Myriad-Dreamin/tinymist/pull/2062#issuecomment-3237812684 I ended up inlining the logic of `DiagWorker::check` into the test. --- crates/tinymist-query/src/check.rs | 2 +- crates/tinymist-query/src/code_action.rs | 18 ++++++++++++------ crates/tinymist-query/src/diagnostics.rs | 10 +--------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/crates/tinymist-query/src/check.rs b/crates/tinymist-query/src/check.rs index 58155f4e..c8d90180 100644 --- a/crates/tinymist-query/src/check.rs +++ b/crates/tinymist-query/src/check.rs @@ -14,6 +14,6 @@ impl SemanticRequest for CheckRequest { fn request(self, ctx: &mut LocalContext) -> Option { let worker = DiagWorker::new(ctx); - Some(worker.full_check().convert_all(self.snap.diagnostics())) + Some(worker.check().convert_all(self.snap.diagnostics())) } } diff --git a/crates/tinymist-query/src/code_action.rs b/crates/tinymist-query/src/code_action.rs index 568175bd..6f8247c9 100644 --- a/crates/tinymist-query/src/code_action.rs +++ b/crates/tinymist-query/src/code_action.rs @@ -126,14 +126,20 @@ mod tests { source: &Source, request_range: &LspRange, ) -> CodeActionContext { - let Warned { output, warnings } = typst::compile::(&ctx.world); - let errors = output.err().unwrap_or_default(); - let compiler_diagnostics = warnings.iter().chain(errors.iter()); + let Warned { + output, + warnings: compiler_warnings, + } = typst::compile::(&ctx.world); + let compiler_errors = output.err().unwrap_or_default(); - // Run the linter for additional diagnostics as well. + let lint_warnings = ctx.lint(source); let diagnostics = DiagWorker::new(ctx) - .check(source) - .convert_all(compiler_diagnostics) + .convert_all( + compiler_errors + .iter() + .chain(compiler_warnings.iter()) + .chain(lint_warnings.iter()), + ) .into_values() .flatten(); diff --git a/crates/tinymist-query/src/diagnostics.rs b/crates/tinymist-query/src/diagnostics.rs index 9824bce0..c376064e 100644 --- a/crates/tinymist-query/src/diagnostics.rs +++ b/crates/tinymist-query/src/diagnostics.rs @@ -46,16 +46,8 @@ impl<'w> DiagWorker<'w> { } } - /// Runs code check on the given document. - pub fn check(mut self, source: &Source) -> Self { - for diag in self.ctx.lint(&source) { - self.handle(&diag); - } - self - } - /// Runs code check on the main document and all its dependencies. - pub fn full_check(mut self) -> Self { + pub fn check(mut self) -> Self { for dep in self.ctx.world.depended_files() { if WorkspaceResolver::is_package_file(dep) { continue;