From 3e39eb2e45011bc32c4bcf7d3e05e604b2d87f0d Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 5 Jul 2022 20:51:58 +0100 Subject: [PATCH 1/3] Make extension default mod output default to cwd The CWD is enforced by the filePath variable passed to childProcess --- src/features/linter-provider.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/features/linter-provider.ts b/src/features/linter-provider.ts index 4d581a6c..91125449 100644 --- a/src/features/linter-provider.ts +++ b/src/features/linter-provider.ts @@ -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'; @@ -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]; } From 92d0fd7c3df5b14a8e60537e8d0863579ee78915 Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 6 Jul 2022 09:47:56 +0100 Subject: [PATCH 2/3] Fixes parsing Error level issues with NAG linter --- src/features/linter-provider.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/features/linter-provider.ts b/src/features/linter-provider.ts index 91125449..4ddc1b81 100644 --- a/src/features/linter-provider.ts +++ b/src/features/linter-provider.ts @@ -414,7 +414,6 @@ export class FortranLintingProvider { case 'panic': case 'fatal': case 'error': - case 'fatal error': severity = vscode.DiagnosticSeverity.Error; break; @@ -431,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; } @@ -486,8 +486,13 @@ export class FortranLintingProvider { // see https://regex101.com/r/GZ0Lzz/2 return /^(?(?:\w:\\)?.*)\((?\d+)\):\s*(?:#(?:(?\w*):\s*(?.*$))|(?\w*)\s*(?.*$)(?:\s*.*\s*)(?-*\^))/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 /^(?Remark|Info|Note|Warning|Questionable|Extension|Deleted feature used|Error|Fatal(?: Error)?|Panic)(\(\w+\))?: (?[\S ]+), line (?\d+): (?.+)$/gm; + return /^(?Remark|Info|Note|Warning|Questionable|Extension|Obsolescent|Deleted feature used|(?:[\w]+ )?Error|Fatal|Panic)(\(\w+\))?: (?[\S ]+), line (?\d+): (?.+)$/gm; default: vscode.window.showErrorMessage('Unsupported linter, change your linter.compiler option'); From 7feab7123704935ce6d7e50b5a21f0a92e89cfff Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 6 Jul 2022 09:48:22 +0100 Subject: [PATCH 3/3] Added unittest for NAG linter --- test/linter-provider.test.ts | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/test/linter-provider.test.ts b/test/linter-provider.test.ts index 2703eaa7..755a3dc9 100644 --- a/test/linter-provider.test.ts +++ b/test/linter-provider.test.ts @@ -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(); @@ -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']); @@ -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 ', () => { + strictEqual(g['sev1'], 'Sequence Error'); + }); + test('REGEX: message ', () => { + 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); + }); +});