Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit c28a553

Browse files
author
MikhailArkhipov
committed
PR
1 parent 5d9fa49 commit c28a553

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/Analysis/Engine/Impl/ProjectEntry.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,12 @@ public IPythonParse GetCurrentParse() {
157157

158158
internal void SetCompleteAnalysis() {
159159
lock (this) {
160-
if (AnalysisVersion >= _expectedParse) {
161-
_analysisTcs.TrySetResult(Analysis);
160+
if (AnalysisVersion < _expectedParse) {
161+
return;
162162
}
163+
_analysisTcs.TrySetResult(Analysis);
163164
}
164-
if (AnalysisVersion >= _expectedParse) {
165-
RaiseNewAnalysis();
166-
}
165+
RaiseNewAnalysis();
167166
}
168167

169168
internal void ResetCompleteAnalysis() {
@@ -294,7 +293,7 @@ private void Parse(bool enqueueOnly, CancellationToken cancel) {
294293
string pathPrefix = PathUtils.EnsureEndSeparator(Path.GetDirectoryName(FilePath));
295294
var children =
296295
from pair in ProjectState.ModulesByFilename
297-
// Is the candidate child package in a subdirectory of our package?
296+
// Is the candidate child package in a subdirectory of our package?
298297
let fileName = pair.Key
299298
where fileName.StartsWithOrdinal(pathPrefix, ignoreCase: true)
300299
let moduleName = pair.Value.Name

src/LanguageServer/Impl/Implementation/Server.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,37 +584,44 @@ private IDisposable GetDocumentParseCounter(IDocument doc, out int count) {
584584
}
585585
}
586586

587-
internal async Task EnqueueItemAsync(IDocument doc, AnalysisPriority priority = AnalysisPriority.Normal, bool parse = true, bool enqueueForAnalysis = true) {
587+
internal Task EnqueueItemAsync(IDocument doc, AnalysisPriority priority = AnalysisPriority.Normal, bool parse = true, bool enqueueForAnalysis = true) {
588588
_disposableBag.ThrowIfDisposed();
589589
var pending = _pendingAnalysisEnqueue.Incremented();
590590
try {
591591
var entry = doc as ProjectEntry;
592592
entry?.ResetCompleteAnalysis();
593593

594-
// If we don't need to parse, use null cooking
595-
IAnalysisCookie cookie = null;
594+
// If we don't need to parse, use null cookie
595+
var cookieTask = Task.FromResult<IAnalysisCookie>(null);
596596
if (parse) {
597597
using (GetDocumentParseCounter(doc, out var count)) {
598598
if (count > 3) {
599599
// Rough check to prevent unbounded queueing. If we have
600600
// multiple parses in queue, we will get the latest doc
601601
// version in one of the ones to come.
602-
return;
602+
return Task.CompletedTask;
603603
}
604604
TraceMessage($"Parsing document {doc.DocumentUri}");
605-
cookie = await ParseQueue.EnqueueAsync(doc, Analyzer.LanguageVersion);
605+
cookieTask = ParseQueue.EnqueueAsync(doc, Analyzer.LanguageVersion);
606606
}
607607
}
608608

609609
// The call must be fire and forget, but should not be yielding.
610610
// It is called from DidChangeTextDocument which must fully finish
611611
// since otherwise Complete() may come before the change is enqueued
612612
// for processing and the completion list will be driven off the stale data.
613-
var p = pending;
614-
await OnDocumentChangeProcessingCompleteAsync(doc, cookie as VersionCookie, enqueueForAnalysis, priority, p);
615-
pending = null;
616-
} finally {
613+
return cookieTask.ContinueWith(async t => {
614+
if (t.IsFaulted) {
615+
// Happens when file got deleted before processing
616+
pending.Dispose();
617+
LogMessage(MessageType.Error, t.Exception.Message);
618+
return;
619+
}
620+
await OnDocumentChangeProcessingCompleteAsync(doc, t.Result as VersionCookie, enqueueForAnalysis, priority, pending);
621+
});
622+
} catch {
617623
pending?.Dispose();
624+
throw;
618625
}
619626
}
620627

0 commit comments

Comments
 (0)