diff --git a/src/LanguageServer/Impl/Indexing/MostRecentDocumentSymbols.cs b/src/LanguageServer/Impl/Indexing/MostRecentDocumentSymbols.cs index 2096e26fc..fe8b6969b 100644 --- a/src/LanguageServer/Impl/Indexing/MostRecentDocumentSymbols.cs +++ b/src/LanguageServer/Impl/Indexing/MostRecentDocumentSymbols.cs @@ -7,6 +7,7 @@ using Microsoft.Python.Analysis.Documents; using Microsoft.Python.Core; using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Indexing { class MostRecentDocumentSymbols : IMostRecentDocumentSymbols { @@ -120,7 +121,20 @@ public void Dispose() { } private async Task> IndexAsync(IDocument doc, CancellationToken indexCt) { - var ast = await doc.GetAstAsync(indexCt); + PythonAst ast = null; + + for (var i = 0; i < 5; i++) { + ast = await doc.GetAstAsync(indexCt); + if (ast != null) { + break; + } + await Task.Delay(100); + } + + if (ast == null) { + return Array.Empty(); + } + indexCt.ThrowIfCancellationRequested(); var walker = new SymbolIndexWalker(ast); ast.Walk(walker);