diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index fa9bf124e51..7fdbbbc9640 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1086,7 +1086,7 @@ namespace FourSlash { } } - public verifyReferenceGroups(startRanges: Range | Range[], parts: FourSlashInterface.ReferenceGroup[]): void { + public verifyReferenceGroups(starts: string | string[] | Range | Range[], parts: FourSlashInterface.ReferenceGroup[]): void { interface ReferenceGroupJson { definition: string | { text: string, range: ts.TextSpan }; references: ts.ReferenceEntry[]; @@ -1105,8 +1105,13 @@ namespace FourSlash { }), })); - for (const startRange of toArray(startRanges)) { - this.goToRangeStart(startRange); + for (const start of toArray(starts)) { + if (typeof start === "string") { + this.goToMarker(start); + } + else { + this.goToRangeStart(start); + } const fullActual = ts.map(this.findReferencesAtCaret(), ({ definition, references }, i) => { const text = definition.displayParts.map(d => d.text).join(""); return { @@ -4075,8 +4080,8 @@ namespace FourSlashInterface { this.state.verifyReferencesOf(start, references); } - public referenceGroups(startRanges: FourSlash.Range[], parts: ReferenceGroup[]) { - this.state.verifyReferenceGroups(startRanges, parts); + public referenceGroups(starts: string | string[] | FourSlash.Range | FourSlash.Range[], parts: ReferenceGroup[]) { + this.state.verifyReferenceGroups(starts, parts); } public noReferences(markerNameOrRange?: string | FourSlash.Range) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 263ac0f4c3b..6ece5e018b3 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -92,7 +92,7 @@ namespace ts { return SemanticMeaning.All; } else if (isInRightSideOfInternalImportEqualsDeclaration(node)) { - return getMeaningFromRightHandSideOfImportEquals(node); + return getMeaningFromRightHandSideOfImportEquals(node as Identifier); } else if (isDeclarationName(node)) { return getMeaningFromDeclaration(node.parent); @@ -112,19 +112,12 @@ namespace ts { } } - function getMeaningFromRightHandSideOfImportEquals(node: Node) { - Debug.assert(node.kind === SyntaxKind.Identifier); - + function getMeaningFromRightHandSideOfImportEquals(node: Node): SemanticMeaning { // import a = |b|; // Namespace // import a = |b.c|; // Value, type, namespace // import a = |b.c|.d; // Namespace - - if (node.parent.kind === SyntaxKind.QualifiedName && - (node.parent).right === node && - node.parent.parent.kind === SyntaxKind.ImportEqualsDeclaration) { - return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace; - } - return SemanticMeaning.Namespace; + const name = node.kind === SyntaxKind.QualifiedName ? node : isQualifiedName(node.parent) && node.parent.right === node ? node.parent : undefined; + return name && name.parent.kind === SyntaxKind.ImportEqualsDeclaration ? SemanticMeaning.All : SemanticMeaning.Namespace; } export function isInRightSideOfInternalImportEqualsDeclaration(node: Node) { diff --git a/tests/cases/fourslash/findAllRefsImportEquals.ts b/tests/cases/fourslash/findAllRefsImportEquals.ts new file mode 100644 index 00000000000..c6884c78b8c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsImportEquals.ts @@ -0,0 +1,7 @@ +/// + +////import j = N./**/ [|q|]; +////namespace N { export const [|{| "isWriteAccess": true, "isDefinition": true |}q|] = 0; } + +goTo.marker(); +verify.referenceGroups("", [{ definition: "const N.q: 0", ranges: test.ranges() }]); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 987af1d6a3a..4d537661a27 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -256,10 +256,10 @@ declare namespace FourSlashInterface { */ referencesOf(start: Range, references: Range[]): void; /** - * For each of startRanges, asserts the ranges that are referenced from there. + * For each of starts, asserts the ranges that are referenced from there. * This uses the 'findReferences' command instead of 'getReferencesAtPosition', so references are grouped by their definition. */ - referenceGroups(startRanges: Range | Range[], parts: Array<{ definition: ReferencesDefinition, ranges: Range[] }>): void; + referenceGroups(starts: string | string[] | Range | Range[], parts: Array<{ definition: ReferencesDefinition, ranges: Range[] }>): void; singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void; rangesAreOccurrences(isWriteAccess?: boolean): void; rangesWithSameTextAreRenameLocations(): void;