Skip to content

Commit e876532

Browse files
Improved error parsing when using verilator
1 parent 416807d commit e876532

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

src/linter/VerilatorLinter.ts

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,42 +107,78 @@ export default class VerilatorLinter extends BaseLinter {
107107
command,
108108
{ cwd: cwd },
109109
(_error: Error, _stdout: string, stderr: string) => {
110-
let diagnostics: vscode.Diagnostic[] = [];
110+
//let diagnostics: vscode.Diagnostic[] = [];
111+
112+
// basically DiagnosticsCollection but with ability to append diag lists
113+
let filesDiag = {};
114+
let error_warning_counter = 0;
111115
stderr.split(/\r?\n/g).forEach((line, _) => {
112-
if (line.search("No such file or directory") >= 0 || line.search("Not a directory") >= 0 || line.search("command not found") >= 0) {
113-
this.logger.error(`Could not execute command: ${command}`);
114-
return;
115-
}
116116

117-
if (!line.startsWith('%') || line.indexOf(docUri) <= 0) {
117+
if (!line.startsWith('%')) {
118+
this.logger.error(line);
118119
return;
119120
}
120121

122+
// for this regex, match sections are:
123+
// 1 - severity (warning/error)
124+
// 3 - error/warning code (EOFNEWLINE, ...),
125+
// 5 - file path
126+
// 9 - line number
127+
// 11 - column number
128+
// 12 - message
129+
121130
let rex = line.match(
122-
/%(\w+)(-[A-Z0-9_]+)?:\s*(\w+:)?(?:[^:]+):\s*(\d+):(?:\s*(\d+):)?\s*(\s*.+)/
131+
/(\w+)(-([A-Z0-9]+))?: ((\S+((\.sv)|(\.v))):(\d+):((\d+):)? )?(.*)/
123132
);
124133

134+
// vscode problems are tied to files, so if there is no file name, no point adding
135+
if (!rex[5]) {return;}
136+
137+
// replacing "\\" and "\" with "/" for consistency
138+
if (isWindows)
139+
{
140+
rex[5] = rex[5].replace(/(\\\\)|(\\)/, "/");
141+
}
142+
143+
// if no errors for this file, new list needs to be created
144+
if (!(rex[5] in Object.keys(filesDiag)))
145+
{
146+
filesDiag[rex[5]] = [];
147+
}
148+
149+
125150
if (rex && rex[0].length > 0) {
126-
let lineNum = Number(rex[4]) - 1;
127-
let colNum = Number(rex[5]) - 1;
151+
let lineNum = Number(rex[9]) - 1;
152+
let colNum = Number(rex[11]) - 1;
128153
// Type of warning is in rex[2]
129154
colNum = isNaN(colNum) ? 0 : colNum; // for older Verilator versions (< 4.030 ~ish)
130155

131156
if (!isNaN(lineNum)) {
132-
diagnostics.push({
157+
filesDiag[rex[5]].push({
133158
severity: this.convertToSeverity(rex[1]),
134159
range: new vscode.Range(lineNum, colNum, lineNum, Number.MAX_VALUE),
135-
message: rex[6],
136-
code: 'verilator',
160+
message: rex[12],
161+
code: rex[3],
137162
source: 'verilator',
138163
});
164+
165+
error_warning_counter++;
139166
}
140167
return;
141168
}
142169
this.logger.warn('[verilator] failed to parse error: ' + line);
143170
});
144-
this.logger.info(`[verilator] ${diagnostics.length} errors/warnings returned`);
145-
this.diagnosticCollection.set(doc.uri, diagnostics);
171+
this.logger.info(`[verilator] ${error_warning_counter} errors/warnings returned`);
172+
this.diagnosticCollection.clear()
173+
for (let fileName in filesDiag)
174+
{
175+
let fileURI = vscode.Uri.file(fileName);
176+
// adding diag info for each file
177+
this.diagnosticCollection.set(
178+
fileURI,
179+
filesDiag[fileName]
180+
);
181+
}
146182
}
147183
);
148184
}

0 commit comments

Comments
 (0)