Fix issue with cancellation corrupting LS state.

The problem here was as follows:
1) Host calls into the LS to do some sort of operation.
2) LS tries to synchronize with the host.
3) During synchronization we attempt to create a new program.
4) Creating the new program causes us to incrementally update some source files.
5) Incrementally updating a source file produces a new source file, and invalidates the old one.
6) *Then* the host asks to cancel this operation.
7) THe synchronization process cancels itself, leaving the LS in an inconsistent state where some
   of its source files have had their trees updated, but the information about the source file still
   thinks that we have the previous version.

The fix is to not allow cancellation during host synchronization.  Once we start, we have to go
all the way to completion.
This commit is contained in:
Cyrus Najmabadi 2015-02-09 17:03:46 -08:00
parent b277695a54
commit 11d19e3019

View file

@ -2022,6 +2022,12 @@ module ts {
return;
}
// IMPORTANT - It is critical from this moment onward that we do not check
// cancellation tokens. We are about to mutate source files from a previous program
// instance. If we cancel midway through, we may end up in an inconsistent state where
// the program points to old source files that have been invalidated because of
// incremental parsing.
var oldSettings = program && program.getCompilerOptions();
var newSettings = hostCache.compilationSettings();
var changesInCompilationSettingsAffectSyntax = oldSettings && oldSettings.target !== newSettings.target;
@ -2056,8 +2062,6 @@ module ts {
return;
function getOrCreateSourceFile(fileName: string): SourceFile {
cancellationToken.throwIfCancellationRequested();
// The program is asking for this file, check first if the host can locate it.
// If the host can not locate the file, then it does not exist. return undefined
// to the program to allow reporting of errors for missing files.
@ -5363,9 +5367,6 @@ module ts {
cancellationToken.throwIfCancellationRequested();
var fileContents = sourceFile.text;
cancellationToken.throwIfCancellationRequested();
var result: TodoComment[] = [];
if (descriptors.length > 0) {