Skip to content

Commit 16f51e6

Browse files
committed
Support for parser error diagnostics
1 parent efbd752 commit 16f51e6

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

server/src/capabilities/diagnostics.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,11 @@ export class LegacyFunctionalityDiagnostic extends BaseDiagnostic {
124124
constructor(range: Range, functionalityType: string) {
125125
super(range, `${functionalityType} are legacy functionality and should be avoided.`);
126126
}
127+
}
128+
129+
export class ParserErrorDiagnostic extends BaseDiagnostic {
130+
severity = DiagnosticSeverity.Error;
131+
constructor(range: Range, msg: string) {
132+
super(range, msg);
133+
}
127134
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Core
2+
import { TextDocument } from 'vscode-languageserver-textdocument';
3+
4+
// Antlr
5+
import { ErrorNode, ParserRuleContext } from 'antlr4ng';
6+
7+
// Project
8+
import { BaseContextSyntaxElement, BaseSyntaxElement } from './base';
9+
import { DiagnosticCapability } from '../../capabilities/capabilities';
10+
import { ParserErrorDiagnostic } from '../../capabilities/diagnostics';
11+
12+
13+
export class ErrorRuleElement extends BaseContextSyntaxElement<ParserRuleContext> {
14+
constructor(node: ErrorNode, doc: TextDocument) {
15+
super(node.parent as ParserRuleContext, doc);
16+
this.diagnosticCapability = new DiagnosticCapability(this);
17+
this.diagnosticCapability.diagnostics.push(
18+
new ParserErrorDiagnostic(this.context.range, node.getText())
19+
);
20+
}
21+
}

server/src/project/workspace.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ export class Workspace implements IWorkspace {
118118
await this.activeDocument.parseAsync(this.parseCancellationTokenSource.token);
119119
this.logger.info(`Parsed ${this.activeDocument.name}`);
120120
this.connection.sendDiagnostics(this.activeDocument.languageServerDiagnostics());
121-
} catch (e) {
121+
} catch (e) {
122122
// Swallow cancellation exceptions. They're good. We like these.
123123
if (e instanceof ParseCancellationException) { }
124124
else if (e instanceof Error) { this.logger.stack(e); }
125-
else { this.logger.error('Something went wrong.')}
125+
else { this.logger.error('Something went wrong.') }
126126
}
127127

128128
this.parseCancellationTokenSource = undefined;
@@ -328,6 +328,7 @@ class WorkspaceEvents {
328328
}
329329

330330
private async onDocumentSymbolAsync(params: DocumentSymbolParams, token: CancellationToken): Promise<SymbolInformation[]> {
331+
Services.logger.debug('[event] onDocumentSymbol');
331332
const document = await this.getParsedProjectDocument(params.textDocument.uri, 0, token);
332333
return document?.languageServerSymbolInformation() ?? [];
333334
}

0 commit comments

Comments
 (0)