diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 174bcc17dfc..fc88f11408a 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -176,44 +176,6 @@ namespace ts.server { return [] as SortedArray; } - export function toSortedArray(arr: string[]): SortedArray; - export function toSortedArray(arr: T[], comparer: Comparer): SortedArray; - export function toSortedArray(arr: T[], comparer?: Comparer): SortedArray { - arr.sort(comparer); - return arr as SortedArray; - } - - export function enumerateInsertsAndDeletes(newItems: SortedReadonlyArray, oldItems: SortedReadonlyArray, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer) { - compare = compare || compareValues; - let newIndex = 0; - let oldIndex = 0; - const newLen = newItems.length; - const oldLen = oldItems.length; - while (newIndex < newLen && oldIndex < oldLen) { - const newItem = newItems[newIndex]; - const oldItem = oldItems[oldIndex]; - const compareResult = compare(newItem, oldItem); - if (compareResult === Comparison.LessThan) { - inserted(newItem); - newIndex++; - } - else if (compareResult === Comparison.GreaterThan) { - deleted(oldItem); - oldIndex++; - } - else { - newIndex++; - oldIndex++; - } - } - while (newIndex < newLen) { - inserted(newItems[newIndex++]); - } - while (oldIndex < oldLen) { - deleted(oldItems[oldIndex++]); - } - } - export class ThrottledOperations { private pendingTimeouts: Map = createMap(); constructor(private readonly host: ServerHost) { @@ -261,7 +223,10 @@ namespace ts.server { } } } +} +/* @internal */ +namespace ts.server { export function insertSorted(array: SortedArray, insert: T, compare: Comparer): void { if (array.length === 0) { array.push(insert); @@ -289,4 +254,42 @@ namespace ts.server { array.splice(removeIndex, 1); } } + + export function toSortedArray(arr: string[]): SortedArray; + export function toSortedArray(arr: T[], comparer: Comparer): SortedArray; + export function toSortedArray(arr: T[], comparer?: Comparer): SortedArray { + arr.sort(comparer); + return arr as SortedArray; + } + + export function enumerateInsertsAndDeletes(newItems: SortedReadonlyArray, oldItems: SortedReadonlyArray, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer) { + compare = compare || compareValues; + let newIndex = 0; + let oldIndex = 0; + const newLen = newItems.length; + const oldLen = oldItems.length; + while (newIndex < newLen && oldIndex < oldLen) { + const newItem = newItems[newIndex]; + const oldItem = oldItems[oldIndex]; + const compareResult = compare(newItem, oldItem); + if (compareResult === Comparison.LessThan) { + inserted(newItem); + newIndex++; + } + else if (compareResult === Comparison.GreaterThan) { + deleted(oldItem); + oldIndex++; + } + else { + newIndex++; + oldIndex++; + } + } + while (newIndex < newLen) { + inserted(newItems[newIndex++]); + } + while (oldIndex < oldLen) { + deleted(oldItems[oldIndex++]); + } + } } \ No newline at end of file