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

Commit b423ed8

Browse files
authored
Prevent crashes when the AST happens to be null (#1405)
1 parent 754a668 commit b423ed8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/LanguageServer/Impl/Indexing/MostRecentDocumentSymbols.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Python.Analysis.Documents;
88
using Microsoft.Python.Core;
99
using Microsoft.Python.Core.Diagnostics;
10+
using Microsoft.Python.Parsing.Ast;
1011

1112
namespace Microsoft.Python.LanguageServer.Indexing {
1213
class MostRecentDocumentSymbols : IMostRecentDocumentSymbols {
@@ -120,7 +121,20 @@ public void Dispose() {
120121
}
121122

122123
private async Task<IReadOnlyList<HierarchicalSymbol>> IndexAsync(IDocument doc, CancellationToken indexCt) {
123-
var ast = await doc.GetAstAsync(indexCt);
124+
PythonAst ast = null;
125+
126+
for (var i = 0; i < 5; i++) {
127+
ast = await doc.GetAstAsync(indexCt);
128+
if (ast != null) {
129+
break;
130+
}
131+
await Task.Delay(100);
132+
}
133+
134+
if (ast == null) {
135+
return Array.Empty<HierarchicalSymbol>();
136+
}
137+
124138
indexCt.ThrowIfCancellationRequested();
125139
var walker = new SymbolIndexWalker(ast);
126140
ast.Walk(walker);

0 commit comments

Comments
 (0)