Fix handling of message beginning on error code line.

Also, add test covering this behavior.
This commit is contained in:
Thomas Willson 2021-09-29 20:06:05 +01:00
Родитель 0b6da4c968
Коммит 4b4066b17c
2 изменённых файлов: 29 добавлений и 8 удалений

Просмотреть файл

@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import {oneLess, RawDiagnosticParser, FeedLineResult, RawDiagnostic} from './util';
const CODE_REGEX
= /^\"(?<file>.*)\",(?<line>\d+)\s+(?<severity>[A-Za-z]+)\[(?<code>[A-Za-z]+[0-9]+)\]:/;
= /^\"(?<file>.*)\",(?<line>\d+)\s+(?<severity>[A-Za-z ]+)\[(?<code>[A-Za-z]+[0-9]+)\]:(?<message_start>.*)$/;
const POINTER_REGEX = /^( +)\^$/;
@ -24,6 +24,7 @@ export class Parser extends RawDiagnosticParser {
private translateSeverity(iar_severity: string): string {
switch (iar_severity) {
case 'Error':
case 'Fatal error':
return 'error';
case 'Warning':
return 'warning';
@ -58,14 +59,14 @@ export class Parser extends RawDiagnosticParser {
return FeedLineResult.NotMine;
}
const [full, file, lineno = '1', severity, code] = mat;
const [full, file, lineno = '1', severity, code, message_start] = mat;
if (file && severity) {
this.pending_diagnostic = {
full: full,
file: file,
location : new vscode.Range(oneLess(lineno), this.pending_column ?? 0, oneLess(lineno), 999),
severity: this.translateSeverity(severity),
message: "",
message: message_start ? message_start + ' ' : '', // Add space ready for the next line of the message. It'll be trimmed if there isn't an additional part to the message.
code: code,
related : []
};
@ -79,15 +80,12 @@ export class Parser extends RawDiagnosticParser {
const diagnostic = this.pending_diagnostic!;
if (line === '' || line[0] !== ' ') {
diagnostic.message = diagnostic.message.trim();
this.reset();
return diagnostic;
}
if (diagnostic.message !== '') {
diagnostic.message += '\n';
}
diagnostic.message += line.trim();
diagnostic.message += line.trim() + '\n';
diagnostic.full += `\n${line}`;
return FeedLineResult.Ok;
}

Просмотреть файл

@ -432,4 +432,27 @@ suite('Diagnostics', async () => {
expect(diagnostic.message).to.eq('identifier "kjfdlkj" is undefined');
expect(diagnostic.severity).to.eq('error');
});
test('Parse IAR fatal error', () => {
const lines = [
' #include <kjlkjl>',
' ^',
'"C:\\foo\\bar\\test.c",1 Fatal error[Pe1696]: cannot open source',
' file "kjlkjl"',
' searched: "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench',
' 8.0\\arm\\inc\\"',
' current directory: "C:\\Users\\user\\Documents"',
'Fatal error detected, aborting.'
];
feedLines(build_consumer, [], lines);
expect(build_consumer.compilers.iar.diagnostics).to.have.length(1);
const diagnostic = build_consumer.compilers.iar.diagnostics[0];
expect(diagnostic.file).to.eq('C:\\foo\\bar\\test.c');
expect(diagnostic.location.start.line).to.eq(0);
expect(diagnostic.location.start.character).to.eq(17);
expect(diagnostic.code).to.eq('Pe1696');
expect(diagnostic.message).to.eq('cannot open source file "kjlkjl"\nsearched: "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench\n8.0\\arm\\inc\\"\ncurrent directory: "C:\\Users\\user\\Documents"');
expect(diagnostic.severity).to.eq('error');
});
});