From 4b4066b17cb83ba700a9375f2894c9e9f5f5aac3 Mon Sep 17 00:00:00 2001 From: Thomas Willson Date: Wed, 29 Sep 2021 20:06:05 +0100 Subject: [PATCH] Fix handling of message beginning on error code line. Also, add test covering this behavior. --- src/diagnostics/iar.ts | 14 ++++++-------- test/unit-tests/diagnostics.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/diagnostics/iar.ts b/src/diagnostics/iar.ts index 38764992..d328abb3 100644 --- a/src/diagnostics/iar.ts +++ b/src/diagnostics/iar.ts @@ -7,7 +7,7 @@ import * as vscode from 'vscode'; import {oneLess, RawDiagnosticParser, FeedLineResult, RawDiagnostic} from './util'; const CODE_REGEX - = /^\"(?.*)\",(?\d+)\s+(?[A-Za-z]+)\[(?[A-Za-z]+[0-9]+)\]:/; + = /^\"(?.*)\",(?\d+)\s+(?[A-Za-z ]+)\[(?[A-Za-z]+[0-9]+)\]:(?.*)$/; 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; } diff --git a/test/unit-tests/diagnostics.test.ts b/test/unit-tests/diagnostics.test.ts index cb3323f1..1f15eff6 100644 --- a/test/unit-tests/diagnostics.test.ts +++ b/test/unit-tests/diagnostics.test.ts @@ -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 ', + ' ^', + '"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'); + }); });