Skip to content

Commit 85426a5

Browse files
authored
Merge pull request #1408 from zooba/entry-race
Fixes race condition from unloading files before clearing local information
2 parents 8e1b7c1 + 7a04a3c commit 85426a5

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Collections.Generic;
1919
using System.Reflection;
2020
using Microsoft.PythonTools.Analysis;
21+
using Microsoft.PythonTools.Infrastructure;
2122
using Microsoft.PythonTools.Interpreter;
2223
using Microsoft.PythonTools.Ipc.Json;
2324
using Microsoft.PythonTools.Parsing;
@@ -310,6 +311,8 @@ public sealed class UnloadFileRequest : Request<Response> {
310311

311312
public int fileId;
312313
public override string command => Command;
314+
315+
public override string ToString() => "{0}:{1}".FormatUI(command, fileId);
313316
}
314317

315318

@@ -329,6 +332,8 @@ public sealed class FileUpdateRequest : Request<FileUpdateResponse> {
329332
public FileUpdate[] updates;
330333

331334
public override string command => Command;
335+
336+
public override string ToString() => "{0}:{1} ({2} updates)".FormatUI(command, fileId, updates.Length);
332337
}
333338

334339
public enum FileUpdateKind {

Python/Product/Ipc.Json/Request.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace Microsoft.PythonTools.Ipc.Json {
2424
public class Request {
2525
[JsonIgnore]
2626
public virtual string command => null;
27+
28+
public override string ToString() => command;
2729
}
2830

2931
public class GenericRequest : Request<Response> {

Python/Product/PythonTools/PythonTools/Intellisense/ProjectAnalyzer.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1339,14 +1339,15 @@ internal async Task StopAnalyzingDirectoryAsync(string directory) {
13391339

13401340
internal async Task UnloadFileAsync(AnalysisEntry entry) {
13411341
_analysisComplete = false;
1342-
await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false);
13431342
AnalysisEntry removed;
13441343
_projectFiles.TryRemove(entry.Path, out removed);
13451344
_projectFilesById.TryRemove(entry.FileId, out removed);
13461345

13471346
_errorProvider.Clear(entry, ParserTaskMoniker);
13481347
_errorProvider.Clear(entry, UnresolvedImportMoniker);
13491348
_commentTaskProvider.Clear(entry, ParserTaskMoniker);
1349+
1350+
await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false);
13501351
}
13511352

13521353
internal void ClearAllTasks() {
@@ -1380,7 +1381,7 @@ private void OnShouldWarnOnLaunchChanged(AnalysisEntry entry) {
13801381
if (conn == null) {
13811382
return default(T);
13821383
}
1383-
Debug.WriteLine(String.Format("{1} Sending request {0}", request.command, DateTime.Now));
1384+
Debug.WriteLine(String.Format("{1} Sending request {0}", request, DateTime.Now));
13841385
T res = defaultValue;
13851386
try {
13861387
res = await conn.SendRequestAsync(request, _processExitedCancelSource.Token).ConfigureAwait(false);
@@ -1391,7 +1392,7 @@ private void OnShouldWarnOnLaunchChanged(AnalysisEntry entry) {
13911392
} catch (FailedRequestException e) {
13921393
_pyService.Logger.LogEvent(Logging.PythonLogEvent.AnalysisOpertionFailed, e.Message);
13931394
}
1394-
Debug.WriteLine(String.Format("{1} Done sending request {0}", request.command, DateTime.Now));
1395+
Debug.WriteLine(String.Format("{1} Done sending request {0}", request, DateTime.Now));
13951396
return res;
13961397
}
13971398

0 commit comments

Comments
 (0)