Skip to content

Commit dff85c0

Browse files
ematipicodyc3
andauthored
fix(lsp): unsafe fixes when pulling code actions (#7249)
Co-authored-by: dyc3 <1808807+dyc3@users.noreply.github.com>
1 parent 67b4224 commit dff85c0

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

.changeset/fancy-plants-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#748](https://github.com/biomejs/biome-vscode/issues/748), where Biome Language Server didn't show the unsafe fixes when requesting the quick fixes. Now all LSP editors will show also opt-in, unsafe fixes.

crates/biome_lsp/src/handlers/analysis.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use biome_analyze::{
88
SUPPRESSION_TOP_LEVEL_ACTION_CATEGORY, SourceActionKind,
99
};
1010
use biome_configuration::analyzer::RuleSelector;
11-
use biome_diagnostics::{Applicability, Error};
11+
use biome_diagnostics::Error;
1212
use biome_fs::BiomePath;
1313
use biome_line_index::LineIndex;
1414
use biome_lsp_converters::from_proto;
@@ -100,17 +100,13 @@ pub(crate) fn code_actions(
100100
}
101101

102102
let mut has_fix_all = false;
103-
let mut has_quick_fix = false;
104103
let mut filters = Vec::new();
105104
if let Some(filter) = &params.context.only {
106105
for kind in filter {
107106
let kind = kind.as_str();
108107
if FIX_ALL_CATEGORY.matches(kind) {
109108
has_fix_all = true;
110109
}
111-
if kind == "quickfix.biome" {
112-
has_quick_fix = true;
113-
}
114110
filters.push(kind);
115111
}
116112
}
@@ -202,16 +198,6 @@ pub(crate) fn code_actions(
202198
&action.category, &action.suggestion.applicability
203199
);
204200

205-
// Skip quick fixes that have unsafe code fixes
206-
if has_quick_fix && action.suggestion.applicability == Applicability::MaybeIncorrect {
207-
return None;
208-
}
209-
210-
if action.category.matches("quickfix.biome")
211-
&& action.suggestion.applicability == Applicability::MaybeIncorrect
212-
{
213-
return None;
214-
}
215201
// Filter out source.organizeImports.biome action when assist is not supported.
216202
if action.category.matches("source.organizeImports.biome")
217203
&& !file_features.supports_assist()

crates/biome_lsp/src/server.tests.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ async fn pull_biome_quick_fixes() -> Result<()> {
14951495
}
14961496

14971497
#[tokio::test]
1498-
async fn pull_quick_fixes_not_include_unsafe() -> Result<()> {
1498+
async fn pull_quick_fixes_include_unsafe() -> Result<()> {
14991499
let factory = ServerFactory::default();
15001500
let (service, client) = factory.create().into_inner();
15011501
let (stream, sink) = client.split();
@@ -1647,7 +1647,7 @@ async fn pull_quick_fixes_not_include_unsafe() -> Result<()> {
16471647
let expected_toplevel_suppression_action = CodeActionOrCommand::CodeAction(CodeAction {
16481648
title: String::from("Suppress rule lint/suspicious/noDoubleEquals for the whole file."),
16491649
kind: Some(CodeActionKind::new("quickfix.suppressRule.topLevel.biome")),
1650-
diagnostics: Some(vec![unsafe_fixable]),
1650+
diagnostics: Some(vec![unsafe_fixable.clone()]),
16511651
edit: Some(WorkspaceEdit {
16521652
changes: Some(top_level_changes),
16531653
document_changes: None,
@@ -1659,9 +1659,44 @@ async fn pull_quick_fixes_not_include_unsafe() -> Result<()> {
16591659
data: None,
16601660
});
16611661

1662+
let mut unsafe_action_changes = HashMap::default();
1663+
unsafe_action_changes.insert(
1664+
uri!("document.js"),
1665+
vec![TextEdit {
1666+
range: Range {
1667+
start: Position {
1668+
line: 0,
1669+
character: 7,
1670+
},
1671+
end: Position {
1672+
line: 0,
1673+
character: 7,
1674+
},
1675+
},
1676+
new_text: String::from("="),
1677+
}],
1678+
);
1679+
let unsafe_action = CodeActionOrCommand::CodeAction(CodeAction {
1680+
title: String::from("Use === instead."),
1681+
kind: Some(CodeActionKind::new(
1682+
"quickfix.biome.suspicious.noDoubleEquals",
1683+
)),
1684+
diagnostics: Some(vec![unsafe_fixable]),
1685+
edit: Some(WorkspaceEdit {
1686+
changes: Some(unsafe_action_changes),
1687+
document_changes: None,
1688+
change_annotations: None,
1689+
}),
1690+
command: None,
1691+
is_preferred: None,
1692+
disabled: None,
1693+
data: None,
1694+
});
1695+
16621696
assert_eq!(
16631697
res,
16641698
vec![
1699+
unsafe_action,
16651700
expected_inline_suppression_action,
16661701
expected_toplevel_suppression_action,
16671702
]

0 commit comments

Comments
 (0)