mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Hook up basic alert of why a code action could not be applied
For #85160
This commit is contained in:
@@ -238,9 +238,14 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.convertApplicableRefactors(response.body, document, rangeOrSelection);
|
||||
const actions = this.convertApplicableRefactors(response.body, document, rangeOrSelection);
|
||||
if (!context.only) {
|
||||
return actions;
|
||||
}
|
||||
return this.appendInvalidActions(actions);
|
||||
}
|
||||
|
||||
|
||||
private convertApplicableRefactors(
|
||||
body: Proto.ApplicableRefactorInfo[],
|
||||
document: vscode.TextDocument,
|
||||
@@ -305,6 +310,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private appendInvalidActions(actions: vscode.CodeAction[]): vscode.CodeAction[] {
|
||||
if (!actions.some(action => action.kind && Extract_Constant.kind.contains(action.kind))) {
|
||||
const disabledAction = new vscode.CodeAction('Extract to constant', Extract_Constant.kind);
|
||||
disabledAction.disabled = localize('extract.disabled', "The current selection cannot be extracted");
|
||||
disabledAction.isPreferred = true;
|
||||
actions.push(disabledAction);
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
|
||||
export function register(
|
||||
|
||||
Reference in New Issue
Block a user