summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-09-17 20:05:19 +0200
committerGitHub <noreply@github.com>2023-09-17 19:05:19 +0100
commit4fcd9a0de815a756e5f173e1bc1f84d90ba39ec7 (patch)
treefe7b0f45fa818b1af8857e72f844683a0c7527a9 /cli/lsp
parent81d6ea8e1174d2b74c2a4806eaf279115cb3068f (diff)
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 <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/analysis.rs22
1 files changed, 20 insertions, 2 deletions
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),