mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
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:
commit
5035df665d
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
14
tests/cases/fourslash/navigateToImport.ts
Normal file
14
tests/cases/fourslash/navigateToImport.ts
Normal 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");
|
||||
Loading…
x
Reference in New Issue
Block a user