mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(lsp): prefer cache over tsc quick fixes (#23093)
This commit is contained in:
parent
34a651ea2e
commit
e1e1da2a04
2 changed files with 17 additions and 13 deletions
|
@ -647,6 +647,10 @@ fn is_preferred(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
} else if let CodeActionKind::Deno(_) = i {
|
||||||
|
// This is to make sure 'Remove import' isn't preferred over 'Cache
|
||||||
|
// dependencies'.
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -1031,18 +1035,18 @@ impl CodeActionCollection {
|
||||||
|
|
||||||
/// Move out the code actions and return them as a `CodeActionResponse`.
|
/// Move out the code actions and return them as a `CodeActionResponse`.
|
||||||
pub fn get_response(self) -> lsp::CodeActionResponse {
|
pub fn get_response(self) -> lsp::CodeActionResponse {
|
||||||
// Prefer TSC fixes first, then Deno fixes, then Deno lint fixes.
|
// Prefer Deno fixes first, then TSC fixes, then Deno lint fixes.
|
||||||
let (tsc, rest): (Vec<_>, Vec<_>) = self
|
let (deno, rest): (Vec<_>, Vec<_>) = self
|
||||||
.actions
|
.actions
|
||||||
.into_iter()
|
|
||||||
.partition(|a| matches!(a, CodeActionKind::Tsc(..)));
|
|
||||||
let (deno, deno_lint): (Vec<_>, Vec<_>) = rest
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.partition(|a| matches!(a, CodeActionKind::Deno(_)));
|
.partition(|a| matches!(a, CodeActionKind::Deno(_)));
|
||||||
|
let (tsc, deno_lint): (Vec<_>, Vec<_>) = rest
|
||||||
tsc
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(deno)
|
.partition(|a| matches!(a, CodeActionKind::Tsc(..)));
|
||||||
|
|
||||||
|
deno
|
||||||
|
.into_iter()
|
||||||
|
.chain(tsc)
|
||||||
.chain(deno_lint)
|
.chain(deno_lint)
|
||||||
.map(|k| match k {
|
.map(|k| match k {
|
||||||
CodeActionKind::Deno(c) => lsp::CodeActionOrCommand::CodeAction(c),
|
CodeActionKind::Deno(c) => lsp::CodeActionOrCommand::CodeAction(c),
|
||||||
|
|
|
@ -4698,18 +4698,18 @@ fn test_lsp_code_actions_ordering() {
|
||||||
}
|
}
|
||||||
let res = serde_json::to_value(actions).unwrap();
|
let res = serde_json::to_value(actions).unwrap();
|
||||||
|
|
||||||
// Ensure ordering is "deno-ts" -> "deno" -> "deno-lint".
|
// Ensure ordering is "deno" -> "deno-ts" -> "deno-lint".
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
json!([
|
json!([
|
||||||
{
|
|
||||||
"title": "Add async modifier to containing function",
|
|
||||||
"source": "deno-ts",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"title": "Cache \"https://deno.land/x/a/mod.ts\" and its dependencies.",
|
"title": "Cache \"https://deno.land/x/a/mod.ts\" and its dependencies.",
|
||||||
"source": "deno",
|
"source": "deno",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"title": "Add async modifier to containing function",
|
||||||
|
"source": "deno-ts",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"title": "Disable prefer-const for this line",
|
"title": "Disable prefer-const for this line",
|
||||||
"source": "deno-lint",
|
"source": "deno-lint",
|
||||||
|
|
Loading…
Reference in a new issue