Skip to content

Commit bdf131a

Browse files
committed
Merge pull request #7353 from zhengbli/i2531
Enable tsserver global operations to be performed on all projects
2 parents 906ce18 + 8709975 commit bdf131a

File tree

6 files changed

+238
-128
lines changed

6 files changed

+238
-128
lines changed

src/compiler/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ namespace ts {
9191
return undefined;
9292
}
9393

94-
export function contains<T>(array: T[], value: T): boolean {
94+
export function contains<T>(array: T[], value: T, areEqual?: (a: T, b: T) => boolean): boolean {
9595
if (array) {
9696
for (const v of array) {
97-
if (v === value) {
97+
if (areEqual ? areEqual(v, value) : v === value) {
9898
return true;
9999
}
100100
}
@@ -156,12 +156,12 @@ namespace ts {
156156
return array1.concat(array2);
157157
}
158158

159-
export function deduplicate<T>(array: T[]): T[] {
159+
export function deduplicate<T>(array: T[], areEqual?: (a: T, b: T) => boolean): T[] {
160160
let result: T[];
161161
if (array) {
162162
result = [];
163163
for (const item of array) {
164-
if (!contains(result, item)) {
164+
if (!contains(result, item, areEqual)) {
165165
result.push(item);
166166
}
167167
}

src/server/editorServices.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ namespace ts.server {
498498
return copiedList;
499499
}
500500

501+
/**
502+
* This helper funciton processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
503+
*/
504+
export function combineProjectOutput<T>(projects: Project[], action: (project: Project) => T[], comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
505+
const result = projects.reduce<T[]>((previous, current) => concatenate(previous, action(current)), []).sort(comparer);
506+
return projects.length > 1 ? deduplicate(result, areEqual) : result;
507+
}
508+
501509
export interface ProjectServiceEventHandler {
502510
(eventName: string, project: Project, fileName: string): void;
503511
}

0 commit comments

Comments
 (0)