fourslash: Add 'goToMarkerOrRange' helper (#28057)

This commit is contained in:
Andy 2018-10-22 11:44:39 -07:00 committed by GitHub
parent d3d4f83f89
commit 1930f8a790
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1181,12 +1181,7 @@ namespace FourSlash {
})); }));
for (const start of toArray<string | Range>(starts)) { for (const start of toArray<string | Range>(starts)) {
if (typeof start === "string") { this.goToMarkerOrRange(start);
this.goToMarker(start);
}
else {
this.goToRangeStart(start);
}
const fullActual = ts.map<ts.ReferencedSymbol, ReferenceGroupJson>(this.findReferencesAtCaret(), ({ definition, references }, i) => { const fullActual = ts.map<ts.ReferencedSymbol, ReferenceGroupJson>(this.findReferencesAtCaret(), ({ definition, references }, i) => {
const text = definition.displayParts.map(d => d.text).join(""); const text = definition.displayParts.map(d => d.text).join("");
return { return {
@ -1203,15 +1198,7 @@ namespace FourSlash {
} }
public verifyNoReferences(markerNameOrRange?: string | Range) { public verifyNoReferences(markerNameOrRange?: string | Range) {
if (markerNameOrRange) { if (markerNameOrRange) this.goToMarkerOrRange(markerNameOrRange);
if (ts.isString(markerNameOrRange)) {
this.goToMarker(markerNameOrRange);
}
else {
this.goToRangeStart(markerNameOrRange);
}
}
const refs = this.getReferencesAtCaret(); const refs = this.getReferencesAtCaret();
if (refs && refs.length) { if (refs && refs.length) {
this.raiseError(`Expected getReferences to fail, but saw references: ${stringify(refs)}`); this.raiseError(`Expected getReferences to fail, but saw references: ${stringify(refs)}`);
@ -2053,6 +2040,14 @@ Actual: ${stringify(fullActual)}`);
this.goToPosition(len); this.goToPosition(len);
} }
private goToMarkerOrRange(markerOrRange: string | Range) {
if (typeof markerOrRange === "string") {
this.goToMarker(markerOrRange);
} else {
this.goToRangeStart(markerOrRange);
}
}
public goToRangeStart({ fileName, pos }: Range) { public goToRangeStart({ fileName, pos }: Range) {
this.openFile(fileName); this.openFile(fileName);
this.goToPosition(pos); this.goToPosition(pos);