From c015acae97b418e1bc94dfb68143ce5072459c58 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Fri, 17 Aug 2018 16:33:55 -0700 Subject: [PATCH] Handle analyzer shutdown during file transfer. --- .../Intellisense/ProjectAnalyzer.cs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs b/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs index 3ecf5ed402..e33a65ff4d 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs @@ -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; @@ -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) { + } } } }