Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ namespace ts {
return undefined;
}

export function contains<T>(array: T[], value: T): boolean {
export function contains<T>(array: T[], value: T, areEqual?: (a: T, b: T) => boolean): boolean {
if (array) {
for (const v of array) {
if (v === value) {
if (areEqual ? areEqual(v, value) : v === value) {
return true;
}
}
Expand Down Expand Up @@ -156,12 +156,12 @@ namespace ts {
return array1.concat(array2);
}

export function deduplicate<T>(array: T[]): T[] {
export function deduplicate<T>(array: T[], areEqual?: (a: T, b: T) => boolean): T[] {
let result: T[];
if (array) {
result = [];
for (const item of array) {
if (!contains(result, item)) {
if (!contains(result, item, areEqual)) {
result.push(item);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ namespace ts.server {
return copiedList;
}

/**
* This helper funciton processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
*/
export function combineProjectOutput<T>(projects: Project[], action: (project: Project) => T[], comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
const result = projects.reduce<T[]>((previous, current) => concatenate(previous, action(current)), []).sort(comparer);
return projects.length > 1 ? deduplicate(result, areEqual) : result;
}

export interface ProjectServiceEventHandler {
(eventName: string, project: Project, fileName: string): void;
}
Expand Down
Loading