Skip to content

Commit 6877c6a

Browse files
committed
Fixes fortls install prompt waiting before spawning fortls
1 parent 525980f commit 6877c6a

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

src/extension.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ export function activate(context: vscode.ExtensionContext) {
6464
}
6565

6666
// Check if the language server is installed and if not prompt to install it
67-
if (!which.sync('fortls', { nothrow: true })) {
68-
const msg = `It is highly recommended to use the fortran-language-server to
69-
enable hover, peeking, gotos and many more.
67+
// Not the most elegant solution but we need pip install to have finished
68+
// before the activate function is called so we do a little code duplication
69+
which(config.get<string>('fortls.path'), err => {
70+
if (err) {
71+
const msg = `It is highly recommended to use the fortran-language-server to
72+
enable IDE features like hover, peeking, gotos and many more.
7073
For a full list of features the language server adds see:
7174
https://github.com/hansec/fortran-language-server`;
72-
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
73-
}
74-
75-
// Spawn the fortran-language-server
76-
const fortls = new FortranLanguageServer(loggingService);
77-
fortls.activate(context.subscriptions);
75+
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService).then(() => {
76+
const fortls = new FortranLanguageServer(loggingService);
77+
fortls.activate(context.subscriptions);
78+
});
79+
} else {
80+
// Spawn the fortran-language-server
81+
const fortls = new FortranLanguageServer(loggingService);
82+
fortls.activate(context.subscriptions);
83+
}
84+
});
7885
}
7986

8087
function detectDeprecatedOptions() {

src/lib/tools.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export function FortranDocumentSelector(folder?: vscode.WorkspaceFolder) {
5050
* @param msg optional message for installing said package
5151
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
5252
*/
53-
export function promptForMissingTool(
53+
export async function promptForMissingTool(
5454
tool: string,
5555
msg: string,
5656
toolType: string,
5757
logger?: LoggingService
5858
) {
5959
const items = ['Install'];
6060
return new Promise((resolve, reject) => {
61-
resolve(
61+
return resolve(
6262
vscode.window.showInformationMessage(msg, ...items).then(selected => {
6363
if (selected === 'Install') {
6464
switch (toolType) {
@@ -92,22 +92,22 @@ export function promptForMissingTool(
9292
* @param logger `optional` logging channel for output
9393
*/
9494
export function installPythonTool(pyPackage: string, logger?: LoggingService) {
95-
const installProcess = cp.spawn('pip', 'install --user --upgrade '.concat(pyPackage).split(' '));
96-
installProcess.stdout.on('data', data => {
97-
logger.logInfo(`pip install: ${data}`);
98-
});
99-
installProcess.on('exit', (code, signal) => {
100-
if (code !== 0) {
101-
logger.logError(
102-
`Python package ${pyPackage} failed to install with code: ${code}, signal: ${signal}`
103-
);
104-
} else {
105-
logger.logInfo(`Successfully installed ${pyPackage}.`);
106-
}
107-
});
108-
installProcess.on('error', err => {
109-
logger.logError(`${err}`);
110-
});
95+
const installProcess = cp.spawnSync(
96+
'pip',
97+
'install --user --upgrade '.concat(pyPackage).split(' ')
98+
);
99+
if (installProcess.error) {
100+
logger.logError(
101+
`Python package ${pyPackage} failed to install with code: ${installProcess.error}`
102+
);
103+
}
104+
if (installProcess.stdout) {
105+
const sep = '-'.repeat(80);
106+
logger.logInfo(
107+
`pip install --user --upgrade ${pyPackage}:\n${sep}\n${installProcess.stdout}${sep}`
108+
);
109+
logger.logInfo(`pip install was successful`);
110+
}
111111
}
112112

113113
/**

0 commit comments

Comments
 (0)