Skip to content

Commit fe243b1

Browse files
Fix extract action for python (#1207)
- Fixes #461 ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet Co-authored-by: Andreas Arvidsson <[email protected]>
1 parent c2e930f commit fe243b1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/ide/vscode/VscodeTextEditorImpl.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,21 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
193193
}
194194

195195
public async extractVariable(_range?: Range): Promise<void> {
196-
await vscode.commands.executeCommand("editor.action.codeAction", {
197-
kind: "refactor.extract.constant",
198-
preferred: true,
199-
});
196+
if (this.document.languageId === "python") {
197+
// Workaround for https://github.com/microsoft/vscode-python/issues/20455
198+
await vscode.commands.executeCommand("editor.action.codeAction", {
199+
kind: "refactor.extract",
200+
});
201+
await sleep(250);
202+
await vscode.commands.executeCommand("selectNextCodeAction");
203+
await vscode.commands.executeCommand("acceptSelectedCodeAction");
204+
} else {
205+
await vscode.commands.executeCommand("editor.action.codeAction", {
206+
kind: "refactor.extract.constant",
207+
preferred: true,
208+
});
209+
}
210+
211+
await sleep(250);
200212
}
201213
}

0 commit comments

Comments
 (0)