Skip to content

Commit 11df362

Browse files
authored
Merge pull request #562 from fortran-lang/gnikit/issue476
Add NAG linting
2 parents 8fab085 + 957c7b2 commit 11df362

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Added
1313

14+
- Added NAG (`nagfor`) compiler support for linting
15+
([#476](https://github.com/fortran-lang/vscode-fortran-support/issues/476))
1416
- Added `Modern Fortran`, `fortls` and `fpm` as keywords to the extension
1517
([#536](https://github.com/fortran-lang/vscode-fortran-support/issues/536))
1618

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- GoTo/Peek implementation and Find/Peek references
3737
- Project-wide and Document symbol detection and Renaming
3838
- [Native Language Server integration](#language-server-integration) with [`fortls`](https://github.com/gnikit/fortls)
39-
- [Linting support](#linting) for GCC's [`gfortran`](https://gcc.gnu.org/wiki/GFortran), and Intel's [`ifort`](https://www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html), `ifx`
39+
- [Linting support](#linting): GNU's [`gfortran`](https://gcc.gnu.org/wiki/GFortran), Intel's [`ifort`](https://www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html), `ifx`, NAG's [`nagfor`](https://www.nag.co.uk/nagfor/)
4040
- [Interactive Debugger with UI](#debugging)
4141
- [Formatting](#formatting) with [findent](https://github.com/gnikit/findent-pypi) or [fprettify](https://github.com/pseewald/fprettify)
4242
- [Code snippets](#snippets) (more can be defined by the user [see](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets))
@@ -81,6 +81,12 @@ For more about the Language Server's capabilities please refer to the
8181
Linting allows for compiler error and warning detection while coding
8282
without the user having to compile.
8383

84+
| Vendor | Compiler |
85+
| --------------------------------------------------------------------------------------------- | -------------- |
86+
| [GNU](https://gcc.gnu.org/wiki/GFortran) | `gfortran` |
87+
| [Intel](https://www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html) | `ifort`, `ifx` |
88+
| [NAG](https://www.nag.com/) | `nagfor` |
89+
8490
Using an invalid if expression
8591

8692
![alt](assets/gif/lint-demo.gif)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
"gfortran",
196196
"ifort",
197197
"ifx",
198+
"nagfor",
198199
"Disabled"
199200
],
200201
"markdownDescription": "Compiler used for linting support."

src/features/linter-provider.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export class FortranLintingProvider {
132132
...args,
133133
...this.getIncludeParams(includePaths), // include paths
134134
textDocument.fileName,
135-
`-o ${fileNameWithoutExtension}.mod`,
135+
'-o',
136+
`${fileNameWithoutExtension}.mod`,
136137
];
137138

138139
return argList.map(arg => arg.trim()).filter(arg => arg !== '');
@@ -148,6 +149,10 @@ export class FortranLintingProvider {
148149
modFlag = '-module';
149150
break;
150151

152+
case 'nagfor':
153+
modFlag = '-mdir';
154+
break;
155+
151156
default:
152157
modFlag = '-J';
153158
break;
@@ -270,7 +275,7 @@ export class FortranLintingProvider {
270275
// gfortran and flang have compiler flags for restricting the width of
271276
// the code.
272277
// You can always override by passing in the correct args as extraArgs
273-
if (compiler !== 'ifort' && compiler !== 'ifx') {
278+
if (compiler === 'gfortran') {
274279
const ln: number = config.get('fortls.maxLineLength');
275280
const lnStr: string = ln === -1 ? 'none' : ln.toString();
276281
args.push(`-ffree-line-length-${lnStr}`, `-ffixed-line-length-${lnStr}`);
@@ -379,11 +384,59 @@ export class FortranLintingProvider {
379384
}
380385
return diagnostics;
381386

387+
case 'nagfor':
388+
return this.linterParserNagfor(matches);
389+
382390
default:
383391
break;
384392
}
385393
}
386394

395+
private linterParserNagfor(matches: RegExpMatchArray[]) {
396+
const diagnostics: vscode.Diagnostic[] = [];
397+
for (const m of matches) {
398+
const g = m.groups;
399+
const fname: string = g['fname'];
400+
const lineNo: number = parseInt(g['ln']);
401+
const msg_type: string = g['sev1'];
402+
const msg: string = g['msg1'];
403+
// NAGFOR does not have a column number, so get the entire line
404+
const range = vscode.window.activeTextEditor.document.lineAt(lineNo - 1).range;
405+
406+
let severity: vscode.DiagnosticSeverity;
407+
switch (msg_type.toLowerCase()) {
408+
case 'panic':
409+
case 'fatal':
410+
case 'error':
411+
case 'fatal error':
412+
severity = vscode.DiagnosticSeverity.Error;
413+
break;
414+
415+
case 'extension':
416+
case 'questionable':
417+
case 'deleted feature used':
418+
case 'warning':
419+
severity = vscode.DiagnosticSeverity.Warning;
420+
break;
421+
422+
case 'remark':
423+
case 'note':
424+
case 'info':
425+
severity = vscode.DiagnosticSeverity.Information;
426+
break;
427+
428+
default:
429+
severity = vscode.DiagnosticSeverity.Error;
430+
console.log('Unknown severity: ' + msg_type);
431+
break;
432+
}
433+
434+
const d = new vscode.Diagnostic(range, msg, severity);
435+
diagnostics.push(d);
436+
}
437+
return diagnostics;
438+
}
439+
387440
/**
388441
* Different compilers, display errors in different ways, hence we need
389442
* different regular expressions to interpret their output.
@@ -427,6 +480,9 @@ export class FortranLintingProvider {
427480
// see https://regex101.com/r/GZ0Lzz/2
428481
return /^(?<fname>(?:\w:\\)?.*)\((?<ln>\d+)\):\s*(?:#(?:(?<sev2>\w*):\s*(?<msg2>.*$))|(?<sev1>\w*)\s*(?<msg1>.*$)(?:\s*.*\s*)(?<cn>-*\^))/gm;
429482

483+
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;
485+
430486
default:
431487
vscode.window.showErrorMessage('Unsupported linter, change your linter.compiler option');
432488
}
@@ -454,6 +510,9 @@ export class FortranLintingProvider {
454510
case 'ifort':
455511
return ['-syntax-only', '-fpp'];
456512

513+
case 'nagfor':
514+
return ['-M', '-quiet'];
515+
457516
default:
458517
break;
459518
}

updates/RELEASE_NOTES-v3.2.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# What's New (v3.2) <!-- omit in toc -->
22

3-
## Changes
3+
## 🎉 Modern Fortran Release of v3.2 🎉! <!-- omit in toc -->
4+
5+
- [Linting](#linting)
6+
- [Other Changes](#other-changes)
7+
- [Added](#added)
8+
- [Changed](#changed)
9+
- [Fixed](#fixed)
10+
11+
## Linting
12+
13+
Added linting support for [NAG](https://www.nag.com/content/nag-fortran-compiler)'s
14+
`nagfor` compiler. Compiler diagnostics should now be served via the _Modern Fortran_ linter.
15+
16+
## Other Changes
417

518
### Added
619

0 commit comments

Comments
 (0)