Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter mod output #564

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/features/linter-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,15 @@ export class FortranLintingProvider {
private getModOutputDir(compiler: string): string[] {
const config = vscode.workspace.getConfiguration('fortran');
let modout: string = config.get('linter.modOutput', '');
let modFlag = '-J';
let modFlag = '';
// Return if no mod output directory is specified
if (modout === '') return [];
switch (compiler) {
case 'flang':
case 'gfortran':
modFlag = '-J';
break;

case 'ifx':
case 'ifort':
modFlag = '-module';
Expand All @@ -154,13 +161,12 @@ export class FortranLintingProvider {
break;

default:
modFlag = '-J';
modFlag = '';
break;
}
if (modout) {
modout = resolveVariables(modout);
this.logger.logInfo(`Linter.moduleOutput: ${modFlag} ${modout}`);
}

modout = resolveVariables(modout);
this.logger.logInfo(`Linter.moduleOutput: ${modFlag} ${modout}`);
return [modFlag, modout];
}

Expand Down Expand Up @@ -408,7 +414,6 @@ export class FortranLintingProvider {
case 'panic':
case 'fatal':
case 'error':
case 'fatal error':
severity = vscode.DiagnosticSeverity.Error;
break;

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

// fatal error, sequence error, etc.
default:
severity = vscode.DiagnosticSeverity.Error;
console.log('Unknown severity: ' + msg_type);
console.log('Using default Error Severity for: ' + msg_type);
break;
}

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

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

default:
vscode.window.showErrorMessage('Unsupported linter, change your linter.compiler option');
Expand Down
49 changes: 46 additions & 3 deletions test/linter-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as path from 'path';
import { strictEqual, deepStrictEqual } from 'assert';
import { Diagnostic, DiagnosticSeverity, Range, Position } from 'vscode';
import { Diagnostic, DiagnosticSeverity, Range, Position, window, workspace, Uri } from 'vscode';
import { FortranLintingProvider } from '../src/features/linter-provider';
import { delay } from '../src/lib/helper';

suite('GNU (gfortran) lint single', () => {
const linter = new FortranLintingProvider();
Expand Down Expand Up @@ -232,8 +234,8 @@ suite('Intel (ifort) lint single', () => {
linter['compiler'] = 'ifort';
const msg = `
/fetch/radiant/RADIANT_Matrix_Free_Subgrid_Scale.F90(102): error #5082: Syntax error, found '::' when expecting one of: ( : % [ . = =>
PetscInt :: ierr
---------------^
PetscInt :: ierr
---------------^
`;
suite('REGEX matches', () => {
const regex = linter['getCompilerREGEX'](linter['compiler']);
Expand Down Expand Up @@ -514,3 +516,44 @@ C:\\Some\\random\\path\\sample.f90(4): error #6631: A non-optional actual argume
deepStrictEqual(matches, ref);
});
});

// -----------------------------------------------------------------------------
suite('NAG (nagfor) lint single', () => {
const linter = new FortranLintingProvider();
linter['compiler'] = 'nagfor';
const msg = `
Sequence Error: lint/err-mod.f90, line 3: The IMPLICIT statement cannot occur here
`;
suite('REGEX matches', () => {
const regex = linter['getCompilerREGEX'](linter['compiler']);
const matches = [...msg.matchAll(regex)];
const g = matches[0].groups;
test('REGEX: filename', () => {
strictEqual(g['fname'], 'lint/err-mod.f90');
});
test('REGEX: line number', () => {
strictEqual(g['ln'], '3');
});
test('REGEX: severity <sev1>', () => {
strictEqual(g['sev1'], 'Sequence Error');
});
test('REGEX: message <msg1>', () => {
strictEqual(g['msg1'], 'The IMPLICIT statement cannot occur here');
});
});
test('Diagnostics Array', async () => {
const fileUri = Uri.file(path.resolve(__dirname, '../../test/fortran/lint/err-mod.f90'));
const doc = await workspace.openTextDocument(fileUri);
await window.showTextDocument(doc);
await delay(100);
const matches = linter['getLinterResults'](msg);
const ref = [
new Diagnostic(
new Range(new Position(2, 0), new Position(2, 17)),
'The IMPLICIT statement cannot occur here',
DiagnosticSeverity.Error
),
];
deepStrictEqual(matches, ref);
});
});