Merge pull request #8756 from Microsoft/no_navigate_to_import

Don't include imports in navigateTo if the imported declaration is also in the items and has the same name
This commit is contained in:
Andy 2016-05-23 13:07:14 -07:00
commit 5035df665d
3 changed files with 30 additions and 3 deletions

View File

@ -2,7 +2,7 @@
namespace ts.NavigateTo {
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
export function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] {
export function getNavigateToItems(program: Program, checker: TypeChecker, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] {
const patternMatcher = createPatternMatcher(searchValue);
let rawItems: RawNavigateToItem[] = [];
@ -49,6 +49,19 @@ namespace ts.NavigateTo {
}
});
// Remove imports when the imported declaration is already in the list and has the same name.
rawItems = filter(rawItems, item => {
const decl = item.declaration;
if (decl.kind === SyntaxKind.ImportClause || decl.kind === SyntaxKind.ImportSpecifier || decl.kind === SyntaxKind.ImportEqualsDeclaration) {
const importer = checker.getSymbolAtLocation(decl.name);
const imported = checker.getAliasedSymbol(importer);
return importer.name !== imported.name;
}
else {
return true;
}
});
rawItems.sort(compareNavigateToItems);
if (maxResultCount !== undefined) {
rawItems = rawItems.slice(0, maxResultCount);

View File

@ -6606,8 +6606,8 @@ namespace ts {
/// NavigateTo
function getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[] {
synchronizeHostData();
return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount);
const checker = getProgram().getTypeChecker();
return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount);
}
function getEmitOutput(fileName: string): EmitOutput {

View File

@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />
// @Filename: library.ts
////export function foo() {}
////export function bar() {}
// @Filename: user.ts
////import {foo, bar as baz} from './library';
verify.navigationItemsListCount(1, "foo");
verify.navigationItemsListContains("foo", "function", "foo", "exact");
verify.navigationItemsListCount(1, "bar");
verify.navigationItemsListContains("bar", "function", "bar", "exact");
verify.navigationItemsListCount(1, "baz");
verify.navigationItemsListContains("baz", "alias", "baz", "exact");