Skip to content

Commit fcedc8b

Browse files
committed
Updates fortls interface
1 parent 18f0cea commit fcedc8b

File tree

2 files changed

+70
-40
lines changed

2 files changed

+70
-40
lines changed

package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,20 @@
228228
"default": "fortls",
229229
"description": "Path to the Fortran language server (fortls)."
230230
},
231-
"fortran.fortls.preserveKeywordOrder": {
231+
"fortran.fortls.configure": {
232+
"type": "string",
233+
"default": "",
234+
"description": "Filename holding additional configuration options. For more see: https://gnikit.github.io/fortls/options.html#configuration-using-a-file"
235+
},
236+
"fortran.fortls.sortKeywords": {
232237
"type": "boolean",
233-
"default": true,
234-
"description": "Display variable keywords information when hovering in original order (default: sort to consistent ordering)."
238+
"default": false,
239+
"description": "Display variable keywords information when hovering in a sorted, consistent order."
240+
},
241+
"fortran.fortls.disableAutoupdate": {
242+
"type": "boolean",
243+
"default": false,
244+
"description": "fortls will automatically attempt to update itself from PyPi. Set this option if you want to fix your version of fortls. Autoudpate will not occur for Anaconda environments."
235245
},
236246
"fortran.fortls.disableDiagnostics": {
237247
"type": "boolean",
@@ -318,6 +328,9 @@
318328
},
319329
"fortran.provideCompletion": {
320330
"deprecationMessage": "fortran.provideCompletion has been renamed to fortran.provide.autocomplete. By default the fortls autocompletion is used, to enable the built-in autocompletion turn on the Built-in option."
331+
},
332+
"fortran.fortls.preserveKeywordOrder": {
333+
"deprecationMessage": "This option is now the default, use fortran.fortls.sortKeywords to sort keywords."
321334
}
322335
}
323336
},

src/features/fortls-interface.ts

+54-37
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ export class FortranLanguageServer {
7676

7777
this.logger.logInfo('Initialising the Fortran Language Server');
7878

79+
const args: string[] = await this.fortlsArguments();
80+
const executablePath = workspace.getConfiguration(EXTENSION_ID).get<string>('fortls.path');
81+
82+
// Detect language server version and verify selected options
83+
this._fortlsVersion = this.getLSVersion(executablePath, args);
84+
if (this._fortlsVersion) {
85+
const serverOptions: ServerOptions = {
86+
command: executablePath,
87+
args: args,
88+
};
89+
90+
// Options to control the language client
91+
const clientOptions: LanguageClientOptions = {
92+
// Register the server for all Fortran documents in workspace
93+
// NOTE: remove the folder args and workspaceFolder to ge single file language servers
94+
// will also have to change the checkLanguageServerActivation method
95+
// we want fortran documents but not just in the workspace
96+
// if in the workspace do provide
97+
documentSelector: FortranDocumentSelector(folder),
98+
workspaceFolder: folder,
99+
};
100+
101+
// Create the language client, start the client and add it to the registry
102+
const client = new LanguageClient(
103+
'fortls',
104+
'Fortran Language Server',
105+
serverOptions,
106+
clientOptions
107+
);
108+
client.start();
109+
clients.set(folder.uri.toString(), client);
110+
}
111+
}
112+
113+
/**
114+
* Sets `fortls` arguments based on VS Code settings
115+
* @returns argument list
116+
*/
117+
private async fortlsArguments() {
79118
// Get path for the language server
80119
const conf = workspace.getConfiguration(EXTENSION_ID);
81120
const executablePath = conf.get<string>('fortls.path');
@@ -94,27 +133,32 @@ export class FortranLanguageServer {
94133
// Enable all hover functionality. Does not make much sense to have one
95134
// but not the other two
96135
if (hover === 'fortls' || hover === 'Both') {
97-
args.push('--variable_hover', '--hover_signature', '--use_signature_help');
136+
args.push('--hover_signature', '--use_signature_help');
98137
}
99138
if (letterCase === 'lowercase') args.push('--lowercase_intrinsics');
100139

101140
// FORTLS specific args with no overlap with the main extension
102-
if (conf.get<boolean>('fortls.preserveKeywordOrder')) {
103-
args.push('--preserve_keyword_order');
141+
if (conf.get<string>('fortls.configure')) {
142+
args.push('-c', conf.get<string>('fortls.configure'));
104143
}
105-
if (conf.get<boolean>('fortls.disableDiagnostics')) {
106-
args.push('--disable_diagnostics');
144+
if (conf.get<boolean>('fortls.notifyInit')) {
145+
args.push('--notify_init');
107146
}
108147
if (conf.get<boolean>('fortls.incrementalSync')) {
109148
args.push('--incremental_sync');
110149
}
150+
if (conf.get<boolean>('fortls.sortKeywords')) {
151+
args.push('--sort_keywords');
152+
}
153+
if (conf.get<boolean>('fortls.disableAutoupdate')) {
154+
args.push('--disable_autoupdate');
155+
}
156+
if (conf.get<boolean>('fortls.disableDiagnostics')) {
157+
args.push('--disable_diagnostics');
158+
}
111159
if (!conf.get<boolean>('fortls.symbolTypes')) {
112160
args.push('--symbol_skip_mem');
113161
}
114-
if (conf.get<boolean>('fortls.notifyInit')) {
115-
args.push('--notify_init');
116-
}
117-
118162
if (maxLineLength > 0) {
119163
args.push(`--max_line_length=${maxLineLength}`);
120164
}
@@ -125,34 +169,7 @@ export class FortranLanguageServer {
125169
args.push(...fortlsExtraArgs);
126170
}
127171

128-
// Detect language server version and verify selected options
129-
this._fortlsVersion = this.getLSVersion(executablePath, args);
130-
if (this._fortlsVersion) {
131-
// Check if there is a newer version
132-
// this.checkVersion(this._fortlsVersion);
133-
134-
const serverOptions: ServerOptions = {
135-
command: executablePath,
136-
args: args,
137-
};
138-
139-
// Options to control the language client
140-
const clientOptions: LanguageClientOptions = {
141-
// Register the server for all Fortran documents in workspace
142-
documentSelector: FortranDocumentSelector(folder),
143-
workspaceFolder: folder,
144-
};
145-
146-
// Create the language client, start the client and add it to the registry
147-
const client = new LanguageClient(
148-
'fortls',
149-
'Fortran Language Server',
150-
serverOptions,
151-
clientOptions
152-
);
153-
client.start();
154-
clients.set(folder.uri.toString(), client);
155-
}
172+
return args;
156173
}
157174

158175
/**

0 commit comments

Comments
 (0)