Skip to content

Commit 4053dca

Browse files
committed
Added async cancellation support.
1 parent 328cf14 commit 4053dca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

server/src/project/document.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Range, TextDocument } from 'vscode-languageserver-textdocument';
66
import { SyntaxParser } from './parser/vbaSyntaxParser';
77
import { FoldingRange } from '../capabilities/folding';
88
import { SemanticTokensManager } from '../capabilities/semanticTokens';
9+
import { ParseCancellationException } from 'antlr4ng';
910

1011
export interface DocumentSettings {
1112
maxDocumentLines: number;
@@ -134,13 +135,28 @@ export abstract class BaseProjectDocument {
134135
}
135136

136137
async parseAsync(token: CancellationToken): Promise<void> {
138+
// Handle already cancelled.
139+
if (token.isCancellationRequested) {
140+
throw new ParseCancellationException(Error('Parse operation cancelled before it started.'));
141+
}
142+
143+
// Listen for cancellation event.
144+
token.onCancellationRequested(() => {
145+
throw new ParseCancellationException(new Error('Parse operation cancelled during parse.'));
146+
})
147+
148+
// Don't parse oversize documents.
137149
if (await this.isOversize) {
138150
console.log(`Document oversize: ${this.textDocument.lineCount} lines.`);
139151
console.warn(`Syntax parsing has been disabled to prevent crashing.`);
140152
this._isBusy = false;
141153
return;
142154
}
155+
156+
// Parse the document.
143157
await (new SyntaxParser()).parseAsync(this, token)
158+
159+
// Evaluate the diagnostics.
144160
this._hasDiagnosticElements.forEach(element => {
145161
element.evaluateDiagnostics;
146162
this._diagnostics.concat(element.diagnostics);

0 commit comments

Comments
 (0)