Skip to content

Commit d2903be

Browse files
committed
Redesigns UI options menu
- Adds more `fortls` arguments - Arrange UI settings to sections, linting, formatting, LSP, etc. - Adds log output for fortls args - Changes fortls spawn error message
1 parent 89eb302 commit d2903be

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3636

3737
### Changed
3838

39+
- Prettified the format of the settings UI and added `fortls` options
3940
- Changed images from SVG to PNG because `vsce` does not support SVG
4041
([#510](https://github.com/fortran-lang/vscode-fortran-support/pull/510))
4142
- Changed need for matching begin-end scope names, in the following constructs:

package.json

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
"fortran.fortls.configure": {
279279
"type": "string",
280280
"default": "",
281-
"markdownDescription": "Filename holding additional configuration options. For more see: https://gnikit.github.io/fortls/options.html#configuration-using-a-file",
281+
"markdownDescription": "Filename holding additional configuration options. For more see: https://gnikit.github.io/fortls/options.html#configuration-using-a-file.",
282282
"order": 20
283283
},
284284
"fortran.fortls.notifyInit": {
@@ -293,6 +293,12 @@
293293
"markdownDescription": "Use incremental synchronization for file changes.",
294294
"order": 40
295295
},
296+
"fortran.fortls.nthreads": {
297+
"type": "integer",
298+
"default": 4,
299+
"markdownDescription": "Number of threads to use during workspace initialization (default: 4).",
300+
"order": 45
301+
},
296302
"fortran.fortls.sortKeywords": {
297303
"type": "boolean",
298304
"default": false,
@@ -305,6 +311,68 @@
305311
"markdownDescription": "Include derived types in the symbols outline. If false it adds the `--symbol_skip_mem` argument to fortls.",
306312
"order": 60
307313
},
314+
"fortran.fortls.suffixes": {
315+
"type": "array",
316+
"items": {
317+
"type": "string"
318+
},
319+
"default": [],
320+
"markdownDescription": "Parse additional file extensions to the default (**default**: `F,F77,F90,F95,F03,F08,FOR,FPP` (lower & upper casing)) (**fortls arg: `incl_suffixes`**). For more read the [documentation](https://gnikit.github.io/fortls/options.html#incl-suffixes).",
321+
"order": 61
322+
},
323+
"fortran.fortls.directories": {
324+
"type": "array",
325+
"items": {
326+
"type": "string"
327+
},
328+
"default": [],
329+
"markdownDescription": "Folders containing source files (**default: `['./**']`**), (**fortls arg: `source_dirs`**). For more read the [documentation](https://gnikit.github.io/fortls/options.html#source-dirs).",
330+
"order": 62
331+
},
332+
"fortran.fortls.excludeSuffixes": {
333+
"type": "array",
334+
"items": {
335+
"type": "string"
336+
},
337+
"default": [],
338+
"markdownDescription": "Source file extensions to be excluded (**fortls arg: `excl_suffixes`**). For more read the [documentation](https://gnikit.github.io/fortls/options.html#excl-suffixes).",
339+
"order": 63
340+
},
341+
"fortran.fortls.excludeDirectories": {
342+
"type": "array",
343+
"items": {
344+
"type": "string"
345+
},
346+
"default": [],
347+
"markdownDescription": "Folders to exclude from parsing (**fortls arg: `excl_paths`**). For more read the [documentation](https://gnikit.github.io/fortls/options.html#excl-paths).",
348+
"order": 64
349+
},
350+
"fortran.fortls.preprocessor.suffixes": {
351+
"type": "array",
352+
"items": {
353+
"type": "string"
354+
},
355+
"default": [],
356+
"markdownDescription": "File extensions to be parsed **ONLY** for preprocessor commands (**default**: all uppercase source file suffixes) (**fortls arg: `pp_suffixes`**). By default preprocessor definitions are parsed for all Fortran source files with uppercase extensions e.g. `.F90`, `.F`, `.F08`, etc.. However, the default behaviour can be overridden by defining `pp_defs`. For more read the [documentation](https://gnikit.github.io/fortls/options.html#pp-suffixes).",
357+
"order": 65
358+
},
359+
"fortran.fortls.preprocessor.directories": {
360+
"type": "array",
361+
"items": {
362+
"type": "string"
363+
},
364+
"default": [],
365+
"markdownDescription": "Folders containing preprocessor files with extensions `pp_suffixes` (**fortls arg: `include_dirs`**). Understands Python glob patterns. By default `fortls` will scan the project’s directories for files with extensions `pp_suffixes` to parse for **preprocessor definitions**. However, if the preprocessor files are external to the project, their locations can be specified via `include_dirs`. For more read the [documentation](https://gnikit.github.io/fortls/options.html#include-dirs).",
366+
"order": 66
367+
},
368+
"fortran.fortls.preprocessor.definitions": {
369+
"type": "object",
370+
"additionalProperties": {
371+
"type": "string"
372+
},
373+
"markdownDescription": "A dictionary of preprocessor definitions. (**fortls arg: `pp_defs`**). Preprocessor definitions are normally included via `include_dirs`. For more read the [documentation](https://gnikit.github.io/fortls/options.html#pp-defs).",
374+
"order": 67
375+
},
308376
"fortran.fortls.disableDiagnostics": {
309377
"type": "boolean",
310378
"default": false,

src/lsp/client.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ export class FortlsClient {
109109
if (!folder) {
110110
const fileRoot: string = path.dirname(document.uri.fsPath);
111111
if (clients.has(fileRoot)) return; // already registered
112-
this.logger.logInfo('Initialising Language Server for file: ' + document.uri.fsPath);
112+
this.logger.logInfo(
113+
'Initialising Language Server for file: ' +
114+
`${document.uri.fsPath} with command-line options: ${args.join(', ')}`
115+
);
113116
// Options to control the language client
114117
const clientOptions: LanguageClientOptions = {
115118
documentSelector: FortranDocumentSelector(fileRoot),
@@ -130,7 +133,10 @@ export class FortlsClient {
130133
if (!clients.has(folder.uri.toString())) {
131134
folder = getOuterMostWorkspaceFolder(folder);
132135
if (clients.has(folder.uri.toString())) return; // already registered
133-
this.logger.logInfo('Initialising Language Server for workspace: ' + folder.uri.fsPath);
136+
this.logger.logInfo(
137+
'Initialising Language Server for workspace: ' +
138+
`${document.uri.fsPath} with command-line options: ${args.join(', ')}`
139+
);
134140
// Options to control the language client
135141
const clientOptions: LanguageClientOptions = {
136142
documentSelector: FortranDocumentSelector(folder.uri.fsPath),
@@ -162,6 +168,7 @@ export class FortlsClient {
162168
const autocomplete = conf.get<string>('provide.autocomplete');
163169
const letterCase = conf.get<string>('preferredCase');
164170
const hover = conf.get<string>('provide.hover');
171+
const pp = workspace.getConfiguration(`${EXTENSION_ID}.fortls.preprocessor`);
165172

166173
// Setup server arguments
167174
const args: string[] = ['--enable_code_actions'];
@@ -179,6 +186,9 @@ export class FortlsClient {
179186
if (conf.get<string>('fortls.configure')) {
180187
args.push('-c', conf.get<string>('fortls.configure'));
181188
}
189+
if (conf.get<number>('fortls.nthreads')) {
190+
args.push(`--nthreads=${conf.get<number>('fortls.nthreads')}`);
191+
}
182192
if (conf.get<boolean>('fortls.notifyInit')) {
183193
args.push('--notify_init');
184194
}
@@ -207,6 +217,32 @@ export class FortlsClient {
207217
args.push(...fortlsExtraArgs);
208218
}
209219

220+
// Fortran source file parsing
221+
if (conf.get<string[]>('fortls.suffixes').length > 0) {
222+
args.push('--incl_suffixes', ...conf.get<string[]>('fortls.suffixes'));
223+
}
224+
if (conf.get<string[]>('fortls.directories').length > 0) {
225+
args.push('--source_dirs', ...conf.get<string[]>('fortls.directories'));
226+
}
227+
if (conf.get<string[]>('fortls.excludeSuffixes').length > 0) {
228+
args.push('--excl_suffixes', ...conf.get<string[]>('fortls.excludeSuffixes'));
229+
}
230+
if (conf.get<string[]>('fortls.excludeDirectories').length > 0) {
231+
args.push('--excl_paths', ...conf.get<string[]>('fortls.excludeDirectories'));
232+
}
233+
234+
// Preprocessor args
235+
if (pp.get<string[]>('suffixes').length > 0) {
236+
args.push(`--pp_suffixes`, ...pp.get<string[]>('suffixes'));
237+
}
238+
if (pp.get<string[]>('directories').length > 0) {
239+
args.push(`--include_dirs`, ...pp.get<string[]>('directories'));
240+
}
241+
const pp_defs = pp.get('definitions');
242+
if (Object.keys(pp_defs).length > 0) {
243+
args.push(`--pp_defs=${JSON.stringify(pp_defs)}`);
244+
}
245+
210246
return args;
211247
}
212248

@@ -224,7 +260,7 @@ export class FortlsClient {
224260
const results = spawnSync(executablePath, args.concat(['--version']));
225261
if (results.error) {
226262
const selected = window.showErrorMessage(
227-
'Error starting fortls: Check that fortls is in your PATH or that "fortran.fortls.path" is pointing to a fortls binary.',
263+
'Modern Fortran Error starting fortls: Check that fortls is in your PATH or that "fortran.fortls.path" is pointing to a fortls binary.',
228264
'Settings',
229265
'Workspace settings',
230266
'Disable fortls'

test/resources/.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"fortran.fortls.disableAutoupdate": true,
3+
"fortran.fortls.preprocessor.definitions": {
4+
"HAVE_ZOLTAN": "",
5+
"PetscInt": "integer(kind=selected_int_kind(5))"
6+
},
7+
"fortran.fortls.preprocessor.directories": ["include", "val"],
8+
"fortran.fortls.preprocessor.suffixes": [".fypp", ".f90"],
9+
"fortran.fortls.suffixes": [".FFF", ".F90-2018"],
10+
"fortran.fortls.directories": ["./**"],
11+
"fortran.fortls.excludeSuffixes": [".snap"],
12+
"fortran.fortls.excludeDirectories": [".vscode/"],
13+
"fortran.fortls.notifyInit": true
14+
}

0 commit comments

Comments
 (0)