Skip to content

Commit

Permalink
Allows for fortls to be completly disabled.
Browse files Browse the repository at this point in the history
Also fixes forts missing warning disables fortls parsing if fortls is installed  #365
and adds more options for configuring the options through the UI.
  • Loading branch information
gnikit committed Jan 26, 2022
1 parent aaaba2c commit 4d77037
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
([#318](https://github.com/krvajal/vscode-fortran-support/issues/318))
- Fixes `%` accessor highlighting for type-bound subroutines
([#325](https://github.com/krvajal/vscode-fortran-support/issues/325))
- Fixes `fortls` not spawning when `ignoreWarning` was set to true
([#365](https://github.com/krvajal/vscode-fortran-support/issues/365))

### Changed

Expand All @@ -38,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
unnecessary the usage of Fortran Intellisense extension
([#290](https://github.com/krvajal/vscode-fortran-support/issues/290))
- Adds commands for re/starting/stopping the Language Server
- Added more options for configuring the `fortls` settings through the UI

## [2.6.2]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ A summary of all the options
| `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` |
| `fortls.maxCommentLineLength` | Number | -1 | Maximum comment line length (fortls requires v1.8.0+). |
| `fortls.extraArgs` | String Array | `[]` | Additional arguments for the fortls |
| `fortls.disabled` | Boolean | `false` | Disable the Language Server. If true, it will limit the extension's functionality substantially (should be avoid!) |
| `preferredCase` | `lowercase`, `uppercase` | `lowercase` | Specify the word case to use when suggesting autocomplete options |

## Requirements
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@
"default": [],
"description": "Additional arguments for the fortls"
},
"fortran.fortls.disabled": {
"type": "boolean",
"default": false,
"description": "Disable the Language Server. If true, it will limit the extension's functionality substantially (should be avoid!)"
},
"fortran.preferredCase": {
"type": "string",
"default": "lowercase",
Expand Down
52 changes: 29 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,39 @@ export async function activate(context: vscode.ExtensionContext) {
// Check if the language server is installed and if not prompt to install it
// Not the most elegant solution but we need pip install to have finished
// before the activate function is called so we do a little code duplication
which(config.get<string>('fortls.path'), (err: any) => {
if (!config.get('ignoreWarning.fortls')) {
if (err) {
const msg = `It is highly recommended to use the fortls to
if (!config.get<string>('fortls.disabled')) {
which(config.get<string>('fortls.path'), (err: any) => {
if (!config.get('ignoreWarning.fortls')) {
if (err) {
const msg = `It is highly recommended to use the fortls to
enable IDE features like hover, peeking, gotos and many more.
For a full list of features the language server adds see:
https://github.com/gnikit/fortls`;
promptForMissingTool(
LANG_SERVER_TOOL_ID,
msg,
'Python',
['Install', "Don't Show Again"],
loggingService,
() => {
config.update('ignoreWarning.fortls', true);
}
).then(() => {
const fortls = new FortranLanguageServer(loggingService);
fortls.activate();
});
} else {
// Spawn fortls
const fortls = new FortranLanguageServer(loggingService);
fortls.activate();
promptForMissingTool(
LANG_SERVER_TOOL_ID,
msg,
'Python',
['Install', "Don't Show Again"],
loggingService,
() => {
config.update('ignoreWarning.fortls', true);
}
).then(() => {
// fortls not installed AND Warnings are enabled
new FortranLanguageServer(loggingService).activate();
});
}
// Ignore fortls Warnings NOT set. Activate the LS
else {
new FortranLanguageServer(loggingService).activate();
}
}
}
});
// Ignore fortls Warnings are SET. Activate the LS
else {
new FortranLanguageServer(loggingService).activate();
}
});
}
}

function detectDeprecatedOptions() {
Expand Down
23 changes: 18 additions & 5 deletions src/features/fortls-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,31 @@ export class FortranLanguageServer {
const results = spawnSync(executablePath, args.concat(['--version']));
if (results.error) {
const selected = window.showErrorMessage(
'Error spawning fortls: Please check that "fortls" is installed and in your path.',
'Open settings'
'Error starting fortls: Check that fortls is in your PATH or that "fortran.fortls.path" is pointing to a fortls binary.',
'Settings',
'Workspace settings',
'Disable fortls'
);
selected.then(() => commands.executeCommand('workbench.action.openGlobalSettings'));
selected.then(opt => {
const config = workspace.getConfiguration(EXTENSION_ID);
if (opt === 'Settings') commands.executeCommand('workbench.action.openGlobalSettings');
else if (opt === 'Workspace settings')
commands.executeCommand('workbench.action.openWorkspaceSettings');
else if (opt === 'Disable fortls') config.update('fortls.disabled', true);
});
return null;
}
if (results.status !== 0) {
const selected = window.showErrorMessage(
'Error launching fortls: Please check that all selected options are supported by your language server version.',
'Open settings'
'Settings',
'Workspace settings'
);
selected.then(() => commands.executeCommand('workbench.action.openGlobalSettings'));
selected.then(opt => {
if (opt === 'settings') commands.executeCommand('workbench.action.openGlobalSettings');
else if (opt === 'Workspace settings')
commands.executeCommand('workbench.action.openWorkspaceSettings');
});
return null;
}
return results.stdout.toString().trim();
Expand Down

0 comments on commit 4d77037

Please # to comment.