@@ -10,33 +10,26 @@ import * as vscode from 'vscode';
10
10
export default class FortranLintingProvider {
11
11
12
12
constructor ( ) {
13
-
13
+
14
14
15
15
}
16
16
17
17
private diagnosticCollection : vscode . DiagnosticCollection ;
18
+
18
19
private doModernFortranLint ( textDocument : vscode . TextDocument ) {
19
- const errorRegex : RegExp = / ^ .{ 2 } ( [ ^ : ] * ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) : \r ? \n \s * ( .* ) \r ? \n .* \r ? \n ( E r r o r | W a r n i n g | F a t a l E r r o r ) : \s ( .* ) $ / gm; ;
20
+
21
+
22
+ const errorRegex : RegExp = / ^ ( [ A - Z ] : \\ ) * ( [ ^ : ] * ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) : \n + ( .* ) \n .* \n ( E r r o r | W a r n i n g | F a t a l E r r o r ) : \s ( .* ) $ / gm;
20
23
21
24
if ( textDocument . languageId !== LANGUAGE_ID ) {
22
25
return ;
23
26
}
24
27
let decoded = '' ;
25
28
let diagnostics : vscode . Diagnostic [ ] = [ ] ;
26
- let options = vscode . workspace . rootPath ? { cwd : vscode . workspace . rootPath } : undefined ;
27
- let args = [ ...this . getLinterExtraArgs ( ) , "-cpp" , "-fsyntax-only" , '-fdiagnostics-show-option' ] ;
28
- let includePaths = this . getIncludePaths ( ) ;
29
29
let command = this . getGfortranPath ( ) ;
30
+ let argList = this . constructArgumentList ( textDocument ) ;
30
31
31
- let argList = [
32
- ...args ,
33
- getIncludeParams ( includePaths ) , // include paths
34
- textDocument . fileName
35
- ] ;
36
-
37
- argList = argList . map ( arg => arg . trim ( ) ) . filter ( arg => arg !== "" ) ;
38
-
39
- let childProcess = cp . spawn ( command , argList )
32
+ let childProcess = cp . spawn ( command , argList ) ;
40
33
41
34
if ( childProcess . pid ) {
42
35
childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
@@ -48,16 +41,17 @@ export default class FortranLintingProvider {
48
41
childProcess . stderr . on ( 'end' , ( ) => {
49
42
let matchesArray : string [ ] ;
50
43
while ( ( matchesArray = errorRegex . exec ( decoded ) ) !== null ) {
44
+
51
45
let elements : string [ ] = matchesArray . slice ( 1 ) ; // get captured expressions
52
- let startLine = parseInt ( elements [ 1 ] ) ;
53
- let startColumn = parseInt ( elements [ 2 ] )
54
- let type = elements [ 4 ] ; //error or warning
46
+ let startLine = parseInt ( elements [ 2 ] ) ;
47
+ let startColumn = parseInt ( elements [ 3 ] ) ;
48
+ let type = elements [ 5 ] ; // error or warning
55
49
let severity = type . toLowerCase ( ) === "warning" ? vscode . DiagnosticSeverity . Warning : vscode . DiagnosticSeverity . Error ;
56
- let message = elements [ 5 ] ;
50
+ let message = elements [ 6 ] ;
57
51
let range = new vscode . Range ( new vscode . Position ( startLine - 1 , startColumn ) ,
58
52
new vscode . Position ( startLine - 1 , startColumn ) ) ;
59
53
let diagnostic = new vscode . Diagnostic ( range , message , severity ) ;
60
- diagnostics . push ( diagnostic )
54
+ diagnostics . push ( diagnostic ) ;
61
55
}
62
56
63
57
this . diagnosticCollection . set ( textDocument . uri , diagnostics ) ;
@@ -75,6 +69,25 @@ export default class FortranLintingProvider {
75
69
}
76
70
}
77
71
72
+
73
+ private constructArgumentList ( textDocument :vscode . TextDocument ) : string [ ] {
74
+
75
+ let options = vscode . workspace . rootPath ? { cwd : vscode . workspace . rootPath } : undefined ;
76
+ let args = [ "-fsyntax-only" , "-cpp" , '-fdiagnostics-show-option' , ...this . getLinterExtraArgs ( ) ] ;
77
+ let includePaths = this . getIncludePaths ( ) ;
78
+
79
+ let extensionIndex = textDocument . fileName . lastIndexOf ( '.' ) ;
80
+ let fileNameWithoutExtension = textDocument . fileName . substring ( 0 , extensionIndex ) ;
81
+ let argList = [
82
+ ...args ,
83
+ getIncludeParams ( includePaths ) , // include paths
84
+ textDocument . fileName ,
85
+ `-o ${ fileNameWithoutExtension } .mod`
86
+ ] ;
87
+
88
+ return argList . map ( arg => arg . trim ( ) ) . filter ( arg => arg !== "" ) ;
89
+ }
90
+
78
91
private static commandId : string = 'fortran.lint.runCodeAction' ;
79
92
80
93
public provideCodeActions ( document : vscode . TextDocument , range : vscode . Range , context : vscode . CodeActionContext , token : vscode . CancellationToken ) : vscode . Command [ ] {
0 commit comments