Skip to content

Commit ce4386a

Browse files
authored
Merge pull request #905 from fortran-lang/gnikit/issue904
fix: linter not swapping fixed/free forms
2 parents b65e1a6 + a72affb commit ce4386a

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

CHANGELOG.md

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

8181
### Fixed
8282

83+
- Fixed bug where linter would not use the correct Fortran file association
84+
if the extension was part of the default extensions of another Fortran lang ID
85+
([#904](https://github.com/fortran-lang/vscode-fortran-support/issues/904))
8386
- Fixed linter REGEX for GFortran 4.x.x
8487
([#813](https://github.com/fortran-lang/vscode-fortran-support/issues/813))
8588
- Fixed GFortran version regex to allow for semver + build metadata

src/features/linter-provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,15 @@ export class FortranLintingProvider {
465465
// const extensionIndex = textDocument.fileName.lastIndexOf('.');
466466
// const fileNameWithoutExtension = textDocument.fileName.substring(0, extensionIndex);
467467
const fortranSource: string[] = this.settings.fyppEnabled
468-
? ['-xf95', isFreeForm(textDocument) ? '-ffree-form' : '-ffixed-form', '-']
468+
? ['-xf95', '-']
469469
: [textDocument.fileName];
470470

471471
const argList = [
472472
...args,
473473
...this.getIncludeParams(includePaths), // include paths
474+
// Explicitly set the type for Fortran in case the user has associated
475+
// fixed-form extensions to free-form, or vice versa
476+
isFreeForm(textDocument) ? this.linter.freeFlag : this.linter.fixedFlag,
474477
'-o',
475478
`${textDocument.fileName}.o`,
476479
...fortranSource,

src/lib/linters.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ abstract class Linter {
3535
/**
3636
* Compiler flag used to change the directory output for modules
3737
*/
38-
public readonly modFlag?: string
38+
public readonly modFlag?: string,
39+
/**
40+
* Compiler flag used to force free-form compilation
41+
*/
42+
public readonly freeFlag?: string,
43+
/**
44+
* Compiler flag used to force fixed-form compilation
45+
*/
46+
public readonly fixedFlag?: string
3947
) {}
4048

4149
public getSeverityLevel(msg_type: string): vscode.DiagnosticSeverity {
@@ -62,7 +70,9 @@ export class GNULinter extends Linter {
6270
},
6371
['-fsyntax-only', '-cpp'],
6472
['-Wall'],
65-
'-J'
73+
'-J',
74+
'-ffree-form',
75+
'-ffixed-form'
6676
);
6777
}
6878
/**
@@ -116,7 +126,9 @@ export class GNUModernLinter extends Linter {
116126
},
117127
['-fsyntax-only', '-cpp', '-fdiagnostics-plain-output'],
118128
['-Wall'],
119-
'-J'
129+
'-J',
130+
'-ffree-form',
131+
'-ffixed-form'
120132
);
121133
}
122134

@@ -163,7 +175,9 @@ export class IntelLinter extends Linter {
163175
},
164176
['-syntax-only', '-fpp'],
165177
['-warn', 'all'],
166-
'-module'
178+
'-module',
179+
'-free',
180+
'-fixed'
167181
);
168182
}
169183
/**
@@ -206,7 +220,9 @@ export class NAGLinter extends Linter {
206220
},
207221
['-M', '-quiet'],
208222
[],
209-
'-mdir'
223+
'-mdir',
224+
'-free',
225+
'-fixed'
210226
);
211227
}
212228

@@ -256,7 +272,9 @@ export class LFortranLinter extends Linter {
256272
},
257273
['--error-format=short'],
258274
[],
259-
'-J'
275+
'-J',
276+
'',
277+
'--fixed-form'
260278
);
261279
}
262280

test/fortran/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"files.associations": {
3+
"*.f77": "FortranFreeForm"
4+
},
25
"fortran.logging.level": "Debug",
36
"fortran.linter.includePaths": ["${workspaceFolder}/lint/**"],
47
"fortran.linter.fypp.enabled": false,

test/fortran/lint/fixed-as-free.f77

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
program fixed_as_free
2+
implicit none
3+
print*, "This is Free Form"
4+
end program fixed_as_free

test/integration/linter.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ suite('Linter', async () => {
4444
linter.dispose();
4545
strictEqual(linter['subscriptions'].length, 0);
4646
});
47+
48+
test('Check file association overrides propagate to the linter', async () => {
49+
const file = '../../../test/fortran/lint/fixed-as-free.f77';
50+
const fileUri = vscode.Uri.file(path.resolve(__dirname, file));
51+
doc = await vscode.workspace.openTextDocument(fileUri);
52+
await vscode.window.showTextDocument(doc);
53+
const res = await linter['doLint'](doc);
54+
strictEqual(res !== undefined, true);
55+
strictEqual(res?.length, 0);
56+
});
4757
});

0 commit comments

Comments
 (0)