Skip to content

Commit 68e8c22

Browse files
authored
Merge pull request #564 from fortran-lang:bug/default-modooutput
Linter mod output
2 parents 25e22c4 + 7feab71 commit 68e8c22

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

src/features/linter-provider.ts

+20-9
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,15 @@ export class FortranLintingProvider {
142142
private getModOutputDir(compiler: string): string[] {
143143
const config = vscode.workspace.getConfiguration('fortran');
144144
let modout: string = config.get('linter.modOutput', '');
145-
let modFlag = '-J';
145+
let modFlag = '';
146+
// Return if no mod output directory is specified
147+
if (modout === '') return [];
146148
switch (compiler) {
149+
case 'flang':
150+
case 'gfortran':
151+
modFlag = '-J';
152+
break;
153+
147154
case 'ifx':
148155
case 'ifort':
149156
modFlag = '-module';
@@ -154,13 +161,12 @@ export class FortranLintingProvider {
154161
break;
155162

156163
default:
157-
modFlag = '-J';
164+
modFlag = '';
158165
break;
159166
}
160-
if (modout) {
161-
modout = resolveVariables(modout);
162-
this.logger.logInfo(`Linter.moduleOutput: ${modFlag} ${modout}`);
163-
}
167+
168+
modout = resolveVariables(modout);
169+
this.logger.logInfo(`Linter.moduleOutput: ${modFlag} ${modout}`);
164170
return [modFlag, modout];
165171
}
166172

@@ -408,7 +414,6 @@ export class FortranLintingProvider {
408414
case 'panic':
409415
case 'fatal':
410416
case 'error':
411-
case 'fatal error':
412417
severity = vscode.DiagnosticSeverity.Error;
413418
break;
414419

@@ -425,9 +430,10 @@ export class FortranLintingProvider {
425430
severity = vscode.DiagnosticSeverity.Information;
426431
break;
427432

433+
// fatal error, sequence error, etc.
428434
default:
429435
severity = vscode.DiagnosticSeverity.Error;
430-
console.log('Unknown severity: ' + msg_type);
436+
console.log('Using default Error Severity for: ' + msg_type);
431437
break;
432438
}
433439

@@ -480,8 +486,13 @@ export class FortranLintingProvider {
480486
// see https://regex101.com/r/GZ0Lzz/2
481487
return /^(?<fname>(?:\w:\\)?.*)\((?<ln>\d+)\):\s*(?:#(?:(?<sev2>\w*):\s*(?<msg2>.*$))|(?<sev1>\w*)\s*(?<msg1>.*$)(?:\s*.*\s*)(?<cn>-*\^))/gm;
482488

489+
/*
490+
See Section 7 of the NAGFOR manual, although it is not accurate with regards
491+
to all the possible messages.
492+
severity: filename, line No.: message
493+
*/
483494
case 'nagfor':
484-
return /^(?<sev1>Remark|Info|Note|Warning|Questionable|Extension|Deleted feature used|Error|Fatal(?: Error)?|Panic)(\(\w+\))?: (?<fname>[\S ]+), line (?<ln>\d+): (?<msg1>.+)$/gm;
495+
return /^(?<sev1>Remark|Info|Note|Warning|Questionable|Extension|Obsolescent|Deleted feature used|(?:[\w]+ )?Error|Fatal|Panic)(\(\w+\))?: (?<fname>[\S ]+), line (?<ln>\d+): (?<msg1>.+)$/gm;
485496

486497
default:
487498
vscode.window.showErrorMessage('Unsupported linter, change your linter.compiler option');

test/linter-provider.test.ts

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as path from 'path';
12
import { strictEqual, deepStrictEqual } from 'assert';
2-
import { Diagnostic, DiagnosticSeverity, Range, Position } from 'vscode';
3+
import { Diagnostic, DiagnosticSeverity, Range, Position, window, workspace, Uri } from 'vscode';
34
import { FortranLintingProvider } from '../src/features/linter-provider';
5+
import { delay } from '../src/lib/helper';
46

57
suite('GNU (gfortran) lint single', () => {
68
const linter = new FortranLintingProvider();
@@ -232,8 +234,8 @@ suite('Intel (ifort) lint single', () => {
232234
linter['compiler'] = 'ifort';
233235
const msg = `
234236
/fetch/radiant/RADIANT_Matrix_Free_Subgrid_Scale.F90(102): error #5082: Syntax error, found '::' when expecting one of: ( : % [ . = =>
235-
PetscInt :: ierr
236-
---------------^
237+
PetscInt :: ierr
238+
---------------^
237239
`;
238240
suite('REGEX matches', () => {
239241
const regex = linter['getCompilerREGEX'](linter['compiler']);
@@ -514,3 +516,44 @@ C:\\Some\\random\\path\\sample.f90(4): error #6631: A non-optional actual argume
514516
deepStrictEqual(matches, ref);
515517
});
516518
});
519+
520+
// -----------------------------------------------------------------------------
521+
suite('NAG (nagfor) lint single', () => {
522+
const linter = new FortranLintingProvider();
523+
linter['compiler'] = 'nagfor';
524+
const msg = `
525+
Sequence Error: lint/err-mod.f90, line 3: The IMPLICIT statement cannot occur here
526+
`;
527+
suite('REGEX matches', () => {
528+
const regex = linter['getCompilerREGEX'](linter['compiler']);
529+
const matches = [...msg.matchAll(regex)];
530+
const g = matches[0].groups;
531+
test('REGEX: filename', () => {
532+
strictEqual(g['fname'], 'lint/err-mod.f90');
533+
});
534+
test('REGEX: line number', () => {
535+
strictEqual(g['ln'], '3');
536+
});
537+
test('REGEX: severity <sev1>', () => {
538+
strictEqual(g['sev1'], 'Sequence Error');
539+
});
540+
test('REGEX: message <msg1>', () => {
541+
strictEqual(g['msg1'], 'The IMPLICIT statement cannot occur here');
542+
});
543+
});
544+
test('Diagnostics Array', async () => {
545+
const fileUri = Uri.file(path.resolve(__dirname, '../../test/fortran/lint/err-mod.f90'));
546+
const doc = await workspace.openTextDocument(fileUri);
547+
await window.showTextDocument(doc);
548+
await delay(100);
549+
const matches = linter['getLinterResults'](msg);
550+
const ref = [
551+
new Diagnostic(
552+
new Range(new Position(2, 0), new Position(2, 17)),
553+
'The IMPLICIT statement cannot occur here',
554+
DiagnosticSeverity.Error
555+
),
556+
];
557+
deepStrictEqual(matches, ref);
558+
});
559+
});

0 commit comments

Comments
 (0)