From ad4e257df72da7cdcc6c4555165b350799c26180 Mon Sep 17 00:00:00 2001 From: gnikit Date: Fri, 19 Nov 2021 16:36:36 +0000 Subject: [PATCH 1/4] Fixes formatter detection check Also adds output on successfull install. There is still a problem with the install tool returning a promise that is being fullfied after we have executed the formatter (that is if the tool is missing) which results into the user having to call the formatter twice to format the document. --- src/features/formatting-provider.ts | 30 +++++++++++++---------------- src/lib/tools.ts | 3 +++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/features/formatting-provider.ts b/src/features/formatting-provider.ts index 97d39aa9..6efe0838 100644 --- a/src/features/formatting-provider.ts +++ b/src/features/formatting-provider.ts @@ -45,16 +45,14 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP const formatterName = 'fprettify'; const formatterPath: string = this.getFormatterPath(); - // If no formatter path is present check that formatter is present in $PATH - if (!formatterPath) { - if (!which.sync(formatterName, { nothrow: true })) { - this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. + const formatter: string = path.join(formatterPath, formatterName); + // If no formatter is detected try and install it + if (!which.sync(formatter, { nothrow: true })) { + this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. Attempting to install now.`); - const msg = `Installing ${formatterName} through pip with --user option`; - promptForMissingTool(formatterName, msg, 'Python'); - } + const msg = `Installing ${formatterName} through pip with --user option`; + promptForMissingTool(formatterName, msg, 'Python'); } - const formatter: string = path.join(formatterPath, formatterName); const args: string[] = [document.fileName, ...this.getFormatterArgs()]; // args.push('--silent'); // TODO: pass? @@ -86,16 +84,14 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP private doFormatFindent(document: vscode.TextDocument) { const formatterName = 'findent'; const formatterPath: string = this.getFormatterPath(); - // If no formatter path is present check that formatter is present in $PATH - if (!formatterPath) { - if (!which.sync(formatterName, { nothrow: true })) { - this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. - Attempting to install now.`); - const msg = `Installing ${formatterName} through pip with --user option`; - promptForMissingTool(formatterName, msg, 'Python'); - } - } let formatter: string = path.join(formatterPath, formatterName); + // If no formatter is detected try and install it + if (!which.sync(formatter, { nothrow: true })) { + this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. + Attempting to install now.`); + const msg = `Installing ${formatterName} through pip with --user option`; + promptForMissingTool(formatterName, msg, 'Python'); + } // Annoyingly findent only outputs to a file and not to a stream so // let us go and create a temporary file diff --git a/src/lib/tools.ts b/src/lib/tools.ts index 2fd65ab5..2f4db311 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -75,6 +75,7 @@ export function promptForMissingTool( default: logger.logError(`Failed to install tool: ${tool}`); + vscode.window.showErrorMessage(`Failed to install tool: ${tool}`); break; } } @@ -100,6 +101,8 @@ export function installPythonTool(pyPackage: string, logger?: LoggingService) { logger.logError( `Python package ${pyPackage} failed to install with code: ${code}, signal: ${signal}` ); + } else { + logger.logInfo(`Successfully installed ${pyPackage}.`); } }); installProcess.on('error', err => { From ccb003dc4ff5d8dda6672be7c892b2fe76a1ba57 Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 24 Nov 2021 12:46:03 +0000 Subject: [PATCH 2/4] Adds Don't Show Again action when fortls is missing --- package.json | 5 +++ src/extension.ts | 14 +++++++- src/features/formatting-provider.ts | 4 +-- src/lib/tools.ts | 51 +++++++++++++++-------------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 7c0a77b5..e8463aca 100644 --- a/package.json +++ b/package.json @@ -221,6 +221,11 @@ "uppercase" ], "description": "Specify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')" + }, + "fortran.ignoreWarning.fortls": { + "type": "boolean", + "default": false, + "description": "Hide error message when the fortran-language-server is not detected" } } }, diff --git a/src/extension.ts b/src/extension.ts index 961ba41e..8bf93146 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -71,6 +71,18 @@ export function activate(context: vscode.ExtensionContext) { enable hover, peeking, gotos and many more. For a full list of features the language server adds see: https://github.com/hansec/fortran-language-server`; - promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService); + + if (!extensionConfig.get('ignoreWarning.fortls')) { + promptForMissingTool( + LANG_SERVER_TOOL_ID, + msg, + 'Python', + ['Install', "Don't Show Again"], + loggingService, + () => { + extensionConfig.update('ignoreWarning.fortls', true); + } + ); + } } } diff --git a/src/features/formatting-provider.ts b/src/features/formatting-provider.ts index 6efe0838..e57a2d1c 100644 --- a/src/features/formatting-provider.ts +++ b/src/features/formatting-provider.ts @@ -51,7 +51,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. Attempting to install now.`); const msg = `Installing ${formatterName} through pip with --user option`; - promptForMissingTool(formatterName, msg, 'Python'); + promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger); } const args: string[] = [document.fileName, ...this.getFormatterArgs()]; @@ -90,7 +90,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP this.logger.logWarning(`Formatter: ${formatterName} not detected in your system. Attempting to install now.`); const msg = `Installing ${formatterName} through pip with --user option`; - promptForMissingTool(formatterName, msg, 'Python'); + promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger); } // Annoyingly findent only outputs to a file and not to a stream so diff --git a/src/lib/tools.ts b/src/lib/tools.ts index 2f4db311..a0a549a0 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -47,40 +47,43 @@ export function FortranDocumentSelector(folder?: vscode.WorkspaceFolder) { * e.g 'hansec.fortran-ls' * * @param tool name of the tool e.g. fortran-language-server - * @param msg optional message for installing said package + * @param msg message for installing said package * @param toolType type of tool, supports `Python` (through pip) and 'VSExt' + * @param opts options for the prompt. "Install" and "Don't Show Again" are coded + * @param logger log channel output + * @param action a void function for an action to perform when "Don't Show Again" is pressed */ export function promptForMissingTool( tool: string, msg: string, toolType: string, - logger?: LoggingService + opts: string[], + logger?: LoggingService, + action?: () => void ) { const items = ['Install']; - return new Promise((resolve, reject) => { - resolve( - vscode.window.showInformationMessage(msg, ...items).then(selected => { - if (selected === 'Install') { - switch (toolType) { - case 'Python': - installPythonTool(tool, logger); - break; + return vscode.window.showInformationMessage(msg, ...opts).then(selected => { + if (selected === 'Install') { + switch (toolType) { + case 'Python': + installPythonTool(tool, logger); + break; - case 'VSExt': - logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`); - vscode.commands.executeCommand('extension.open', tool); - vscode.commands.executeCommand('workbench.extensions.installExtension', tool); - logger.logInfo(`Extension ${tool} successfully installed`); - break; + case 'VSExt': + logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`); + vscode.commands.executeCommand('extension.open', tool); + vscode.commands.executeCommand('workbench.extensions.installExtension', tool); + logger.logInfo(`Extension ${tool} successfully installed`); + break; - default: - logger.logError(`Failed to install tool: ${tool}`); - vscode.window.showErrorMessage(`Failed to install tool: ${tool}`); - break; - } - } - }) - ); + default: + logger.logError(`Failed to install tool: ${tool}`); + vscode.window.showErrorMessage(`Failed to install tool: ${tool}`); + break; + } + } else if (selected === "Don't Show Again") { + action(); + } }); } From d42397cc8837b51ed9292f21fa4e65eafdd79e90 Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 24 Nov 2021 12:55:12 +0000 Subject: [PATCH 3/4] Updates CHANGELOG.md --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 280e55f7..bfa13791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [2.6.2] + +### Added + +- Adds Don't Show Again option when failing to spawn `fortls`, Fortran Intellisense + pop-up has already been removed + ([#303](https://github.com/krvajal/vscode-fortran-support/issues/303)) + ## [2.6.1] ### Fixed @@ -336,7 +344,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Initial release -[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.6.1...HEAD +[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.6.2...HEAD +[2.6.2]: https://github.com/krvajal/vscode-fortran-support/compare/v2.6.1...v2.6.2 [2.6.1]: https://github.com/krvajal/vscode-fortran-support/compare/v2.6.0...v2.6.1 [2.6.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.5.0...v2.6.0 [2.5.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.3...v2.5.0 From 8af8962ba4a6da2b3233048f3fe88d9f3a15847f Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 24 Nov 2021 13:07:44 +0000 Subject: [PATCH 4/4] 2.6.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 514d8def..e1e8c8ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "linter-gfortran", - "version": "2.6.1", + "version": "2.6.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "linter-gfortran", - "version": "2.6.1", + "version": "2.6.2", "license": "MIT", "dependencies": { "fast-glob": "^3.2.7", diff --git a/package.json b/package.json index e8463aca..f62ada80 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "linter-gfortran", "displayName": "Modern Fortran", "description": "Modern Fortran language support, including syntax highlighting and error detection.", - "version": "2.6.1", + "version": "2.6.2", "publisher": "krvajalm", "license": "MIT", "author": {