Use object for refactor.disabled

For #85160

Using an object is more explict with property names and will let us introduce additional properties in the future if needed
This commit is contained in:
Matt Bierner 2019-12-11 20:15:07 -08:00
parent ba2524065b
commit a4177f50c4
3 changed files with 13 additions and 5 deletions

View file

@ -314,7 +314,9 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
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.disabled = {
reason: localize('extract.disabled', "The current selection cannot be extracted"),
};
disabledAction.isPreferred = true;
actions.push(disabledAction);
}

View file

@ -1331,10 +1331,16 @@ declare module 'vscode' {
/**
* Marks that the code action cannot currently be applied.
*
* This should be a human readable description of why the code action is currently disabled. Disabled code actions
* will be surfaced in the refactor UI but cannot be applied.
* Disabled code actions will be surfaced in the refactor UI but cannot be applied.
*/
disabled?: string;
disabled?: {
/**
* Human readable description of why the code action is currently disabled.
*
* This is displayed in the UI.
*/
reason: string;
};
}
//#endregion

View file

@ -389,7 +389,7 @@ class CodeActionAdapter {
edit: candidate.edit && typeConvert.WorkspaceEdit.from(candidate.edit),
kind: candidate.kind && candidate.kind.value,
isPreferred: candidate.isPreferred,
disabled: candidate.disabled
disabled: candidate.disabled?.reason
});
}
}