Implement getScope
This commit is contained in:
parent
dbf9e47832
commit
fefe2fb093
6 changed files with 137 additions and 34 deletions
|
@ -2163,7 +2163,7 @@ module ts {
|
|||
// Compute the meaning from the location and the symbol it references
|
||||
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations());
|
||||
|
||||
var scope = getSymbolScope(symbol, node);
|
||||
var scope = getSymbolScope(symbol);
|
||||
|
||||
if (scope) {
|
||||
result = [];
|
||||
|
@ -2184,11 +2184,44 @@ module ts {
|
|||
|
||||
return result;
|
||||
|
||||
function getSymbolScope(symbol: Symbol, node: Node): Node {
|
||||
/// TODO: find the enclosing scope
|
||||
function getSymbolScope(symbol: Symbol): Node {
|
||||
// If this is private property or method, the scope is the containing class
|
||||
if (symbol.getFlags() && (SymbolFlags.Property | SymbolFlags.Method)) {
|
||||
var privateDeclaration = forEach(symbol.getDeclarations(), d => (d.flags & NodeFlags.Private) ? d : undefined);
|
||||
if (privateDeclaration) {
|
||||
return privateDeclaration.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// if this symbol is visible from its parent container, e.g. exported, then bail out
|
||||
if (symbol.parent) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var scope: Node = undefined;
|
||||
|
||||
var declarations = symbol.getDeclarations();
|
||||
for (var i = 0, n = declarations.length; i < n; i++) {
|
||||
var container = getContainerNode(declarations[i]);
|
||||
|
||||
if (scope && scope !== container) {
|
||||
// Diffrent declarations have diffrent containers, bail out
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (container.kind === SyntaxKind.SourceFile && !isExternalModule(<SourceFile>container)) {
|
||||
// This is a global variable and not an external module, any declaration defined
|
||||
// withen this scope is visible outside the file
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// The search scope is the container node
|
||||
scope = container;
|
||||
}
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, start: number, end: number): number[] {
|
||||
var positions: number[] = [];
|
||||
|
||||
|
|
17
tests/cases/fourslash/referencesForGlobals2.ts
Normal file
17
tests/cases/fourslash/referencesForGlobals2.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// Global class reference.
|
||||
|
||||
// @Filename: referencesForGlobals_1.ts
|
||||
////class /*2*/globalClass {
|
||||
//// public f() { }
|
||||
////}
|
||||
|
||||
// @Filename: referencesForGlobals_2.ts
|
||||
////var c = /*1*/globalClass();
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(2);
|
17
tests/cases/fourslash/referencesForGlobals3.ts
Normal file
17
tests/cases/fourslash/referencesForGlobals3.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// Global interface reference.
|
||||
|
||||
// @Filename: referencesForGlobals_1.ts
|
||||
////interface /*2*/globalInterface {
|
||||
//// f();
|
||||
////}
|
||||
|
||||
// @Filename: referencesForGlobals_2.ts
|
||||
////var i: /*1*/globalInterface;
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(2);
|
17
tests/cases/fourslash/referencesForGlobals4.ts
Normal file
17
tests/cases/fourslash/referencesForGlobals4.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// Global module reference.
|
||||
|
||||
// @Filename: referencesForGlobals_1.ts
|
||||
////module /*2*/globalModule {
|
||||
//// export f() { };
|
||||
////}
|
||||
|
||||
// @Filename: referencesForGlobals_2.ts
|
||||
////var m = /*1*/globalModule;
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(2);
|
19
tests/cases/fourslash/referencesForGlobals5.ts
Normal file
19
tests/cases/fourslash/referencesForGlobals5.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// Global module reference.
|
||||
|
||||
// @Filename: referencesForGlobals_1.ts
|
||||
////module globalModule {
|
||||
//// export var x;
|
||||
////}
|
||||
////
|
||||
////import /*2*/globalAlias = globalModule;
|
||||
|
||||
// @Filename: referencesForGlobals_2.ts
|
||||
////var m = /*1*/globalAlias;
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(2);
|
Loading…
Reference in a new issue