Add multiple overloads for verify.goToDefinition
.
Use explicit pairs `verify.goToDefinition([["a", "b"], ["c", "d"]])` instead of `verify.goToDefinition("a", "b", "c", "d")`. Also provide an option `verify.goToDefinition({ a: "b", c: "d" })` for cases where the starts are not theirselves lists.
This commit is contained in:
parent
37f8eac014
commit
c75f6d0ec7
24 changed files with 145 additions and 106 deletions
|
@ -529,24 +529,35 @@ namespace FourSlash {
|
|||
this.verifyGoToDefinitionWorker(endMarker instanceof Array ? endMarker : [endMarker]);
|
||||
}
|
||||
|
||||
public verifyGoToDefinition(startsAndEnds: (string | string[])[]) {
|
||||
if (startsAndEnds.length % 2) {
|
||||
throw new Error("verify.goToDefinition needs an even number of arguments.");
|
||||
public verifyGoToDefinition(arg0: any, endMarkerNames?: string | string[]) {
|
||||
if (endMarkerNames) {
|
||||
this.verifyGoToDefinitionPlain(arg0, endMarkerNames);
|
||||
}
|
||||
|
||||
for (let i = 0; i < startsAndEnds.length; i += 2) {
|
||||
const start = startsAndEnds[i];
|
||||
const end = startsAndEnds[i + 1];
|
||||
|
||||
if (start instanceof Array) {
|
||||
for (const s of start) {
|
||||
this.verifyGoToDefinitionSingle(s, end);
|
||||
else if (arg0 instanceof Array) {
|
||||
const pairs: [string | string[], string | string[]][] = arg0;
|
||||
for (const [start, end] of pairs) {
|
||||
this.verifyGoToDefinitionPlain(start, end);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const obj: { [startMarkerName: string]: string | string[] } = arg0;
|
||||
for (const startMarkerName in obj) {
|
||||
if (ts.hasProperty(obj, startMarkerName)) {
|
||||
this.verifyGoToDefinitionPlain(startMarkerName, obj[startMarkerName]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.verifyGoToDefinitionSingle(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
private verifyGoToDefinitionPlain(startMarkerNames: string | string[], endMarkerNames: string | string[]) {
|
||||
if (startMarkerNames instanceof Array) {
|
||||
for (const start of startMarkerNames) {
|
||||
this.verifyGoToDefinitionSingle(start, endMarkerNames);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.verifyGoToDefinitionSingle(startMarkerNames, endMarkerNames);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyGoToDefinitionForMarkers(markerNames: string[]) {
|
||||
|
@ -555,9 +566,9 @@ namespace FourSlash {
|
|||
}
|
||||
}
|
||||
|
||||
private verifyGoToDefinitionSingle(start: string, end: string | string[]) {
|
||||
this.goToMarker(start);
|
||||
this.verifyGoToDefinitionWorker(end instanceof Array ? end : [end]);
|
||||
private verifyGoToDefinitionSingle(startMarkerName: string, endMarkerNames: string | string[]) {
|
||||
this.goToMarker(startMarkerName);
|
||||
this.verifyGoToDefinitionWorker(endMarkerNames instanceof Array ? endMarkerNames : [endMarkerNames]);
|
||||
}
|
||||
|
||||
private verifyGoToDefinitionWorker(endMarkers: string[]) {
|
||||
|
@ -2947,8 +2958,11 @@ namespace FourSlashInterface {
|
|||
this.state.verifyGoToDefinitionIs(endMarkers);
|
||||
}
|
||||
|
||||
public goToDefinition(...startsAndEnds: (string | string[])[]) {
|
||||
this.state.verifyGoToDefinition(startsAndEnds);
|
||||
public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[]): void;
|
||||
public goToDefinition(startsAndEnds: [string | string[], string | string[]][]): void;
|
||||
public goToDefinition(startsAndEnds: { [startMarkerName: string]: string | string[] }): void;
|
||||
public goToDefinition(arg0: any, endMarkerName?: string | string[]) {
|
||||
this.state.verifyGoToDefinition(arg0, endMarkerName);
|
||||
}
|
||||
|
||||
public goToDefinitionForMarkers(...markerNames: string[]) {
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
|
||||
goTo.marker("useFoo");
|
||||
verify.quickInfoIs("import foo");
|
||||
verify.goToDefinition(
|
||||
"useFoo", "importFoo",
|
||||
"importFoo", "module");
|
||||
verify.goToDefinition({
|
||||
useFoo: "importFoo",
|
||||
importFoo: "module"
|
||||
});
|
||||
|
||||
goTo.marker("useBar");
|
||||
verify.quickInfoIs("import bar");
|
||||
|
@ -22,12 +23,14 @@ verify.goToDefinition("useBar", "module");
|
|||
|
||||
goTo.marker("useBaz");
|
||||
verify.quickInfoIs("import baz");
|
||||
verify.goToDefinition(
|
||||
"useBaz", "importBaz",
|
||||
"idBaz", "module");
|
||||
verify.goToDefinition({
|
||||
useBaz: "importBaz",
|
||||
idBaz: "module"
|
||||
});
|
||||
|
||||
goTo.marker("useBang");
|
||||
verify.quickInfoIs("import bang = require(\"jquery\")");
|
||||
verify.goToDefinition(
|
||||
"useBang", "importBang",
|
||||
"idBang", "module");
|
||||
verify.goToDefinition({
|
||||
useBang: "importBang",
|
||||
idBang: "module"
|
||||
});
|
||||
|
|
|
@ -156,9 +156,12 @@ declare namespace FourSlashInterface {
|
|||
* `verify.goToDefinition("a", "b");` verifies that go-to-definition at marker "a" takes you to marker "b".
|
||||
* `verify.goToDefinition(["a", "aa"], "b");` verifies that markers "a" and "aa" have the same definition "b".
|
||||
* `verify.goToDefinition("a", ["b", "bb"]);` verifies that "a" has multiple definitions available.
|
||||
* Finally, `verify.goToDefinition("a", "b", "c", "d");` is just `verify.goToDefinition("a", "b"); verify.goToDefinition("c", "d");`.
|
||||
*/
|
||||
goToDefinition(...startsAndEnds: (string | string[])[]): void;
|
||||
goToDefinition(startMarkerNames: string | string[], endMarkerNames: string | string[]): void;
|
||||
/** Performs `goToDefinition` for each pair. */
|
||||
goToDefinition(startsAndEnds: [string | string[], string | string[]][]): void;
|
||||
/** Performs `goToDefinition` on each key and value. */
|
||||
goToDefinition(startsAndEnds: { [startMarkerName: string]: string | string[] }): void;
|
||||
/** Verifies goToDefinition for each `${markerName}Reference` -> `${markerName}Definition` */
|
||||
goToDefinitionForMarkers(...markerNames: string[]): void;
|
||||
verifyGetEmitOutputForCurrentFile(expected: string): void;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//// @/*useDecSymbol*/dec [s]() {}
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"useDecString", "defDecString",
|
||||
"useDecSymbol", "defDecSymbol");
|
||||
verify.goToDefinition({
|
||||
useDecString: "defDecString",
|
||||
useDecSymbol: "defDecSymbol"
|
||||
});
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
//// x;
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
["alias1Type", "alias1Value"], "alias1Definition",
|
||||
["alias2Type", "alias2Value"], "alias2Definition");
|
||||
verify.goToDefinition([
|
||||
[["alias1Type", "alias1Value"], "alias1Definition"],
|
||||
[["alias2Type", "alias2Value"], "alias2Definition"]
|
||||
]);
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
////var constructorOverload = new /*constructorOverloadReference1*/ConstructorOverload();
|
||||
////var constructorOverload = new /*constructorOverloadReference2*/ConstructorOverload("foo");
|
||||
|
||||
verify.goToDefinition(
|
||||
"constructorOverloadReference1", "constructorOverload1",
|
||||
"constructorOverloadReference2", "constructorOverload2",
|
||||
"constructorOverload1", "constructorDefinition");
|
||||
verify.goToDefinition({
|
||||
constructorOverloadReference1: "constructorOverload1",
|
||||
constructorOverloadReference2: "constructorOverload2",
|
||||
constructorOverload1: "constructorDefinition"
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
//// return target => target;
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"decoratorUse", "decoratorDefinition",
|
||||
"decoratorFactoryUse", "decoratorFactoryDefinition");
|
||||
verify.goToDefinition({
|
||||
decoratorUse: "decoratorDefinition",
|
||||
decoratorFactoryUse: "decoratorFactoryDefinition"
|
||||
});
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
/////*functionOverloadReference2*/functionOverload("123");
|
||||
/////*brokenOverload*/functionOverload({});
|
||||
|
||||
verify.goToDefinition(
|
||||
"functionOverloadReference1", "functionOverload1",
|
||||
"functionOverloadReference2", "functionOverload2",
|
||||
"brokenOverload", "functionOverload1",
|
||||
"functionOverload", "functionOverloadDefinition");
|
||||
verify.goToDefinition({
|
||||
functionOverloadReference1: "functionOverload1",
|
||||
functionOverloadReference2: "functionOverload2",
|
||||
brokenOverload: "functionOverload1",
|
||||
functionOverload: "functionOverloadDefinition"
|
||||
});
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//// constructor() { }
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"staticFunctionOverload", "staticFunctionOverloadDefinition",
|
||||
"functionOverload", "functionOverloadDefinition");
|
||||
verify.goToDefinition({
|
||||
staticFunctionOverload: "staticFunctionOverloadDefinition",
|
||||
functionOverload: "functionOverloadDefinition"
|
||||
});
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
//// }
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
["interfaceReference", "interfaceReferenceInList", "interfaceReferenceInConstructor"], "interfaceDefinition",
|
||||
["classReference", "classReferenceInInitializer"], "classDefinition",
|
||||
["enumReference", "enumReferenceInInitializer"], "enumDefinition",
|
||||
"selfReference", "selfDefinition");
|
||||
verify.goToDefinition([
|
||||
[["interfaceReference", "interfaceReferenceInList", "interfaceReferenceInConstructor"], "interfaceDefinition"],
|
||||
[["classReference", "classReferenceInInitializer"], "classDefinition"],
|
||||
[["enumReference", "enumReferenceInInitializer"], "enumDefinition"],
|
||||
["selfReference", "selfDefinition"]
|
||||
]);
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
//// }
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"1", "label1Definition",
|
||||
"2", "label2Definition",
|
||||
verify.goToDefinition({
|
||||
1: "label1Definition",
|
||||
2: "label2Definition",
|
||||
// labels accross function boundaries
|
||||
"3", "label1Definition",
|
||||
3: "label1Definition",
|
||||
// undefined label
|
||||
"4", []);
|
||||
4: []
|
||||
});
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
////methodOverload./*instanceMethodReference1*/method();
|
||||
////methodOverload./*instanceMethodReference2*/method("456");
|
||||
|
||||
verify.goToDefinition(
|
||||
"staticMethodReference1", "staticMethodOverload1",
|
||||
"staticMethodReference2", "staticMethodOverload2",
|
||||
"instanceMethodReference1", "instanceMethodOverload1",
|
||||
"instanceMethodReference2", "instanceMethodOverload2",
|
||||
"staticMethodOverload1Name", "staticMethodDefinition",
|
||||
"instanceMethodOverload1Name", "instanceMethodDefinition");
|
||||
verify.goToDefinition({
|
||||
staticMethodReference1: "staticMethodOverload1",
|
||||
staticMethodReference2: "staticMethodOverload2",
|
||||
instanceMethodReference1: "instanceMethodOverload1",
|
||||
instanceMethodReference2: "instanceMethodOverload2",
|
||||
staticMethodOverload1Name: "staticMethodDefinition",
|
||||
instanceMethodOverload1Name: "instanceMethodDefinition"
|
||||
});
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
//// obj./*valueReference1*/name;
|
||||
//// obj./*valueReference2*/id;
|
||||
|
||||
verify.goToDefinition(
|
||||
"valueDefinition1", "valueDeclaration1",
|
||||
"valueDefinition2", ["valueDeclaration2", "valueDeclaration3"],
|
||||
"valueReference1", "valueDefinition1",
|
||||
"valueReference2", "valueDefinition2");
|
||||
verify.goToDefinition({
|
||||
valueDefinition1: "valueDeclaration1",
|
||||
valueDefinition2: ["valueDeclaration2", "valueDeclaration3"],
|
||||
valueReference1: "valueDefinition1",
|
||||
valueReference2: "valueDefinition2"
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//// /*letProp*/y
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"varProp", "varDef",
|
||||
"letProp", "letDef");
|
||||
verify.goToDefinition({
|
||||
varProp: "varDef",
|
||||
letProp: "letDef"
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// @Filename: b.ts
|
||||
/////*fileB*/
|
||||
|
||||
verify.goToDefinition(
|
||||
"unknownFile", [],
|
||||
"knownFile", "fileB");
|
||||
verify.goToDefinition({
|
||||
unknownFile: [],
|
||||
knownFile: "fileB"
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
/////*useFNumber*/f`${0}`;
|
||||
/////*useFBool*/f`${false}`;
|
||||
|
||||
verify.goToDefinition(
|
||||
"useFNumber", "defFNumber",
|
||||
"useFBool", "defFBool");
|
||||
verify.goToDefinition({
|
||||
useFNumber: "defFNumber",
|
||||
useFBool: "defFBool"
|
||||
});
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
//// get self(/*getterDecl*/this: number) { return /*getterUse*/this; }
|
||||
////}
|
||||
|
||||
verify.goToDefinition(
|
||||
"fnUse", "fnDecl",
|
||||
"clsUse", "cls",
|
||||
"getterUse", "getterDecl");
|
||||
verify.goToDefinition({
|
||||
"fnUse": "fnDecl",
|
||||
"clsUse": "cls",
|
||||
"getterUse": "getterDecl"
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//// return typeof parameter === "string";
|
||||
//// }
|
||||
|
||||
verify.goToDefinition(
|
||||
"parameterName", "parameterDeclaration",
|
||||
"typeReference", "classDeclaration");
|
||||
verify.goToDefinition({
|
||||
parameterName: "parameterDeclaration",
|
||||
typeReference: "classDeclaration"
|
||||
});
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
////}
|
||||
|
||||
|
||||
verify.goToDefinition(
|
||||
verify.goToDefinition({
|
||||
// Super in call position goes to constructor.
|
||||
"super", "ctr",
|
||||
super: "ctr",
|
||||
// Super in any other position goes to the superclass.
|
||||
"superExpression", "B",
|
||||
"superBroken", []);
|
||||
superExpression: "B",
|
||||
superBroken: []
|
||||
});
|
||||
|
|
|
@ -9,4 +9,3 @@
|
|||
|
||||
// Won't-fixed: Should go to '2' instead
|
||||
verify.goToDefinition("1", "3");
|
||||
goTo.marker('1');
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
//// x.alpha/*src1*/;
|
||||
//// x.beta/*src2*/;
|
||||
|
||||
verify.goToDefinition(
|
||||
"src1", "dst1",
|
||||
"src2", "dst2");
|
||||
verify.goToDefinition({
|
||||
src1: "dst1",
|
||||
src2: "dst2"
|
||||
});
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
//// /** @type {Animal} */
|
||||
//// var animal; animal.animalName/*4*/
|
||||
|
||||
verify.goToDefinition(
|
||||
"3", "1",
|
||||
"4", "2");
|
||||
verify.goToDefinition({
|
||||
3: "1",
|
||||
4: "2"
|
||||
});
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
//// var x = <My/*c*/Class />;
|
||||
//// var y = <MyClass f/*p*/oo= 'hello' />;
|
||||
|
||||
verify.goToDefinition(
|
||||
"c", "ct",
|
||||
"p", "pt");
|
||||
verify.goToDefinition({
|
||||
c: "ct",
|
||||
p: "pt"
|
||||
});
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
//// var y = <s/*ss*/pan />;
|
||||
//// var z = <div na/*ps*/me='hello' />;
|
||||
|
||||
verify.goToDefinition(
|
||||
"ds", "dt",
|
||||
"ss", "st",
|
||||
"ps", "pt");
|
||||
verify.goToDefinition({
|
||||
ds: "dt",
|
||||
ss: "st",
|
||||
ps: "pt"
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue