Skip to content

Commit c69dc2a

Browse files
committed
Updates options.
- Symbols are always turned on through `fortls` so now the options are to use the `fortls` symbols or `fortls` + `Built-in` i.e. `Both` which does not make much sense but some people might end up using it. - Added the `-f(free|fixed)-line-length-<n>` arguments to be included automatically when when the `fortran.fortls.maxLineLength` is specified. - Added the flag for Intel's preprocessor `-fpp` to be included automatically.
1 parent d3474eb commit c69dc2a

File tree

6 files changed

+81
-71
lines changed

6 files changed

+81
-71
lines changed

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,29 @@ If the formatter is not present in the `PATH` its location can be input with
175175

176176
A summary of all the options
177177

178-
| Setting | Possible values | Default | Description |
179-
| ----------------------------- | ---------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------ |
180-
| `provide.hover` | `fortls`, `Built-in`, `Both`, `Disabled` | `fortls` | Enables hover support, by default it uses fortran-language-server |
181-
| `provide.autocomplete` | `fortls`, `Built-in`, `Both`, `Disabled` | `fortls` | Enables code autocompletion, by default it uses fortran-language-server |
182-
| `provide.symbols` | `fortls`, `Built-in`, `Both`, `Disabled` | `fortls` | Outline of type members in the document, by default it uses fortran-language-server |
183-
| `linter.compiler` | `gfortran`, `flang`, `ifort`, `Disabled` | `gfortran` | Compiler used for linting support |
184-
| `linter.includePaths` | String Array | `[]` | Specifies folder paths to be used as include paths during linting. Can handle globs |
185-
| `linter.compilerPath` | String | `''` | Specifies the path to the linter executable |
186-
| `linter.extraArgs` | String Array | `[-Wall]` | Pass additional options to the linter compiler |
187-
| `linter.modOutput` | String | `''` | Global output directory for .mod files generated due to linting |
188-
| `formatting.formatter` | `findent`, `fprettify`, `Disabled` | `findent` | Fortran formatter, currently supports findent and fprettify |
189-
| `fortran.formatting.args` | String Array | `[]` | Additional arguments for the formatter |
190-
| `formatting.path` | String | `''` | If the formatter is not in the $PATH specify the full path to its location |
191-
| `fortls.path` | String | `fortls` | Path to the Fortran language server (fortls) |
192-
| `fortls.preserveKeywordOrder` | Boolean | `true` | Display variable keywords information when hovering in original order (default: sort to consistent ordering) |
193-
| `fortls.disableDiagnostics` | Boolean | `false` | Disable diagnostics (requires v1.12.0+) |
194-
| `fortls.incrementalSync` | Boolean | `true` | Use incremental synchronization for file changes |
195-
| `fortls.notifyInit` | Boolean | `false` | Notify when workspace initialization is complete (requires v1.7.0+) |
196-
| `fortls.extraArgs` | String Array | `[]` | Additional arguments for the fortran-language-server |
197-
| `maxLineLength` | Number | -1 | Maximum line length (fortls requires v1.8.0+). Passed in both the linter and the language server |
198-
| `maxCommentLineLength` | Number | -1 | Maximum comment line length (fortls requires v1.8.0+). Passed in both the linter and the language server |
199-
| `preferredCase` | `lowercase`, `uppercase` | `lowercase` | Specify the word case to use when suggesting autocomplete options |
178+
| Setting | Possible values | Default | Description |
179+
| ----------------------------- | ---------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180+
| `provide.hover` | `fortls`, `Built-in`, `Both`, `Disabled` | `fortls` | Enables hover support, by default it uses fortran-language-server |
181+
| `provide.autocomplete` | `fortls`, `Built-in`, `Both`, `Disabled` | `fortls` | Enables code autocompletion, by default it uses fortran-language-server |
182+
| `provide.symbols` | `fortls`, `Both` | `fortls` | Outline of modules, functions, subroutines, etc. in the document, by default it uses fortran-language-server, `Both` will use `fortls` and the `Built-in` functionality (not recommended) |
183+
| `linter.compiler` | `gfortran`, `flang`, `ifort`, `Disabled` | `gfortran` | Compiler used for linting support |
184+
| `linter.includePaths` | String Array | `[]` | Specifies folder paths to be used as include paths during linting. Can handle globs |
185+
| `linter.compilerPath` | String | `''` | Specifies the path to the linter executable |
186+
| `linter.extraArgs` | String Array | `[-Wall]` | Pass additional options to the linter compiler |
187+
| `linter.modOutput` | String | `''` | Global output directory for .mod files generated due to linting |
188+
| `formatting.formatter` | `findent`, `fprettify`, `Disabled` | `findent` | Fortran formatter, currently supports findent and fprettify |
189+
| `fortran.formatting.args` | String Array | `[]` | Additional arguments for the formatter |
190+
| `formatting.path` | String | `''` | If the formatter is not in the $PATH specify the full path to its location |
191+
| `fortls.path` | String | `fortls` | Path to the Fortran language server (fortls) |
192+
| `fortls.preserveKeywordOrder` | Boolean | `true` | Display variable keywords information when hovering in original order (default: sort to consistent ordering) |
193+
| `fortls.disableDiagnostics` | Boolean | `false` | Disable additional diagnostics from fortls e.g. multiple variable definitions, unknown modules in use statement (requires v1.12.0+) |
194+
| `fortls.incrementalSync` | Boolean | `true` | Use incremental synchronization for file changes |
195+
| `fortls.symbolTypes` | Boolean | `trues` | Include derived types in the symbols outline. If false it adds the `--symbol_skip_mem` argument to fortls. |
196+
| `fortls.notifyInit` | Boolean | `false` | Notify when workspace initialization is complete (requires v1.7.0+) |
197+
| `fortls.maxLineLength` | Number | -1 | Maximum line length (fortls requires v1.8.0+). For `gfortran` and `flang` this also sets the linting compiler flag `-ffree-line-length-<n>` and `-ffixed-line-length-<n>`. Default value is `none` |
198+
| `fortls.maxCommentLineLength` | Number | -1 | Maximum comment line length (fortls requires v1.8.0+). |
199+
| `fortls.extraArgs` | String Array | `[]` | Additional arguments for the fortran-language-server |
200+
| `preferredCase` | `lowercase`, `uppercase` | `lowercase` | Specify the word case to use when suggesting autocomplete options |
200201

201202
## Requirements
202203

package.json

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@
155155
"default": "fortls",
156156
"enum": [
157157
"fortls",
158-
"Built-in",
159-
"Both",
160-
"Disabled"
158+
"Both"
161159
],
162-
"description": "Outline of type members in the document, by default it uses fortran-language-server."
160+
"description": "Outline of modules, functions, subroutines, etc. in the document, by default it uses fortran-language-server, `Both` will use `fortls` and the `Built-in` functionality (not recommended)."
163161
},
164162
"fortran.linter.compiler": {
165163
"type": "string",
@@ -234,18 +232,33 @@
234232
"fortran.fortls.disableDiagnostics": {
235233
"type": "boolean",
236234
"default": false,
237-
"description": "Disable diagnostics (requires v1.12.0+)."
235+
"description": "Disable additional diagnostics from fortls e.g. multiple variable definitions, unknown modules in use statement (requires v1.12.0+)."
238236
},
239237
"fortran.fortls.incrementalSync": {
240238
"type": "boolean",
241239
"default": true,
242240
"description": "Use incremental synchronization for file changes."
243241
},
242+
"fortran.fortls.symbolTypes": {
243+
"type": "boolean",
244+
"default": true,
245+
"description": "Include derived types in the symbols outline. If false it adds the `--symbol_skip_mem` argument to fortls."
246+
},
244247
"fortran.fortls.notifyInit": {
245248
"type": "boolean",
246249
"default": false,
247250
"description": "Notify when workspace initialization is complete (requires v1.7.0+)."
248251
},
252+
"fortran.fortls.maxLineLength": {
253+
"type": "number",
254+
"default": -1,
255+
"description": "Maximum line length (fortls requires v1.8.0+). For `gfortran` and `flang` this also sets the linting compiler flag `-ffree-line-length-<n>` and `-ffixed-line-length-<n>`. Default value is `none`."
256+
},
257+
"fortran.fortls.maxCommentLineLength": {
258+
"type": "number",
259+
"default": -1,
260+
"description": "Maximum comment line length (fortls requires v1.8.0+)."
261+
},
249262
"fortran.fortls.extraArgs": {
250263
"type": [
251264
"array"
@@ -256,16 +269,6 @@
256269
"default": [],
257270
"description": "Additional arguments for the fortran-language-server"
258271
},
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."
263-
},
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."
268-
},
269272
"fortran.preferredCase": {
270273
"type": "string",
271274
"default": "lowercase",
@@ -294,7 +297,7 @@
294297
"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."
295298
},
296299
"fortran.symbols": {
297-
"deprecationMessage": "fortran.symbols has been removed in favour of returning all symbols."
300+
"deprecationMessage": "fortran.symbols has been removed in favour of the fortran language server returning all symbols."
298301
},
299302
"fortran.provideHover": {
300303
"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."

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function activate(context: vscode.ExtensionContext) {
5858
vscode.languages.registerHoverProvider(FortranDocumentSelector(), hoverProvider);
5959
}
6060

61-
if (symbolsType === 'Built-in') {
61+
if (symbolsType === 'Both') {
6262
const symbolProvider = new FortranDocumentSymbolProvider();
6363
vscode.languages.registerDocumentSymbolProvider(FortranDocumentSelector(), symbolProvider);
6464
}

src/features/document-symbol-provider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
parseSubroutine as getDeclaredSubroutine,
1414
} from '../lib/functions';
1515
import { parseVars as getDeclaredVar } from '../lib/variables';
16+
import { EXTENSION_ID } from '../lib/tools';
1617

1718
type SymbolType = 'subroutine' | 'function' | 'variable';
1819
type ParserFunc = (line: TextLine) => SymbolInformation | undefined;
@@ -98,9 +99,9 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
9899
}
99100

100101
getSymbolTypes() {
101-
const config = vscode.workspace.getConfiguration('fortran');
102+
const config = vscode.workspace.getConfiguration(EXTENSION_ID);
102103
// It does not make much sense for this to be an input option
103-
const symbolTypes: SymbolType[] = ['subroutine', 'function', 'variable'];
104+
const symbolTypes: SymbolType[] = ['subroutine', 'function'];
104105
return symbolTypes;
105106
}
106107
}

src/features/fortls-interface.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,43 @@ export class FortranLanguageServer {
4242
*/
4343
private didOpenTextDocument(document: TextDocument): void {
4444
// We are only interested in Fortran files
45-
if (!document.languageId.toLowerCase().startsWith('fortran')) {
45+
if (
46+
!FortranDocumentSelector().some(e => e.scheme === document.uri.scheme) ||
47+
!FortranDocumentSelector().some(e => e.language === document.languageId)
48+
) {
4649
return;
4750
}
4851
const uri = document.uri;
4952
const folder = workspace.getWorkspaceFolder(uri);
5053
// Files outside a folder can't be handled. This might depend on the language.
5154
// Single file languages like JSON might handle files outside the workspace folders.
52-
if (!folder) {
53-
return;
54-
}
55-
this.logger.logInfo('Fortran Language Server');
55+
// This will be undefined if the file does not belong to the workspace
56+
if (!folder) return;
57+
if (this.clients.has(folder.uri.toString())) return;
5658

57-
// If we have nested workspace folders we only start a server on the outer most workspace folder.
58-
// folder = this.getOuterMostWorkspaceFolder(folder);
59-
if (this.clients.has(folder.uri.toString())) {
60-
return;
61-
}
59+
this.logger.logInfo('Initialising the Fortran Language Server');
6260

6361
// Get path for the language server
6462
const conf = workspace.getConfiguration(EXTENSION_ID);
65-
const executablePath = conf.get<string>('path') || 'fortls';
66-
const maxLineLength = conf.get<number>('maxLineLength') || -1;
67-
const maxCommentLineLength = conf.get<number>('maxCommentLineLength') || -1;
63+
const executablePath = conf.get<string>('fortls.path');
64+
const maxLineLength = conf.get<number>('fortls.maxLineLength');
65+
const maxCommentLineLength = conf.get<number>('fortls.maxCommentLineLength');
66+
const fortlsExtraArgs = conf.get<string[]>('fortls.extraArgs');
67+
const autocomplete = conf.get<string>('provide.autocomplete');
68+
const letterCase = conf.get<string>('preferredCase');
69+
const hover = conf.get<string>('provide.hover');
6870

6971
// Setup server arguments
7072
const args: string[] = ['--enable_code_actions'];
71-
// todo: fortran.useFortranLanguageServer: true|false
72-
if (conf.get<string>('provide.autocomplete', 'fortls') === 'Disabled') {
73+
if (autocomplete === 'Disabled' || autocomplete === 'Built-in') {
7374
args.push('--autocomplete_no_prefix');
7475
}
75-
if (conf.get<string>('preferredCase', 'lowercase') === 'lowercase') {
76-
args.push('--lowercase_intrinsics');
77-
}
78-
if (conf.get<string>('provide.symbols', 'fortls') === 'Disabled') {
79-
args.push('--symbol_skip_mem');
80-
}
81-
8276
// Enable all hover functionality. Does not make much sense to have one
8377
// but not the other two
84-
if (
85-
conf.get<string>('provide.hover', 'fortls') === 'fortls' ||
86-
conf.get<string>('provide.hover', 'fortls') === 'Both'
87-
) {
78+
if (hover === 'fortls' || hover === 'Both') {
8879
args.push('--variable_hover', '--hover_signature', '--use_signature_help');
8980
}
81+
if (letterCase === 'lowercase') args.push('--lowercase_intrinsics');
9082

9183
// FORTLS specific args with no overlap with the main extension
9284
if (conf.get<boolean>('fortls.preserveKeywordOrder')) {
@@ -96,19 +88,24 @@ export class FortranLanguageServer {
9688
args.push('--disable_diagnostics');
9789
}
9890
if (conf.get<boolean>('fortls.incrementalSync')) {
99-
args.push('--incrmental_sync');
91+
args.push('--incremental_sync');
92+
}
93+
if (!conf.get<boolean>('fortls.symbolTypes')) {
94+
args.push('--symbol_skip_mem');
10095
}
10196
if (conf.get<boolean>('fortls.notifyInit')) {
10297
args.push('--notify_init');
10398
}
10499

105-
// TODO: this should also be passed in the linter.extraArgs
106100
if (maxLineLength > 0) {
107101
args.push(`--max_line_length=${maxLineLength}`);
108102
}
109103
if (maxCommentLineLength > 0) {
110104
args.push(`--max_comment_line_length=${maxCommentLineLength}`);
111105
}
106+
if (fortlsExtraArgs.length > 0) {
107+
args.push(...fortlsExtraArgs);
108+
}
112109

113110
// Detect language server version and verify selected options
114111
this._fortlsVersion = this.getLSVersion(executablePath, args);

0 commit comments

Comments
 (0)