Fix bug: Handle QualifiedName in getMeaningFromRightHandSideOfImportEquals (#21779)

* Fix bug: Handle QualifiedName in getMeaningFromRightHandSideOfImportEquals

* Fix lint
This commit is contained in:
Andy
2018-02-20 14:32:51 -08:00
committed by GitHub
parent 98baea992e
commit b00c13b716
4 changed files with 23 additions and 18 deletions

View File

@@ -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<string | Range>(starts)) {
if (typeof start === "string") {
this.goToMarker(start);
}
else {
this.goToRangeStart(start);
}
const fullActual = ts.map<ts.ReferencedSymbol, ReferenceGroupJson>(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) {

View File

@@ -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 &&
(<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) {

View File

@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />
////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() }]);

View File

@@ -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;