From 7a04a3cae0f51c67fc0aee68f8b5225d718820a3 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 7 Jul 2016 12:39:45 -0700 Subject: [PATCH] Fixes race condition from unloading files before clearing local information. Improves AnalysisProtocol logging. --- Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs | 5 +++++ Python/Product/Ipc.Json/Request.cs | 2 ++ .../PythonTools/Intellisense/ProjectAnalyzer.cs | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs b/Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs index 0b9e05e12e..db107eb494 100644 --- a/Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs +++ b/Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Reflection; using Microsoft.PythonTools.Analysis; +using Microsoft.PythonTools.Infrastructure; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Ipc.Json; using Microsoft.PythonTools.Parsing; @@ -310,6 +311,8 @@ public sealed class UnloadFileRequest : Request { public int fileId; public override string command => Command; + + public override string ToString() => "{0}:{1}".FormatUI(command, fileId); } @@ -329,6 +332,8 @@ public sealed class FileUpdateRequest : Request { public FileUpdate[] updates; public override string command => Command; + + public override string ToString() => "{0}:{1} ({2} updates)".FormatUI(command, fileId, updates.Length); } public enum FileUpdateKind { diff --git a/Python/Product/Ipc.Json/Request.cs b/Python/Product/Ipc.Json/Request.cs index 3e4660eb27..dd9a78faa0 100644 --- a/Python/Product/Ipc.Json/Request.cs +++ b/Python/Product/Ipc.Json/Request.cs @@ -24,6 +24,8 @@ namespace Microsoft.PythonTools.Ipc.Json { public class Request { [JsonIgnore] public virtual string command => null; + + public override string ToString() => command; } public class GenericRequest : Request { diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs b/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs index 1c7160ddd9..8dd0abc48e 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs @@ -1339,7 +1339,6 @@ internal async Task StopAnalyzingDirectoryAsync(string directory) { internal async Task UnloadFileAsync(AnalysisEntry entry) { _analysisComplete = false; - await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false); AnalysisEntry removed; _projectFiles.TryRemove(entry.Path, out removed); _projectFilesById.TryRemove(entry.FileId, out removed); @@ -1347,6 +1346,8 @@ internal async Task UnloadFileAsync(AnalysisEntry entry) { _errorProvider.Clear(entry, ParserTaskMoniker); _errorProvider.Clear(entry, UnresolvedImportMoniker); _commentTaskProvider.Clear(entry, ParserTaskMoniker); + + await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false); } internal void ClearAllTasks() { @@ -1380,7 +1381,7 @@ private void OnShouldWarnOnLaunchChanged(AnalysisEntry entry) { if (conn == null) { return default(T); } - Debug.WriteLine(String.Format("{1} Sending request {0}", request.command, DateTime.Now)); + Debug.WriteLine(String.Format("{1} Sending request {0}", request, DateTime.Now)); T res = defaultValue; try { res = await conn.SendRequestAsync(request, _processExitedCancelSource.Token).ConfigureAwait(false); @@ -1391,7 +1392,7 @@ private void OnShouldWarnOnLaunchChanged(AnalysisEntry entry) { } catch (FailedRequestException e) { _pyService.Logger.LogEvent(Logging.PythonLogEvent.AnalysisOpertionFailed, e.Message); } - Debug.WriteLine(String.Format("{1} Done sending request {0}", request.command, DateTime.Now)); + Debug.WriteLine(String.Format("{1} Done sending request {0}", request, DateTime.Now)); return res; }