Skip to content

Commit

Permalink
Handle analyzer shutdown during file transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba committed Aug 17, 2018
1 parent 2b8ae79 commit c015aca
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,22 @@ internal async Task TransferFromOldAnalyzer(VsProjectAnalyzer oldAnalyzer) {

var entries = (await AnalyzeFileAsync(oldBulkEntries)).ToList();
foreach (var e in oldEntries) {
if (!IsActive) {
// We've been shut down - abort
return;
}

if (e.IsTemporaryFile || e.SuppressErrorList) {
var entry = await AnalyzeFileAsync(e.Path, null, e.IsTemporaryFile, e.SuppressErrorList);
for (int retries = 3; retries > 0 && entry == null; --retries) {
for (int retries = 3; retries > 0 && entry == null && IsActive; --retries) {
// Likely in the process of changing analyzer, so we'll delay slightly and retry.
await Task.Delay(100);
entry = await AnalyzeFileAsync(e.Path, null, e.IsTemporaryFile, e.SuppressErrorList);
}
if (!IsActive) {
// We've been shut down - abort
return;
}
if (entry == null) {
Debug.Fail($"Failed to analyze file {e.Path}");
continue;
Expand All @@ -961,16 +970,28 @@ internal async Task TransferFromOldAnalyzer(VsProjectAnalyzer oldAnalyzer) {
if (e == null) {
continue;
}
if (!IsActive) {
// We've been shut down - abort
return;
}

if (oldBuffers.TryGetValue(e.Path, out ITextBuffer[] buffers)) {
foreach (var b in buffers.MaybeEnumerate()) {
if (!IsActive) {
// We've been shut down - abort
return;
}

PythonTextBufferInfo.MarkForReplacement(b);
var bi = _services.GetBufferInfo(b);
var actualEntry = bi.TrySetAnalysisEntry(e, null);
var bp = actualEntry?.GetOrCreateBufferParser(_services);
if (bp != null) {
bp.AddBuffer(b);
await bp.EnsureCodeSyncedAsync(b);
try {
bp.AddBuffer(b);
await bp.EnsureCodeSyncedAsync(b);
} catch (InvalidOperationException) {
}
}
}
}
Expand Down

0 comments on commit c015aca

Please sign in to comment.