@@ -10,33 +10,26 @@ import * as vscode from 'vscode';
1010export default class FortranLintingProvider {
1111
1212 constructor ( ) {
13-
13+
1414
1515 }
1616
1717 private diagnosticCollection : vscode . DiagnosticCollection ;
18+
1819 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;
2023
2124 if ( textDocument . languageId !== LANGUAGE_ID ) {
2225 return ;
2326 }
2427 let decoded = '' ;
2528 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 ( ) ;
2929 let command = this . getGfortranPath ( ) ;
30+ let argList = this . constructArgumentList ( textDocument ) ;
3031
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 ) ;
4033
4134 if ( childProcess . pid ) {
4235 childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
@@ -48,16 +41,17 @@ export default class FortranLintingProvider {
4841 childProcess . stderr . on ( 'end' , ( ) => {
4942 let matchesArray : string [ ] ;
5043 while ( ( matchesArray = errorRegex . exec ( decoded ) ) !== null ) {
44+
5145 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
5549 let severity = type . toLowerCase ( ) === "warning" ? vscode . DiagnosticSeverity . Warning : vscode . DiagnosticSeverity . Error ;
56- let message = elements [ 5 ] ;
50+ let message = elements [ 6 ] ;
5751 let range = new vscode . Range ( new vscode . Position ( startLine - 1 , startColumn ) ,
5852 new vscode . Position ( startLine - 1 , startColumn ) ) ;
5953 let diagnostic = new vscode . Diagnostic ( range , message , severity ) ;
60- diagnostics . push ( diagnostic )
54+ diagnostics . push ( diagnostic ) ;
6155 }
6256
6357 this . diagnosticCollection . set ( textDocument . uri , diagnostics ) ;
@@ -75,6 +69,25 @@ export default class FortranLintingProvider {
7569 }
7670 }
7771
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+
7891 private static commandId : string = 'fortran.lint.runCodeAction' ;
7992
8093 public provideCodeActions ( document : vscode . TextDocument , range : vscode . Range , context : vscode . CodeActionContext , token : vscode . CancellationToken ) : vscode . Command [ ] {
0 commit comments