Skip to content

Commit 5c1b245

Browse files
Initial work on getOccurrencesAtPosition.
1 parent 892baf0 commit 5c1b245

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/services/services.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,26 @@ module ts {
20932093
}
20942094

20952095
/// Find references
2096+
function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] {
2097+
synchronizeHostData();
2098+
2099+
filename = TypeScript.switchToForwardSlashes(filename);
2100+
var sourceFile = getSourceFile(filename);
2101+
2102+
var node = getNodeAtPosition(sourceFile, position);
2103+
if (!node) {
2104+
return undefined;
2105+
}
2106+
2107+
if (node.kind !== SyntaxKind.Identifier &&
2108+
!isLiteralNameOfPropertyDeclarationOrIndexAccess(node) &&
2109+
!isNameOfExternalModuleImportOrDeclaration(node)) {
2110+
return undefined;
2111+
}
2112+
2113+
return getReferencesForNode(node, [sourceFile]);
2114+
}
2115+
20962116
function getReferencesAtPosition(filename: string, position: number): ReferenceEntry[] {
20972117
synchronizeHostData();
20982118

@@ -2105,11 +2125,15 @@ module ts {
21052125
}
21062126

21072127
if (node.kind !== SyntaxKind.Identifier &&
2108-
!isLiteralNameOfPropertyDeclarationOrIndexAccess(node) &&
2128+
!isLiteralNameOfPropertyDeclarationOrIndexAccess(node) &&
21092129
!isNameOfExternalModuleImportOrDeclaration(node)) {
21102130
return undefined;
21112131
}
21122132

2133+
return getReferencesForNode(node, program.getSourceFiles());
2134+
}
2135+
2136+
function getReferencesForNode(node: Node, sourceFiles : SourceFile[]): ReferenceEntry[] {
21132137
// Labels
21142138
if (isLabelName(node)) {
21152139
if (isJumpStatementTarget(node)) {
@@ -2153,7 +2177,7 @@ module ts {
21532177
getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, result);
21542178
}
21552179
else {
2156-
forEach(program.getSourceFiles(), sourceFile => {
2180+
forEach(sourceFiles, sourceFile => {
21572181
cancellationToken.throwIfCancellationRequested();
21582182

21592183
if (lookUp(sourceFile.identifiers, symbolName)) {
@@ -2789,7 +2813,7 @@ module ts {
27892813
getSignatureAtPosition: (filename, position): SignatureInfo => undefined,
27902814
getDefinitionAtPosition: getDefinitionAtPosition,
27912815
getReferencesAtPosition: getReferencesAtPosition,
2792-
getOccurrencesAtPosition: (filename, position) => [],
2816+
getOccurrencesAtPosition: getOccurrencesAtPosition,
27932817
getImplementorsAtPosition: (filename, position) => [],
27942818
getNameOrDottedNameSpan: getNameOrDottedNameSpan,
27952819
getBreakpointStatementAtPosition: getBreakpointStatementAtPosition,

0 commit comments

Comments
 (0)