parent
20f06e0444
commit
49d05f998f
|
@ -223,7 +223,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
|
|||
_range: vscode.Range,
|
||||
context: vscode.CodeActionContext,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.CodeAction[]> {
|
||||
): Promise<VsCodeCodeAction[]> {
|
||||
const file = this.client.toOpenedFilePath(document);
|
||||
if (!file) {
|
||||
return [];
|
||||
|
|
|
@ -284,7 +284,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
|
|||
context: vscode.CodeActionContext,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<TsCodeAction[] | undefined> {
|
||||
if (!this.shouldTrigger(rangeOrSelection, context)) {
|
||||
if (!this.shouldTrigger(context)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!this.client.toOpenedFilePath(document)) {
|
||||
|
@ -335,10 +335,10 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
|
|||
}
|
||||
|
||||
private toTsTriggerReason(context: vscode.CodeActionContext): Proto.RefactorTriggerReason | undefined {
|
||||
if (!context.only) {
|
||||
return;
|
||||
if (context.triggerKind === vscode.CodeActionTriggerKind.Manual) {
|
||||
return 'invoked';
|
||||
}
|
||||
return 'invoked';
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private convertApplicableRefactors(
|
||||
|
@ -384,12 +384,12 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
|
|||
return codeAction;
|
||||
}
|
||||
|
||||
private shouldTrigger(rangeOrSelection: vscode.Range | vscode.Selection, context: vscode.CodeActionContext) {
|
||||
private shouldTrigger(context: vscode.CodeActionContext) {
|
||||
if (context.only && !vscode.CodeActionKind.Refactor.contains(context.only)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return rangeOrSelection instanceof vscode.Selection;
|
||||
return context.triggerKind === vscode.CodeActionTriggerKind.Manual;
|
||||
}
|
||||
|
||||
private static getKind(refactor: Proto.RefactorActionInfo) {
|
||||
|
|
28
src/vs/vscode.proposed.d.ts
vendored
28
src/vs/vscode.proposed.d.ts
vendored
|
@ -2800,4 +2800,32 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region https://github.com/microsoft/vscode/issues/118084
|
||||
|
||||
/**
|
||||
* The reason why code actions were requested.
|
||||
*/
|
||||
export enum CodeActionTriggerKind {
|
||||
/**
|
||||
* Code actions were requested automatically.
|
||||
*
|
||||
* This typically happens when current selection in a file changes, but can
|
||||
* also be triggered when file content changes.
|
||||
*/
|
||||
Automatic = 1,
|
||||
|
||||
/**
|
||||
* Code actions were requested maually by the user or an extension.
|
||||
*/
|
||||
Manual = 2,
|
||||
}
|
||||
|
||||
export interface CodeActionContext {
|
||||
/**
|
||||
* The reason why code actions were requested.
|
||||
*/
|
||||
readonly triggerKind: CodeActionTriggerKind;
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
|
|
@ -1151,7 +1151,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
CandidatePortSource: CandidatePortSource,
|
||||
CodeAction: extHostTypes.CodeAction,
|
||||
CodeActionKind: extHostTypes.CodeActionKind,
|
||||
CodeActionTrigger: extHostTypes.CodeActionTrigger,
|
||||
CodeActionTriggerKind: extHostTypes.CodeActionTriggerKind,
|
||||
CodeLens: extHostTypes.CodeLens,
|
||||
Color: extHostTypes.Color,
|
||||
ColorInformation: extHostTypes.ColorInformation,
|
||||
|
|
|
@ -412,7 +412,8 @@ class CodeActionAdapter {
|
|||
|
||||
const codeActionContext: vscode.CodeActionContext = {
|
||||
diagnostics: allDiagnostics,
|
||||
only: context.only ? new CodeActionKind(context.only) : undefined
|
||||
only: context.only ? new CodeActionKind(context.only) : undefined,
|
||||
triggerKind: typeConvert.CodeActionTriggerKind.to(context.trigger),
|
||||
};
|
||||
|
||||
return asPromise(() => this._provider.provideCodeActions(doc, ran, codeActionContext, token)).then((commandsOrActions): extHostProtocol.ICodeActionListDto | undefined => {
|
||||
|
|
|
@ -1712,3 +1712,16 @@ export namespace TestResults {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
export namespace CodeActionTriggerKind {
|
||||
|
||||
export function to(value: modes.CodeActionTriggerType): types.CodeActionTriggerKind {
|
||||
switch (value) {
|
||||
case modes.CodeActionTriggerType.Auto:
|
||||
return types.CodeActionTriggerKind.Automatic;
|
||||
|
||||
case modes.CodeActionTriggerType.Manual:
|
||||
return types.CodeActionTriggerKind.Manual;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1178,7 +1178,7 @@ export class DocumentSymbol {
|
|||
}
|
||||
|
||||
|
||||
export enum CodeActionTrigger {
|
||||
export enum CodeActionTriggerKind {
|
||||
Automatic = 1,
|
||||
Manual = 2,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue