From 4fcd9a0de815a756e5f173e1bc1f84d90ba39ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 17 Sep 2023 20:05:19 +0200 Subject: fix(lsp): sort quickfix actions (#17221) This commit changes ordering of quickfix actions, by sorting them in following order: - TSC fixes - Deno fixes - deno_lint fixes Co-authored-by: Nayeem Rahman --- cli/lsp/analysis.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index ec279022d..808f09dec 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -848,8 +848,26 @@ impl CodeActionCollection { /// Move out the code actions and return them as a `CodeActionResponse`. pub fn get_response(self) -> lsp::CodeActionResponse { - self - .actions + let mut actions = self.actions; + + // Prefer TSC fixes first, then Deno fixes, then Deno lint fixes. + actions.sort_by(|a, b| match (a, b) { + (CodeActionKind::Deno(a), CodeActionKind::Deno(b)) => { + a.title.cmp(&b.title) + } + (CodeActionKind::DenoLint(a), CodeActionKind::DenoLint(b)) => { + a.title.cmp(&b.title) + } + (CodeActionKind::Tsc(a, _), CodeActionKind::Tsc(b, _)) => { + a.title.cmp(&b.title) + } + (CodeActionKind::Tsc(_, _), _) => Ordering::Less, + (CodeActionKind::Deno(_), CodeActionKind::Tsc(_, _)) => Ordering::Greater, + (CodeActionKind::Deno(_), CodeActionKind::DenoLint(_)) => Ordering::Less, + (CodeActionKind::DenoLint(_), _) => Ordering::Greater, + }); + + actions .into_iter() .map(|i| match i { CodeActionKind::Tsc(c, _) => lsp::CodeActionOrCommand::CodeAction(c), -- cgit v1.2.3