Skip to content

Commit 396ae07

Browse files
committed
Multiple analysis fixes.
- Fixes microsoft#1151: Reliable way to determine final analysis of a module - Fixes microsoft#1201: NRE in SymbolCollector.AddProperty - Fixes microsoft#1228: NRE in TryFindMissingDependencies - Fixes microsoft#1294: Handle valid case for reloading AST - Fixes microsoft#1295: FindReferences doesn't work on package init members - Fixes microsoft#1296: DependencyResolver graph misses intermediate imports - Part of the fix for microsoft#1174: All references are not listed when using ms language server
1 parent 4a26142 commit 396ae07

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/Analysis/Ast/Impl/Modules/PythonModule.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ private enum State {
5555

5656
private readonly DocumentBuffer _buffer = new DocumentBuffer();
5757
private readonly DisposeToken _disposeToken = DisposeToken.Create<PythonModule>();
58+
<<<<<<< HEAD
5859
private readonly object _syncObj = new object();
60+
=======
61+
private readonly object _analysisLock = new object();
62+
>>>>>>> Multiple analysis fixes.
5963
private IReadOnlyList<DiagnosticsEntry> _parseErrors = Array.Empty<DiagnosticsEntry>();
6064
private readonly Dictionary<object, Node> _astMap = new Dictionary<object, Node>();
6165
private readonly IDiagnosticsService _diagnosticsService;
@@ -252,7 +256,11 @@ public string Content {
252256
public async Task<PythonAst> GetAstAsync(CancellationToken cancellationToken = default) {
253257
Task t = null;
254258
while (true) {
259+
<<<<<<< HEAD
255260
lock (_syncObj) {
261+
=======
262+
lock (_analysisLock) {
263+
>>>>>>> Multiple analysis fixes.
256264
if (t == _parsingTask) {
257265
break;
258266
}
@@ -276,7 +284,11 @@ public async Task<PythonAst> GetAstAsync(CancellationToken cancellationToken = d
276284
public IEnumerable<DiagnosticsEntry> GetParseErrors() => _parseErrors.ToArray();
277285

278286
public void Update(IEnumerable<DocumentChange> changes) {
287+
<<<<<<< HEAD
279288
lock (_syncObj) {
289+
=======
290+
lock (_analysisLock) {
291+
>>>>>>> Multiple analysis fixes.
280292
_parseCts?.Cancel();
281293
_parseCts = new CancellationTokenSource();
282294

@@ -293,7 +305,11 @@ public void Update(IEnumerable<DocumentChange> changes) {
293305
}
294306

295307
public void Reset(string content) {
308+
<<<<<<< HEAD
296309
lock (_syncObj) {
310+
=======
311+
lock (_analysisLock) {
312+
>>>>>>> Multiple analysis fixes.
297313
if (content != Content) {
298314
ContentState = State.None;
299315
InitializeContent(content, _buffer.Version + 1);
@@ -321,7 +337,11 @@ private void Parse(CancellationToken cancellationToken) {
321337

322338
//Log?.Log(TraceEventType.Verbose, $"Parse begins: {Name}");
323339

340+
<<<<<<< HEAD
324341
lock (_syncObj) {
342+
=======
343+
lock (_analysisLock) {
344+
>>>>>>> Multiple analysis fixes.
325345
version = _buffer.Version;
326346
var options = new ParserOptions {
327347
StubFile = FilePath != null && Path.GetExtension(FilePath).Equals(".pyi", FileSystem.StringComparison)
@@ -337,7 +357,11 @@ private void Parse(CancellationToken cancellationToken) {
337357

338358
//Log?.Log(TraceEventType.Verbose, $"Parse complete: {Name}");
339359

360+
<<<<<<< HEAD
340361
lock (_syncObj) {
362+
=======
363+
lock (_analysisLock) {
364+
>>>>>>> Multiple analysis fixes.
341365
cancellationToken.ThrowIfCancellationRequested();
342366
if (version != _buffer.Version) {
343367
throw new OperationCanceledException();
@@ -367,7 +391,11 @@ private void Parse(CancellationToken cancellationToken) {
367391
analyzer.EnqueueDocumentForAnalysis(this, ast, version);
368392
}
369393

394+
<<<<<<< HEAD
370395
lock (_syncObj) {
396+
=======
397+
lock (_analysisLock) {
398+
>>>>>>> Multiple analysis fixes.
371399
_parsingTask = null;
372400
}
373401
}
@@ -384,7 +412,11 @@ public override void Add(string message, SourceSpan span, int errorCode, Severit
384412
#region IAnalyzable
385413

386414
public void NotifyAnalysisBegins() {
415+
<<<<<<< HEAD
387416
lock (_syncObj) {
417+
=======
418+
lock (_analysisLock) {
419+
>>>>>>> Multiple analysis fixes.
388420
if (_updated) {
389421
_updated = false;
390422
// In all variables find those imported, then traverse imported modules
@@ -412,7 +444,11 @@ public void NotifyAnalysisBegins() {
412444
}
413445

414446
public void NotifyAnalysisComplete(IDocumentAnalysis analysis) {
447+
<<<<<<< HEAD
415448
lock (_syncObj) {
449+
=======
450+
lock (_analysisLock) {
451+
>>>>>>> Multiple analysis fixes.
416452
if (analysis.Version < Analysis.Version) {
417453
return;
418454
}
@@ -448,20 +484,32 @@ protected virtual void OnAnalysisComplete() { }
448484

449485
#region IAstNodeContainer
450486
public Node GetAstNode(object o) {
487+
<<<<<<< HEAD
451488
lock (_syncObj) {
489+
=======
490+
lock (_analysisLock) {
491+
>>>>>>> Multiple analysis fixes.
452492
return _astMap.TryGetValue(o, out var n) ? n : null;
453493
}
454494
}
455495

456496
public void AddAstNode(object o, Node n) {
497+
<<<<<<< HEAD
457498
lock (_syncObj) {
499+
=======
500+
lock (_analysisLock) {
501+
>>>>>>> Multiple analysis fixes.
458502
Debug.Assert(!_astMap.ContainsKey(o) || _astMap[o] == n);
459503
_astMap[o] = n;
460504
}
461505
}
462506

463507
public void ClearContent() {
508+
<<<<<<< HEAD
464509
lock (_syncObj) {
510+
=======
511+
lock (_analysisLock) {
512+
>>>>>>> Multiple analysis fixes.
465513
if (ModuleType != ModuleType.User) {
466514
_buffer.Reset(_buffer.Version, string.Empty);
467515
_astMap.Clear();
@@ -492,7 +540,11 @@ protected virtual string LoadContent() {
492540
}
493541

494542
private void InitializeContent(string content, int version) {
543+
<<<<<<< HEAD
495544
lock (_syncObj) {
545+
=======
546+
lock (_analysisLock) {
547+
>>>>>>> Multiple analysis fixes.
496548
LoadContent(content, version);
497549

498550
var startParse = ContentState < State.Parsing && (_parsingTask == null || version > 0);

0 commit comments

Comments
 (0)