mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
change type of RefactorTriggerReason
This commit is contained in:
@@ -3214,8 +3214,8 @@ namespace FourSlash {
|
||||
};
|
||||
}
|
||||
|
||||
public verifyRefactorAvailable(negative: boolean, name: string, actionName?: string) {
|
||||
let refactors = this.getApplicableRefactorsAtSelection();
|
||||
public verifyRefactorAvailable(negative: boolean, triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string) {
|
||||
let refactors = this.getApplicableRefactorsAtSelection(triggerReason);
|
||||
refactors = refactors.filter(r => r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)));
|
||||
const isAvailable = refactors.length > 0;
|
||||
|
||||
@@ -3644,14 +3644,14 @@ namespace FourSlash {
|
||||
test(renameKeys(newFileContents, key => pathUpdater(key) || key), "with file moved");
|
||||
}
|
||||
|
||||
private getApplicableRefactorsAtSelection() {
|
||||
return this.getApplicableRefactorsWorker(this.getSelection(), this.activeFile.fileName);
|
||||
private getApplicableRefactorsAtSelection(triggerReason: ts.RefactorTriggerReason = "implicit") {
|
||||
return this.getApplicableRefactorsWorker(this.getSelection(), this.activeFile.fileName, ts.emptyOptions, triggerReason);
|
||||
}
|
||||
private getApplicableRefactors(rangeOrMarker: Range | Marker, preferences = ts.emptyOptions): readonly ts.ApplicableRefactorInfo[] {
|
||||
return this.getApplicableRefactorsWorker("position" in rangeOrMarker ? rangeOrMarker.position : rangeOrMarker, rangeOrMarker.fileName, preferences); // eslint-disable-line no-in-operator
|
||||
private getApplicableRefactors(rangeOrMarker: Range | Marker, preferences = ts.emptyOptions, triggerReason: ts.RefactorTriggerReason = "implicit"): readonly ts.ApplicableRefactorInfo[] {
|
||||
return this.getApplicableRefactorsWorker("position" in rangeOrMarker ? rangeOrMarker.position : rangeOrMarker, rangeOrMarker.fileName, preferences, triggerReason); // eslint-disable-line no-in-operator
|
||||
}
|
||||
private getApplicableRefactorsWorker(positionOrRange: number | ts.TextRange, fileName: string, preferences = ts.emptyOptions): readonly ts.ApplicableRefactorInfo[] {
|
||||
return this.languageService.getApplicableRefactors(fileName, positionOrRange, preferences) || ts.emptyArray;
|
||||
private getApplicableRefactorsWorker(positionOrRange: number | ts.TextRange, fileName: string, preferences = ts.emptyOptions, triggerReason: ts.RefactorTriggerReason): readonly ts.ApplicableRefactorInfo[] {
|
||||
return this.languageService.getApplicableRefactors(fileName, positionOrRange, preferences, triggerReason) || ts.emptyArray;
|
||||
}
|
||||
|
||||
public configurePlugin(pluginName: string, configuration: any): void {
|
||||
|
||||
@@ -208,7 +208,11 @@ namespace FourSlashInterface {
|
||||
}
|
||||
|
||||
public refactorAvailable(name: string, actionName?: string) {
|
||||
this.state.verifyRefactorAvailable(this.negative, name, actionName);
|
||||
this.state.verifyRefactorAvailable(this.negative, "implicit", name, actionName);
|
||||
}
|
||||
|
||||
public refactorAvailableForTriggerReason(triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string) {
|
||||
this.state.verifyRefactorAvailable(this.negative, triggerReason, name, actionName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -547,12 +547,10 @@ namespace ts.server.protocol {
|
||||
arguments: GetApplicableRefactorsRequestArgs;
|
||||
}
|
||||
export type GetApplicableRefactorsRequestArgs = FileLocationOrRangeRequestArgs & {
|
||||
triggerReason?: RefactorTriggerReason;
|
||||
triggerReason?: RefactorTriggerReason
|
||||
};
|
||||
|
||||
export enum RefactorTriggerReason {
|
||||
Invoked = "invoked"
|
||||
}
|
||||
export type RefactorTriggerReason = "implicit" | "invoked";
|
||||
|
||||
/**
|
||||
* Response is a list of available refactorings.
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
|
||||
|
||||
function getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[] {
|
||||
const { file, startPosition, triggerReason } = context;
|
||||
const forImplicitRequest = triggerReason ? triggerReason === RefactorTriggerReason.Implicit : true;
|
||||
const forImplicitRequest = triggerReason ? triggerReason === "implicit" : true;
|
||||
const info = getConvertibleArrowFunctionAtPosition(file, startPosition, forImplicitRequest);
|
||||
if (!info) return emptyArray;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ts.refactor.extractSymbol {
|
||||
* Exported for tests.
|
||||
*/
|
||||
export function getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[] {
|
||||
const forImplicitRequest = context.triggerReason ? context.triggerReason === RefactorTriggerReason.Implicit : true;
|
||||
const forImplicitRequest = context.triggerReason ? context.triggerReason === "implicit" : true;
|
||||
const rangeToExtract = getRangeToExtract(context.file, getRefactorContextSpan(context), forImplicitRequest);
|
||||
|
||||
const targetRange = rangeToExtract.targetRange;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace ts.refactor {
|
||||
const extractToTypeDef = "Extract to typedef";
|
||||
registerRefactor(refactorName, {
|
||||
getAvailableActions(context): readonly ApplicableRefactorInfo[] {
|
||||
const forImplicitRequest = context.triggerReason ? context.triggerReason === RefactorTriggerReason.Implicit : true;
|
||||
const forImplicitRequest = context.triggerReason ? context.triggerReason === "implicit" : true;
|
||||
const info = getRangeToExtract(context, forImplicitRequest);
|
||||
if (!info) return emptyArray;
|
||||
|
||||
|
||||
@@ -741,10 +741,7 @@ namespace ts {
|
||||
commands?: CodeActionCommand[];
|
||||
}
|
||||
|
||||
export enum RefactorTriggerReason {
|
||||
Implicit = "implicit",
|
||||
Invoked = "invoked",
|
||||
}
|
||||
export type RefactorTriggerReason = "implicit" | "invoked";
|
||||
|
||||
export interface TextInsertion {
|
||||
newText: string;
|
||||
|
||||
@@ -243,6 +243,7 @@ declare namespace FourSlashInterface {
|
||||
applicableRefactorAvailableForRange(): void;
|
||||
|
||||
refactorAvailable(name: string, actionName?: string): void;
|
||||
refactorAvailableForTriggerReason(triggerReason: RefactorTriggerReason, name: string, action?: string): void
|
||||
}
|
||||
class verify extends verifyNegatable {
|
||||
assertHasRanges(ranges: Range[]): void;
|
||||
@@ -683,6 +684,8 @@ declare namespace FourSlashInterface {
|
||||
triggerCharacter?: string,
|
||||
}
|
||||
|
||||
export type RefactorTriggerReason = "implicit" | "invoked";
|
||||
|
||||
export interface VerifyCodeFixAvailableOptions {
|
||||
readonly description: string;
|
||||
readonly actions?: ReadonlyArray<{ readonly type: string, readonly data: {} }>;
|
||||
|
||||
Reference in New Issue
Block a user