Skip to content

Commit 2835e25

Browse files
committed
Enable navigateTo on all projects for a file
1 parent 7663a96 commit 2835e25

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

src/server/session.ts

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ namespace ts.server {
481481
return accum;
482482
}, []);
483483

484-
ts.addRange(locs, bakedRenameLocs);
484+
addRange(locs, bakedRenameLocs);
485485
}
486486

487-
return { info: renameInfo, locs: ts.deduplicate(locs, areSpanGroupsForTheSameFile) };
487+
return { info: renameInfo, locs: deduplicate(locs, areSpanGroupsForTheSameFile) };
488488

489489
function areSpanGroupsForTheSameFile(a: protocol.SpanGroup, b: protocol.SpanGroup) {
490490
if (a && b) {
@@ -537,11 +537,11 @@ namespace ts.server {
537537
};
538538
}).sort(compareFileStart);
539539

540-
ts.addRange(refs, bakedRefs);
540+
addRange(refs, bakedRefs);
541541
}
542542

543543
return {
544-
refs: ts.deduplicate(refs, areReferencesResponseItemsForTheSameLocation),
544+
refs: deduplicate(refs, areReferencesResponseItemsForTheSameLocation),
545545
symbolName: nameText,
546546
symbolStartOffset: nameColStart,
547547
symbolDisplayString: displayString
@@ -868,41 +868,57 @@ namespace ts.server {
868868

869869
private getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
870870
const file = ts.normalizePath(fileName);
871-
const project = this.projectService.getProjectForFile(file);
872-
if (!project) {
871+
const defaultProject = this.projectService.getProjectForFile(file);
872+
if (!defaultProject) {
873873
throw Errors.NoProject;
874874
}
875875

876-
const compilerService = project.compilerService;
877-
const navItems = compilerService.languageService.getNavigateToItems(searchValue, maxResultCount);
878-
if (!navItems) {
879-
return undefined;
876+
const info = this.projectService.getScriptInfo(file);
877+
const projects = this.projectService.findReferencingProjects(info);
878+
const allNavToItems: protocol.NavtoItem[] = [];
879+
for (const project of projects) {
880+
const compilerService = project.compilerService;
881+
const navItems = compilerService.languageService.getNavigateToItems(searchValue, maxResultCount);
882+
if (!navItems) {
883+
continue;
884+
}
885+
886+
const bakedNavItems = navItems.map((navItem) => {
887+
const start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start);
888+
const end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan));
889+
const bakedItem: protocol.NavtoItem = {
890+
name: navItem.name,
891+
kind: navItem.kind,
892+
file: navItem.fileName,
893+
start: start,
894+
end: end,
895+
};
896+
if (navItem.kindModifiers && (navItem.kindModifiers != "")) {
897+
bakedItem.kindModifiers = navItem.kindModifiers;
898+
}
899+
if (navItem.matchKind !== "none") {
900+
bakedItem.matchKind = navItem.matchKind;
901+
}
902+
if (navItem.containerName && (navItem.containerName.length > 0)) {
903+
bakedItem.containerName = navItem.containerName;
904+
}
905+
if (navItem.containerKind && (navItem.containerKind.length > 0)) {
906+
bakedItem.containerKind = navItem.containerKind;
907+
}
908+
return bakedItem;
909+
});
910+
addRange(allNavToItems, bakedNavItems);
880911
}
912+
return deduplicate(allNavToItems, areNavToItemsForTheSameLocation);
881913

882-
return navItems.map((navItem) => {
883-
const start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start);
884-
const end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan));
885-
const bakedItem: protocol.NavtoItem = {
886-
name: navItem.name,
887-
kind: navItem.kind,
888-
file: navItem.fileName,
889-
start: start,
890-
end: end,
891-
};
892-
if (navItem.kindModifiers && (navItem.kindModifiers != "")) {
893-
bakedItem.kindModifiers = navItem.kindModifiers;
894-
}
895-
if (navItem.matchKind !== "none") {
896-
bakedItem.matchKind = navItem.matchKind;
897-
}
898-
if (navItem.containerName && (navItem.containerName.length > 0)) {
899-
bakedItem.containerName = navItem.containerName;
900-
}
901-
if (navItem.containerKind && (navItem.containerKind.length > 0)) {
902-
bakedItem.containerKind = navItem.containerKind;
914+
function areNavToItemsForTheSameLocation(a: protocol.NavtoItem, b: protocol.NavtoItem) {
915+
if (a && b) {
916+
return a.file === b.file &&
917+
a.start === b.start &&
918+
a.end === b.end;
903919
}
904-
return bakedItem;
905-
});
920+
return false;
921+
}
906922
}
907923

908924
private getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] {

0 commit comments

Comments
 (0)