Improve highlighting errors
ncordon opened this issue · comments
At the moment we are providing errors with a very simple syntax listener that admits for improvements (wrong position for the error sometimes):
export class ErrorListener implements ANTLRErrorListener<CommonToken> {
diagnostics: Diagnostic[];
constructor() {
this.diagnostics = [];
}
public syntaxError<T extends Token>(
recognizer: Recognizer<T, any>,
offendingSymbol: T | undefined,
line: number,
charPositionInLine: number,
msg: string,
_: RecognitionException | undefined,
): void {
const lineIndex = (offendingSymbol?.line ?? 1) - 1;
const start = offendingSymbol?.startIndex ?? 0;
const end = (offendingSymbol?.stopIndex ?? 0) + 1;
const diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Warning,
range: {
start: Position.create(lineIndex, start),
end: Position.create(lineIndex, end),
},
message: msg,
};
this.diagnostics.push(diagnostic);
}
}
The messages are unclear and they offer too many keywords most of the time:
Moved to Trello!