From 392d3dcf6c57d8f75514594f7b00da21a6a3c0ca Mon Sep 17 00:00:00 2001 From: gnikit Date: Wed, 26 Jan 2022 05:43:09 +0000 Subject: [PATCH] fixes formatters on Windows Closes Formatter and Fortran Server do not install #354 --- CHANGELOG.md | 2 ++ src/features/formatting-provider.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 969020c9..48ae725f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ([#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)) +- Fixes formatting on Windows (needed .exe extension) + ([#354](https://github.com/krvajal/vscode-fortran-support/issues/354)) ### Changed diff --git a/src/features/formatting-provider.ts b/src/features/formatting-provider.ts index e57a2d1c..27569e9f 100644 --- a/src/features/formatting-provider.ts +++ b/src/features/formatting-provider.ts @@ -43,7 +43,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP return; } - const formatterName = 'fprettify'; + const formatterName = process.platform !== 'win32' ? 'fprettify' : 'fprettify.exe'; const formatterPath: string = this.getFormatterPath(); const formatter: string = path.join(formatterPath, formatterName); // If no formatter is detected try and install it @@ -58,19 +58,19 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP // args.push('--silent'); // TODO: pass? // Get current file (name rel to path), run extension can be in a shell?? - const process = cp.spawn(formatter, args); + const pid = cp.spawn(formatter, args); // if the findent then capture the output from that and parse it back to the file - process.stdout.on('data', data => { + pid.stdout.on('data', data => { this.logger.logInfo(`formatter stdout: ${data}`); }); - process.stderr.on('data', data => { + pid.stderr.on('data', data => { this.logger.logError(`formatter stderr: ${data}`); }); - process.on('close', (code: number) => { + pid.on('close', (code: number) => { if (code !== 0) this.logger.logInfo(`formatter exited with code: ${code}`); }); - process.on('error', code => { + pid.on('error', code => { this.logger.logInfo(`formatter exited with code: ${code}`); }); } @@ -82,7 +82,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP * @param document vscode.TextDocument document to operate on */ private doFormatFindent(document: vscode.TextDocument) { - const formatterName = 'findent'; + const formatterName = process.platform !== 'win32' ? 'findent' : 'findent.exe'; const formatterPath: string = this.getFormatterPath(); let formatter: string = path.join(formatterPath, formatterName); // If no formatter is detected try and install it