Skip to content

Commit

Permalink
fixes formatters on Windows
Browse files Browse the repository at this point in the history
Closes Formatter and Fortran Server do not install #354
  • Loading branch information
gnikit committed Jan 26, 2022
1 parent 4d77037 commit 392d3dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/features/formatting-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}`);
});
}
Expand All @@ -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
Expand Down

0 comments on commit 392d3dc

Please # to comment.