mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
Add experimental trigger reason to ts server protocol
For https://github.com/microsoft/TypeScript/issues/35096
This commit is contained in:
parent
941f7a4d0b
commit
b6c2ea092d
|
@ -19,10 +19,24 @@ import FormattingOptionsManager from './fileConfigurationManager';
|
|||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
interface RefactorActionInfo extends Proto.RefactorActionInfo {
|
||||
error?: string
|
||||
|
||||
namespace Experimental {
|
||||
export interface RefactorActionInfo extends Proto.RefactorActionInfo {
|
||||
readonly error?: string
|
||||
}
|
||||
|
||||
export type RefactorTriggerReason = RefactorInvokedReason;
|
||||
|
||||
export interface RefactorInvokedReason {
|
||||
readonly kind: 'invoked';
|
||||
}
|
||||
|
||||
export interface GetApplicableRefactorsRequestArgs extends Proto.FileRangeRequestArgs {
|
||||
readonly triggerReason?: RefactorTriggerReason;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ApplyRefactoringCommand implements Command {
|
||||
public static readonly ID = '_typescript.applyRefactoring';
|
||||
public readonly id = ApplyRefactoringCommand.ID;
|
||||
|
@ -244,7 +258,10 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
|||
}
|
||||
this.formattingOptionsManager.ensureConfigurationForDocument(document, token);
|
||||
|
||||
const args: Proto.GetApplicableRefactorsRequestArgs = typeConverters.Range.toFileRangeRequestArgs(file, rangeOrSelection);
|
||||
const args: Experimental.GetApplicableRefactorsRequestArgs = {
|
||||
...typeConverters.Range.toFileRangeRequestArgs(file, rangeOrSelection),
|
||||
triggerReason: this.toTsTriggerReason(context),
|
||||
};
|
||||
return this.client.execute('getApplicableRefactors', args, token);
|
||||
});
|
||||
if (response?.type !== 'response' || !response.body) {
|
||||
|
@ -258,6 +275,13 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
|||
return this.appendInvalidActions(actions);
|
||||
}
|
||||
|
||||
private toTsTriggerReason(context: vscode.CodeActionContext): Experimental.RefactorInvokedReason | undefined {
|
||||
if (!context.only) {
|
||||
return;
|
||||
}
|
||||
return { kind: 'invoked' };
|
||||
}
|
||||
|
||||
private convertApplicableRefactors(
|
||||
body: Proto.ApplicableRefactorInfo[],
|
||||
document: vscode.TextDocument,
|
||||
|
@ -283,7 +307,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
|||
}
|
||||
|
||||
private refactorActionToCodeAction(
|
||||
action: RefactorActionInfo,
|
||||
action: Experimental.RefactorActionInfo,
|
||||
document: vscode.TextDocument,
|
||||
info: Proto.ApplicableRefactorInfo,
|
||||
rangeOrSelection: vscode.Range | vscode.Selection,
|
||||
|
|
Loading…
Reference in a new issue