Initial refactoring so that watch from tsc follows the tsserver projects

This commit is contained in:
Sheetal Nandi
2017-07-24 16:57:49 -07:00
parent 94a589b3bb
commit ef5935b52c
12 changed files with 970 additions and 518 deletions

View File

@@ -292,77 +292,4 @@ namespace ts.server {
deleted(oldItems[oldIndex++]);
}
}
export function cleanExistingMap<T>(
existingMap: Map<T>,
onDeleteExistingValue: (key: string, existingValue: T) => void) {
if (existingMap) {
// Remove all
existingMap.forEach((existingValue, key) => {
existingMap.delete(key);
onDeleteExistingValue(key, existingValue);
});
}
}
export function mutateExistingMapWithNewSet<T>(
existingMap: Map<T>, newMap: Map<true>,
createNewValue: (key: string) => T,
onDeleteExistingValue: (key: string, existingValue: T) => void
): Map<T> {
return mutateExistingMap(
existingMap, newMap,
/*createNewValue*/(key, _valueInNewMap) => createNewValue(key),
onDeleteExistingValue,
);
}
export function mutateExistingMap<T, U>(
existingMap: Map<T>, newMap: Map<U>,
createNewValue: (key: string, valueInNewMap: U) => T,
onDeleteExistingValue: (key: string, existingValue: T) => void,
isSameValue?: (existingValue: T, valueInNewMap: U) => boolean,
OnDeleteExistingMismatchValue?: (key: string, existingValue: T) => void,
onSameExistingValue?: (existingValue: T, valueInNewMap: U) => void
): Map<T> {
// If there are new values update them
if (newMap) {
if (existingMap) {
// Needs update
existingMap.forEach((existingValue, key) => {
const valueInNewMap = newMap.get(key);
// Existing value - remove it
if (valueInNewMap === undefined) {
existingMap.delete(key);
onDeleteExistingValue(key, existingValue);
}
// different value - remove it
else if (isSameValue && !isSameValue(existingValue, valueInNewMap)) {
existingMap.delete(key);
OnDeleteExistingMismatchValue(key, existingValue);
}
else if (onSameExistingValue) {
onSameExistingValue(existingValue, valueInNewMap);
}
});
}
else {
// Create new
existingMap = createMap<T>();
}
// Add new values that are not already present
newMap.forEach((valueInNewMap, key) => {
if (!existingMap.has(key)) {
// New values
existingMap.set(key, createNewValue(key, valueInNewMap));
}
});
return existingMap;
}
cleanExistingMap(existingMap, onDeleteExistingValue);
return undefined;
}
}