Skip to content

Commit 3f64a97

Browse files
committed
lsp: scope fix-all actions to pyrefly kind
Code action save hooks currently require enabling generic source.fixAll, which can trigger unrelated servers. This change advertises and emits source.fixAll.pyrefly so editors can target pyrefly-only fix-all behavior.\n\nThe code action filter now accepts both source.fixAll and source.fixAll.* requests so parent-kind clients remain compatible while pyrefly-specific requests are supported.
1 parent 1a9b680 commit 3f64a97

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

pyrefly/lib/lsp/non_wasm/server.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ pub fn capabilities(
11421142
CodeActionKind::new("refactor.delete"),
11431143
CodeActionKind::new("refactor.move"),
11441144
CodeActionKind::REFACTOR_INLINE,
1145-
CodeActionKind::SOURCE_FIX_ALL,
1145+
CodeActionKind::new(SOURCE_FIX_ALL_PYREFLY),
11461146
]),
11471147
..Default::default()
11481148
})),
@@ -1252,6 +1252,7 @@ pub enum ProcessEvent {
12521252
}
12531253

12541254
const PYTHON_SECTION: &str = "python";
1255+
const SOURCE_FIX_ALL_PYREFLY: &str = "source.fixAll.pyrefly";
12551256

12561257
struct TypeHierarchyTarget {
12571258
def_index: ClassDefIndex,
@@ -4171,9 +4172,12 @@ impl Server {
41714172
let allow_quickfix = only_kinds
41724173
.is_none_or(|kinds| kinds.iter().any(|kind| kind == &CodeActionKind::QUICKFIX));
41734174
let allow_fix_all = only_kinds.is_none_or(|kinds| {
4174-
kinds
4175-
.iter()
4176-
.any(|kind| kind == &CodeActionKind::SOURCE_FIX_ALL)
4175+
kinds.iter().any(|kind| {
4176+
kind == &CodeActionKind::SOURCE_FIX_ALL
4177+
|| kind
4178+
.as_str()
4179+
.starts_with(CodeActionKind::SOURCE_FIX_ALL.as_str())
4180+
})
41774181
});
41784182
let allow_refactor = only_kinds.is_none_or(|kinds| {
41794183
kinds
@@ -4276,7 +4280,7 @@ impl Server {
42764280
if !changes.is_empty() {
42774281
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
42784282
title: "Remove all redundant casts".to_owned(),
4279-
kind: Some(CodeActionKind::SOURCE_FIX_ALL),
4283+
kind: Some(CodeActionKind::new(SOURCE_FIX_ALL_PYREFLY)),
42804284
edit: Some(WorkspaceEdit {
42814285
changes: Some(changes),
42824286
..Default::default()

pyrefly/lib/test/lsp/lsp_interaction/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn test_initialize_basic() {
3636
"definitionProvider": true,
3737
"typeDefinitionProvider": true,
3838
"codeActionProvider": {
39-
"codeActionKinds": ["quickfix", "refactor.extract", "refactor.rewrite", "refactor.delete", "refactor.move", "refactor.inline", "source.fixAll"]
39+
"codeActionKinds": ["quickfix", "refactor.extract", "refactor.rewrite", "refactor.delete", "refactor.move", "refactor.inline", "source.fixAll.pyrefly"]
4040
},
4141
"codeLensProvider": {
4242
"resolveProvider": false,

0 commit comments

Comments
 (0)