Skip to content

Commit 084e8a3

Browse files
committed
Changes the extension interface
and adds support for gfortran and ifort compilers Fixes Rewrite settings interface #292 Fixes Add support for Intel and LLVM compilers #291 Fixes gfortran linter regex cannot display certain failures #295
1 parent 7fc99e8 commit 084e8a3

8 files changed

+647
-159
lines changed

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [3.0.0]
11+
12+
### Fixed
13+
14+
- Fixes linting regex to capture a wider spectrum of errors
15+
([#295](https://github.com/krvajal/vscode-fortran-support/issues/295))
16+
17+
### Changed
18+
19+
- Changes the interface of the extension to accommodate for the newest features
20+
([#292](https://github.com/krvajal/vscode-fortran-support/issues/292))
21+
22+
### Added
23+
24+
- Adds support for Intel (ifort) and LLVM (flang) compilers
25+
([#291](https://github.com/krvajal/vscode-fortran-support/issues/291))
26+
- Adds native support for the fortran-language-server (`fortls`) making
27+
unnecessary the usage of Fortran Intellisense extension
28+
([#290](https://github.com/krvajal/vscode-fortran-support/issues/290))
29+
1030
## [2.6.1]
1131

1232
### Fixed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
You can control the include paths to be used by the linter with the `fortran.linter.includePaths` setting.
2727
The `linter.includePaths` should match the include requirements for your projects compilation.
28+
2829
> NOTE: if a glob pattern is used only directories matching the pattern will be included.
2930
3031
```jsonc

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+116-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "linter-gfortran",
33
"displayName": "Modern Fortran",
44
"description": "Modern Fortran language support, including syntax highlighting and error detection.",
5-
"version": "2.6.1",
5+
"version": "3.0.0",
66
"publisher": "krvajalm",
77
"license": "MIT",
88
"author": {
@@ -128,42 +128,78 @@
128128
"type": "object",
129129
"title": "Fortran configuration",
130130
"properties": {
131-
"fortran.includePaths": {
131+
"fortran.provide.hover": {
132+
"type": "string",
133+
"default": "fortls",
134+
"enum": [
135+
"fortls",
136+
"Built-in",
137+
"Both",
138+
"Disabled"
139+
],
140+
"description": "Enables hover support, by default it uses fortran-language-server."
141+
},
142+
"fortran.provide.autocomplete": {
143+
"type": "string",
144+
"default": "fortls",
145+
"enum": [
146+
"fortls",
147+
"Built-in",
148+
"Both",
149+
"Disabled"
150+
],
151+
"description": "Enables code autocompletion, by default it uses fortran-language-server."
152+
},
153+
"fortran.provide.symbols": {
154+
"type": "string",
155+
"default": "fortls",
156+
"enum": [
157+
"fortls",
158+
"Built-in",
159+
"Both",
160+
"Disabled"
161+
],
162+
"description": "Outline of type members in the document, by default it uses fortran-language-server."
163+
},
164+
"fortran.linter.compiler": {
165+
"type": "string",
166+
"default": "gfortran",
167+
"enum": [
168+
"gfortran",
169+
"flang",
170+
"ifort",
171+
"Disabled"
172+
],
173+
"description": "Compiler used for linting support."
174+
},
175+
"fortran.linter.includePaths": {
132176
"type": [
133177
"array"
134178
],
135179
"items": {
136180
"type": "string"
137181
},
138182
"default": [],
139-
"description": "Specifies folder paths to be used as include path for the Fortran linter"
183+
"description": "Specifies folder paths to be used as include paths during linting. Can resolve glob patterns e.g. `/usr/local/include/**` and internal variables with `~`, `${workspaceFolder}`, `${env}`, `${config}`, `${file}`, `${fileDirname}`, `${fileBasenameNoExtension}`"
140184
},
141-
"fortran.gfortranExecutable": {
185+
"fortran.linter.compilerPath": {
142186
"type": "string",
143-
"default": "gfortran",
144-
"description": "Specifies the complete path of the gfortran executable"
145-
},
146-
"fortran.linterEnabled": {
147-
"type": "boolean",
148-
"default": true,
149-
"description": "Enables or disables the linter functionality"
187+
"default": "",
188+
"description": "Specifies the path to the linter executable."
150189
},
151-
"fortran.linterExtraArgs": {
190+
"fortran.linter.extraArgs": {
152191
"type": [
153192
"array"
154193
],
155194
"items": {
156195
"type": "string"
157196
},
158-
"default": [
159-
"-Wall"
160-
],
161-
"description": "Specify additional options to use when calling the gfortran compiler"
197+
"description": "Pass additional options to the linter compiler. Can resolve internal variables with `~`, `${workspaceFolder}`, `${env}`, `${config}`, `${file}`, `${fileDirname}`, `${fileBasenameNoExtension}`"
162198
},
163-
"fortran.linterModOutput": {
199+
"fortran.linter.modOutput": {
164200
"type": "string",
165201
"default": "",
166-
"description": "Global output directory for .mod files `-J<linterModOutput>`"
202+
"description": "Global output directory for .mod files generated due to linting `-J<linter.modOutput>`. Can resolve internal variables with `~`, `${workspaceFolder}`, `${env}`, `${config}`, `${file}`, `${fileDirname}`, `${fileBasenameNoExtension}`"
167203
},
168204
"fortran.formatting.formatter": {
169205
"type": "string",
@@ -183,35 +219,52 @@
183219
"fortran.formatting.path": {
184220
"type": "string",
185221
"default": "",
186-
"description": "Specify the full path of where the formatter is installed"
222+
"description": "If the formatter is not in the $PATH specify the full path to its location."
187223
},
188-
"fortran.provideSymbols": {
224+
"fortran.fortls.path": {
225+
"type": "string",
226+
"default": "fortls",
227+
"description": "Path to the Fortran language server (fortls)."
228+
},
229+
"fortran.fortls.preserveKeywordOrder": {
189230
"type": "boolean",
190231
"default": true,
191-
"description": "Enables or disables symbol functionality (disable if using 'Fortran IntelliSense')"
232+
"description": "Display variable keywords information when hovering in original order (default: sort to consistent ordering)."
192233
},
193-
"fortran.symbols": {
234+
"fortran.fortls.disableDiagnostics": {
235+
"type": "boolean",
236+
"default": false,
237+
"description": "Disable diagnostics (requires v1.12.0+)."
238+
},
239+
"fortran.fortls.incrementalSync": {
240+
"type": "boolean",
241+
"default": true,
242+
"description": "Use incremental synchronization for file changes."
243+
},
244+
"fortran.fortls.notifyInit": {
245+
"type": "boolean",
246+
"default": false,
247+
"description": "Notify when workspace initialization is complete (requires v1.7.0+)."
248+
},
249+
"fortran.fortls.extraArgs": {
194250
"type": [
195251
"array"
196252
],
197253
"items": {
198254
"type": "string"
199255
},
200-
"default": [
201-
"function",
202-
"subroutine"
203-
],
204-
"description": "Specify what kind of symbols should be shown by the symbols' provider"
256+
"default": [],
257+
"description": "Additional arguments for the fortran-language-server"
205258
},
206-
"fortran.provideHover": {
207-
"type": "boolean",
208-
"default": true,
209-
"description": "Enables hover functionality (disable if using 'Fortran IntelliSense')"
259+
"fortran.maxLineLength": {
260+
"type": "number",
261+
"default": -1,
262+
"description": "Maximum line length (fortls requires v1.8.0+). Passed in both the linter and the language server."
210263
},
211-
"fortran.provideCompletion": {
212-
"type": "boolean",
213-
"default": true,
214-
"description": "Enables or disables completion functionality (disable if using 'Fortran IntelliSense')"
264+
"fortran.maxCommentLineLength": {
265+
"type": "number",
266+
"default": -1,
267+
"description": "Maximum comment line length (fortls requires v1.8.0+). Passed in both the linter and the language server."
215268
},
216269
"fortran.preferredCase": {
217270
"type": "string",
@@ -220,7 +273,34 @@
220273
"lowercase",
221274
"uppercase"
222275
],
223-
"description": "Specify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
276+
"description": "Specify the word case to use when suggesting autocomplete options."
277+
},
278+
"fortran.includePaths": {
279+
"deprecationMessage": "fortran.includePaths has been renamed to fortran.linter.includePaths."
280+
},
281+
"fortran.gfortranExecutable": {
282+
"deprecationMessage": "fortran.gfortranExecutable has been renamed to fortran.linter.compilerPath"
283+
},
284+
"fortran.linterEnabled": {
285+
"deprecationMessage": "fortran.linterEnabled has been renamed to fortran.linter.compiler set to Disable to turn off."
286+
},
287+
"fortran.linterExtraArgs": {
288+
"deprecationMessage": "fortran.linterExtraArgs has been renamed to fortran.linter.extraArgs"
289+
},
290+
"fortran.linterModOutput": {
291+
"deprecationMessage": "fortran.linterModOutput has been renamed to fortran.linter.modOutput."
292+
},
293+
"fortran.provideSymbols": {
294+
"deprecationMessage": "fortran.provideSymbols has been renamed to fortran.provide.symbols. By default the fortran-language-server symbols are used, to enable the built-in symbols turn on the Built-in option."
295+
},
296+
"fortran.symbols": {
297+
"deprecationMessage": "fortran.symbols has been removed in favour of returning all symbols."
298+
},
299+
"fortran.provideHover": {
300+
"deprecationMessage": "fortran.provideHover has been renamed to fortran.provide.hover. By default the fortran-language-server hover is used, to enable the built-in hover turn on the Built-in option."
301+
},
302+
"fortran.provideCompletion": {
303+
"deprecationMessage": "fortran.provideCompletion has been renamed to fortran.provide.autocomplete. By default the fortran-language-server autocompletion is used, to enable the built-in autocompletion turn on the Built-in option."
224304
}
225305
}
226306
},

src/extension.ts

+47-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as which from 'which';
33
import * as vscode from 'vscode';
44

5-
import FortranLintingProvider from './features/linter-provider';
5+
import { FortranLintingProvider } from './features/linter-provider';
66
import FortranHoverProvider from './features/hover-provider';
77
import { FortranCompletionProvider } from './features/completion-provider';
88
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider';
@@ -11,58 +11,56 @@ import { LoggingService } from './services/logging-service';
1111
import * as pkg from '../package.json';
1212
import { LANG_SERVER_TOOL_ID } from './lib/tools';
1313
import { FortranFormattingProvider } from './features/formatting-provider';
14+
import { FortranLanguageServer } from './fortls-interface';
1415
import { EXTENSION_ID, FortranDocumentSelector, promptForMissingTool } from './lib/tools';
1516

1617
// Make it global to catch errors when activation fails
1718
const loggingService = new LoggingService();
1819

1920
export function activate(context: vscode.ExtensionContext) {
20-
const extensionConfig = vscode.workspace.getConfiguration(EXTENSION_ID);
21+
const config = vscode.workspace.getConfiguration(EXTENSION_ID);
22+
const linterType = config.get<string>('linter.compiler');
23+
const formatterType = config.get<string>('formatting.formatter');
24+
const autocompleteType = config.get<string>('provide.autocomplete');
25+
const hoverType = config.get<string>('provide.hover');
26+
const symbolsType = config.get<string>('provide.symbols');
27+
detectDeprecatedOptions();
2128

2229
loggingService.logInfo(`Extension Name: ${pkg.displayName}`);
2330
loggingService.logInfo(`Extension Version: ${pkg.version}`);
31+
loggingService.logInfo(`Linter set to: ${linterType}`);
32+
loggingService.logInfo(`Formatter set to: ${formatterType}`);
33+
loggingService.logInfo(`Autocomplete set to: ${autocompleteType}`);
34+
loggingService.logInfo(`Hover set to: ${hoverType}`);
35+
loggingService.logInfo(`Symbols set to: ${symbolsType}`);
2436

25-
if (extensionConfig.get('linterEnabled', true)) {
37+
if (linterType !== 'Disabled') {
2638
const linter = new FortranLintingProvider(loggingService);
2739
linter.activate(context.subscriptions);
2840
vscode.languages.registerCodeActionsProvider(FortranDocumentSelector(), linter);
29-
loggingService.logInfo('Linter is enabled');
30-
} else {
31-
loggingService.logInfo('Linter is not enabled');
3241
}
3342

34-
if (extensionConfig.get('formatter') !== 'Disabled') {
43+
if (formatterType !== 'Disabled') {
3544
const disposable: vscode.Disposable = vscode.languages.registerDocumentFormattingEditProvider(
3645
FortranDocumentSelector(),
3746
new FortranFormattingProvider(loggingService)
3847
);
3948
context.subscriptions.push(disposable);
40-
loggingService.logInfo('Formatting is enabled');
41-
} else {
42-
loggingService.logInfo('Formatting is disabled');
4349
}
4450

45-
if (extensionConfig.get('provideCompletion', true)) {
51+
if (autocompleteType === 'Built-in') {
4652
const completionProvider = new FortranCompletionProvider(loggingService);
4753
vscode.languages.registerCompletionItemProvider(FortranDocumentSelector(), completionProvider);
48-
} else {
49-
loggingService.logInfo('Completion Provider is not enabled');
5054
}
5155

52-
if (extensionConfig.get('provideHover', true)) {
56+
if (hoverType === 'Built-in') {
5357
const hoverProvider = new FortranHoverProvider(loggingService);
5458
vscode.languages.registerHoverProvider(FortranDocumentSelector(), hoverProvider);
55-
loggingService.logInfo('Hover Provider is enabled');
56-
} else {
57-
loggingService.logInfo('Hover Provider is not enabled');
5859
}
5960

60-
if (extensionConfig.get('provideSymbols', true)) {
61+
if (symbolsType === 'Built-in') {
6162
const symbolProvider = new FortranDocumentSymbolProvider();
6263
vscode.languages.registerDocumentSymbolProvider(FortranDocumentSelector(), symbolProvider);
63-
loggingService.logInfo('Symbol Provider is enabled');
64-
} else {
65-
loggingService.logInfo('Symbol Provider is not enabled');
6664
}
6765

6866
// Check if the language server is installed and if not prompt to install it
@@ -73,4 +71,32 @@ export function activate(context: vscode.ExtensionContext) {
7371
https://github.com/hansec/fortran-language-server`;
7472
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
7573
}
74+
75+
// Spawn the fortran-language-server
76+
const fortls = new FortranLanguageServer(loggingService);
77+
fortls.activate(context.subscriptions);
78+
}
79+
80+
function detectDeprecatedOptions() {
81+
const config = vscode.workspace.getConfiguration(EXTENSION_ID);
82+
const oldArgs: string[] = [];
83+
if (config.get('includePaths')) oldArgs.push('fortran.includePaths');
84+
if (config.get('gfortranExecutable')) oldArgs.push('fortran.gfortranExecutable');
85+
if (config.get('linterEnabled')) oldArgs.push('fortran.linterEnabled');
86+
if (config.get('linterExtraArgs')) oldArgs.push('fortran.linterExtraArgs');
87+
if (config.get('linterModOutput')) oldArgs.push('fortran.linterModOutput');
88+
if (config.get('symbols')) oldArgs.push('fortran.symbols');
89+
if (config.get('provideSymbols')) oldArgs.push('fortran.provideSymbols');
90+
if (config.get('provideHover')) oldArgs.push('fortran.provideHover');
91+
if (config.get('provideCompletion')) oldArgs.push('fortran.provideCompletion');
92+
93+
if (oldArgs.length !== 0) {
94+
const err = vscode.window.showErrorMessage(
95+
`Deprecated settings have been detected in your settings.
96+
Please update your settings to make use of the new names. The old names will not work.`,
97+
'Open Settings'
98+
);
99+
err.then(() => vscode.commands.executeCommand('workbench.action.openGlobalSettings'));
100+
loggingService.logError(`The following deprecated options have been detected:\n${oldArgs}`);
101+
}
76102
}

src/features/document-symbol-provider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
9999

100100
getSymbolTypes() {
101101
const config = vscode.workspace.getConfiguration('fortran');
102-
const symbolTypes = config.get<SymbolType[]>('symbols', ['subroutine', 'function']);
102+
// It does not make much sense for this to be an input option
103+
const symbolTypes: SymbolType[] = ['subroutine', 'function', 'variable'];
103104
return symbolTypes;
104105
}
105106
}

0 commit comments

Comments
 (0)