Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Factor out FindAllReferences.Core and use Definition/Entry to allow f…
…indReferencedSymbols and getImplementationsAtPosition to return different results
  • Loading branch information
Andy Hanson committed Mar 17, 2017
commit 94f6839aec38541651caba820d4965ba1deb73c2
3 changes: 0 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,6 @@ namespace ts {
}

export interface ExternalModuleReference extends Node {
parent: ImportEqualsDeclaration;
kind: SyntaxKind.ExternalModuleReference;
parent?: ImportEqualsDeclaration;
expression?: Expression;
Expand Down Expand Up @@ -1909,7 +1908,6 @@ namespace ts {
}

export interface NamedExports extends Node {
parent: ExportDeclaration;
kind: SyntaxKind.NamedExports;
parent?: ExportDeclaration;
elements: NodeArray<ExportSpecifier>;
Expand All @@ -1925,7 +1923,6 @@ namespace ts {
}

export interface ExportSpecifier extends Declaration {
parent: NamedExports;
kind: SyntaxKind.ExportSpecifier;
parent?: NamedExports;
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
Expand Down
4 changes: 2 additions & 2 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ namespace FourSlash {

for (const startRange of toArray(startRanges)) {
this.goToRangeStart(startRange);
const fullActual = this.findReferencesAtCaret().map<ReferenceJson>(({ definition, references }) => ({
const fullActual = ts.map<ts.ReferencedSymbol, ReferenceJson>(this.findReferencesAtCaret(), ({ definition, references }) => ({
definition: definition.displayParts.map(d => d.text).join(""),
ranges: references
}));
Expand Down Expand Up @@ -2383,7 +2383,7 @@ namespace FourSlash {
else {
if (actual === undefined) {
this.raiseError(`${name} failed - expected the template {newText: "${expected.newText}", caretOffset: "${expected.caretOffset}"} but got nothing instead`);

}

if (actual.newText !== expected.newText) {
Expand Down
12 changes: 4 additions & 8 deletions src/services/documentHighlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ namespace ts.DocumentHighlights {
return referenceEntries && convertReferencedSymbols(referenceEntries);
}

function convertReferencedSymbols(referenceEntries: ReferenceEntry[]): DocumentHighlights[] {
function convertReferencedSymbols(referenceEntries: FindAllReferences.Entry[]): DocumentHighlights[] {
const fileNameToDocumentHighlights = createMap<HighlightSpan[]>();
for (const referenceEntry of referenceEntries) {
const fileName = referenceEntry.fileName;
for (const entry of referenceEntries) {
const { fileName, span } = FindAllReferences.toHighlightSpan(entry);
let highlightSpans = fileNameToDocumentHighlights.get(fileName);
if (!highlightSpans) {
fileNameToDocumentHighlights.set(fileName, highlightSpans = []);
}

highlightSpans.push({
textSpan: referenceEntry.textSpan,
kind: referenceEntry.isWriteAccess ? HighlightSpanKind.writtenReference : HighlightSpanKind.reference
});
highlightSpans.push(span);
}

return arrayFrom(fileNameToDocumentHighlights.entries(), ([fileName, highlightSpans ]) => ({ fileName, highlightSpans }));
Expand Down
436 changes: 254 additions & 182 deletions src/services/findAllReferences.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ namespace ts.FindAllReferences {
/** If at an export specifier, go to the symbol it refers to. */
function skipExportSpecifierSymbol(symbol: Symbol, checker: TypeChecker): Symbol {
// For `export { foo } from './bar", there's nothing to skip, because it does not create a new alias. But `export { foo } does.
for (const declaration of symbol.declarations) {
if (symbol.declarations) for (const declaration of symbol.declarations) {
if (isExportSpecifier(declaration) && !(declaration as ExportSpecifier).propertyName && !(declaration as ExportSpecifier).parent.parent.moduleSpecifier) {
return checker.getExportSpecifierLocalTargetSymbol(declaration);
}
Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ namespace ts {
displayParts: SymbolDisplayPart[];
}

//!!! internal implementation details leaked!!!
export interface ReferencedSymbolOf<T extends DocumentSpan> {
definition: ReferencedSymbolDefinitionInfo;
references: T[];
Expand Down
15 changes: 15 additions & 0 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,21 @@ namespace ts {
return false;
}
}

/** True if the symbol is for an external module, as opposed to a namespace. */
export function isExternalModuleSymbol(moduleSymbol: Symbol): boolean {
Debug.assert(!!(moduleSymbol.flags & SymbolFlags.Module));
return moduleSymbol.name.charCodeAt(0) === CharacterCodes.doubleQuote;
}

/** Returns `true` the first time it encounters a node and `false` afterwards. */
export function nodeSeenTracker<T extends Node>(): (node: T) => boolean {
const seen: Array<true> = [];
return node => {
const id = getNodeId(node);
return !seen[id] && (seen[id] = true);
};
}
}

// Display-part writer helpers
Expand Down