I think the way we provide the Quick Fixes might lead to performance issues. So far, it seems to be fine. But I'm not sure how much current implementation will scale.
If you experienced performance issues because of the extension, please let us know here 🙏
Details
Today, each Quick Fix is independent.
To tell VS Code if it should propose a refactoring as a Quick Fix, we traverse the code, check if the refactoring could be made from current selection, and tell VS Code if we can.
Example of such behavior, implemented in action-provider.ts
:
|
public provideCodeActions( |
|
document: vscode.TextDocument, |
|
range: vscode.Range | vscode.Selection |
|
): vscode.ProviderResult<vscode.CodeAction[]> { |
|
const code = document.getText(); |
|
const selection = createSelectionFromVSCode(range); |
|
|
|
if (!hasTernaryToConvert(code, selection)) return; |
|
|
|
const action = new vscode.CodeAction( |
|
"✨ Convert ternary to if/else", |
|
this.kind |
|
); |
|
action.isPreferred = false; |
|
action.command = { |
|
command: commandKey, |
|
title: "Convert Ternary to If/Else" |
|
}; |
|
|
|
return [action]; |
|
} |
|
function hasTernaryToConvert(code: Code, selection: Selection): boolean { |
|
return updateCode(code, selection).hasCodeChanged; |
|
} |
The performance problem would be due to the fact that each refactoring parses, traverses and transforms the AST. At some point, this could be too much.
If this is confirmed, the solution would be to traverse the AST less. Ideally, we would traverse it once and try to figure out what list of refactorings could be performed from that.
The challenge would be to provide individual action providers to VS Code. That's why current implementation is very naive, so every refactoring is independent—which simplifies development a lot!
But until we got actual confirmation that this is a concern, we'll keep current implementation. #makeItWork #makeItRight #makeItFast