Skip to content

Commit ad4e257

Browse files
committed
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.
1 parent 589bb81 commit ad4e257

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/features/formatting-provider.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
4545

4646
const formatterName = 'fprettify';
4747
const formatterPath: string = this.getFormatterPath();
48-
// If no formatter path is present check that formatter is present in $PATH
49-
if (!formatterPath) {
50-
if (!which.sync(formatterName, { nothrow: true })) {
51-
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
48+
const formatter: string = path.join(formatterPath, formatterName);
49+
// If no formatter is detected try and install it
50+
if (!which.sync(formatter, { nothrow: true })) {
51+
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
5252
Attempting to install now.`);
53-
const msg = `Installing ${formatterName} through pip with --user option`;
54-
promptForMissingTool(formatterName, msg, 'Python');
55-
}
53+
const msg = `Installing ${formatterName} through pip with --user option`;
54+
promptForMissingTool(formatterName, msg, 'Python');
5655
}
57-
const formatter: string = path.join(formatterPath, formatterName);
5856

5957
const args: string[] = [document.fileName, ...this.getFormatterArgs()];
6058
// args.push('--silent'); // TODO: pass?
@@ -86,16 +84,14 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
8684
private doFormatFindent(document: vscode.TextDocument) {
8785
const formatterName = 'findent';
8886
const formatterPath: string = this.getFormatterPath();
89-
// If no formatter path is present check that formatter is present in $PATH
90-
if (!formatterPath) {
91-
if (!which.sync(formatterName, { nothrow: true })) {
92-
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
93-
Attempting to install now.`);
94-
const msg = `Installing ${formatterName} through pip with --user option`;
95-
promptForMissingTool(formatterName, msg, 'Python');
96-
}
97-
}
9887
let formatter: string = path.join(formatterPath, formatterName);
88+
// If no formatter is detected try and install it
89+
if (!which.sync(formatter, { nothrow: true })) {
90+
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
91+
Attempting to install now.`);
92+
const msg = `Installing ${formatterName} through pip with --user option`;
93+
promptForMissingTool(formatterName, msg, 'Python');
94+
}
9995

10096
// Annoyingly findent only outputs to a file and not to a stream so
10197
// let us go and create a temporary file

src/lib/tools.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function promptForMissingTool(
7575

7676
default:
7777
logger.logError(`Failed to install tool: ${tool}`);
78+
vscode.window.showErrorMessage(`Failed to install tool: ${tool}`);
7879
break;
7980
}
8081
}
@@ -100,6 +101,8 @@ export function installPythonTool(pyPackage: string, logger?: LoggingService) {
100101
logger.logError(
101102
`Python package ${pyPackage} failed to install with code: ${code}, signal: ${signal}`
102103
);
104+
} else {
105+
logger.logInfo(`Successfully installed ${pyPackage}.`);
103106
}
104107
});
105108
installProcess.on('error', err => {

0 commit comments

Comments
 (0)