Skip to content

Commit 3132795

Browse files
committed
chore: Refactors linter routines
1 parent bba4675 commit 3132795

File tree

1 file changed

+84
-78
lines changed

1 file changed

+84
-78
lines changed

src/features/linter-provider.ts

+84-78
Original file line numberDiff line numberDiff line change
@@ -304,100 +304,106 @@ export class FortranLintingProvider {
304304
* @returns Array of diagnostics for errors, warnings and infos
305305
*/
306306
private getLinterResults(msg: string): vscode.Diagnostic[] {
307+
// Ideally these regexes should be defined inside the linterParser functions
308+
// however we would have to rewrite out linting unit tests
307309
const regex = this.getCompilerREGEX(this.compiler);
308310
const matches = [...msg.matchAll(regex)];
309-
// const matches = msg.matchAll(regex);
310-
const diagnostics: vscode.Diagnostic[] = [];
311-
312311
switch (this.compiler) {
313312
case 'gfortran':
314-
for (const m of matches) {
315-
const g = m.groups;
316-
// NOTE: m[0] is the entire match and then the captured groups follow
317-
const fname: string = g['fname'] !== undefined ? g['fname'] : g['bin'];
318-
const lineNo: number = g['ln'] !== undefined ? parseInt(g['ln']) : 1;
319-
const colNo: number = g['cn'] !== undefined ? parseInt(g['cn']) : 1;
320-
const msg_type: string = g['sev1'] !== undefined ? g['sev1'] : g['sev2'];
321-
const msg: string = g['msg1'] !== undefined ? g['msg1'] : g['msg2'];
322-
323-
const range = new vscode.Range(
324-
new vscode.Position(lineNo - 1, colNo),
325-
new vscode.Position(lineNo - 1, colNo)
326-
);
327-
328-
let severity: vscode.DiagnosticSeverity;
329-
switch (msg_type.toLowerCase()) {
330-
case 'error':
331-
case 'fatal error':
332-
severity = vscode.DiagnosticSeverity.Error;
333-
break;
334-
case 'warning':
335-
severity = vscode.DiagnosticSeverity.Warning;
336-
break;
337-
case 'info': // gfortran does not produce info AFAIK
338-
severity = vscode.DiagnosticSeverity.Information;
339-
break;
340-
default:
341-
severity = vscode.DiagnosticSeverity.Error;
342-
break;
343-
}
344-
345-
const d = new vscode.Diagnostic(range, msg, severity);
346-
diagnostics.push(d);
347-
}
348-
349-
return diagnostics;
350-
351-
case 'flang':
352-
break;
313+
return this.linterParserGCC(matches);
353314

354315
case 'ifx':
355316
case 'ifort':
356-
for (const m of matches) {
357-
const g = m.groups;
358-
// NOTE: m[0] is the entire match and then the captured groups follow
359-
const fname: string = g['fname'];
360-
const lineNo: number = parseInt(g['ln']);
361-
const msg_type: string = g['sev1'] !== undefined ? g['sev1'] : g['sev2'];
362-
const msg: string = g['msg1'] !== undefined ? g['msg1'] : g['msg2'];
363-
const colNo: number = g['cn'] !== undefined ? g['cn'].length : 1;
364-
365-
const range = new vscode.Range(
366-
new vscode.Position(lineNo - 1, colNo),
367-
new vscode.Position(lineNo - 1, colNo)
368-
);
369-
370-
let severity: vscode.DiagnosticSeverity;
371-
switch (msg_type.toLowerCase()) {
372-
case 'error':
373-
case 'fatal error':
374-
severity = vscode.DiagnosticSeverity.Error;
375-
break;
376-
case 'warning':
377-
case 'remark': // ifort's version of warning is remark
378-
severity = vscode.DiagnosticSeverity.Warning;
379-
break;
380-
case 'info': // ifort does not produce info during compile-time AFAIK
381-
severity = vscode.DiagnosticSeverity.Information;
382-
break;
383-
default:
384-
severity = vscode.DiagnosticSeverity.Error;
385-
break;
386-
}
387-
388-
const d = new vscode.Diagnostic(range, msg, severity);
389-
diagnostics.push(d);
390-
}
391-
return diagnostics;
317+
return this.linterParserIntel(matches);
392318

393319
case 'nagfor':
394320
return this.linterParserNagfor(matches);
395321

396322
default:
323+
vscode.window.showErrorMessage(`${this.compiler} compiler is not supported yet.`);
397324
break;
398325
}
399326
}
400327

328+
private linterParserGCC(matches: RegExpMatchArray[]): vscode.Diagnostic[] {
329+
const diagnostics: vscode.Diagnostic[] = [];
330+
for (const m of matches) {
331+
const g = m.groups;
332+
// m[0] is the entire match and then the captured groups follow
333+
const fname: string = g['fname'] !== undefined ? g['fname'] : g['bin'];
334+
const lineNo: number = g['ln'] !== undefined ? parseInt(g['ln']) : 1;
335+
const colNo: number = g['cn'] !== undefined ? parseInt(g['cn']) : 1;
336+
const msg_type: string = g['sev1'] !== undefined ? g['sev1'] : g['sev2'];
337+
const msg: string = g['msg1'] !== undefined ? g['msg1'] : g['msg2'];
338+
339+
const range = new vscode.Range(
340+
new vscode.Position(lineNo - 1, colNo),
341+
new vscode.Position(lineNo - 1, colNo)
342+
);
343+
344+
let severity: vscode.DiagnosticSeverity;
345+
switch (msg_type.toLowerCase()) {
346+
case 'error':
347+
case 'fatal error':
348+
severity = vscode.DiagnosticSeverity.Error;
349+
break;
350+
case 'warning':
351+
severity = vscode.DiagnosticSeverity.Warning;
352+
break;
353+
case 'info': // gfortran does not produce info AFAIK
354+
severity = vscode.DiagnosticSeverity.Information;
355+
break;
356+
default:
357+
severity = vscode.DiagnosticSeverity.Error;
358+
break;
359+
}
360+
361+
const d = new vscode.Diagnostic(range, msg, severity);
362+
diagnostics.push(d);
363+
}
364+
return diagnostics;
365+
}
366+
367+
private linterParserIntel(matches: RegExpMatchArray[]): vscode.Diagnostic[] {
368+
const diagnostics: vscode.Diagnostic[] = [];
369+
for (const m of matches) {
370+
const g = m.groups;
371+
// m[0] is the entire match and then the captured groups follow
372+
const fname: string = g['fname'];
373+
const lineNo: number = parseInt(g['ln']);
374+
const msg_type: string = g['sev1'] !== undefined ? g['sev1'] : g['sev2'];
375+
const msg: string = g['msg1'] !== undefined ? g['msg1'] : g['msg2'];
376+
const colNo: number = g['cn'] !== undefined ? g['cn'].length : 1;
377+
378+
const range = new vscode.Range(
379+
new vscode.Position(lineNo - 1, colNo),
380+
new vscode.Position(lineNo - 1, colNo)
381+
);
382+
383+
let severity: vscode.DiagnosticSeverity;
384+
switch (msg_type.toLowerCase()) {
385+
case 'error':
386+
case 'fatal error':
387+
severity = vscode.DiagnosticSeverity.Error;
388+
break;
389+
case 'warning':
390+
case 'remark': // ifort's version of warning is remark
391+
severity = vscode.DiagnosticSeverity.Warning;
392+
break;
393+
case 'info': // ifort does not produce info during compile-time AFAIK
394+
severity = vscode.DiagnosticSeverity.Information;
395+
break;
396+
default:
397+
severity = vscode.DiagnosticSeverity.Error;
398+
break;
399+
}
400+
401+
const d = new vscode.Diagnostic(range, msg, severity);
402+
diagnostics.push(d);
403+
}
404+
return diagnostics;
405+
}
406+
401407
private linterParserNagfor(matches: RegExpMatchArray[]) {
402408
const diagnostics: vscode.Diagnostic[] = [];
403409
for (const m of matches) {

0 commit comments

Comments
 (0)