Skip to content

Commit

Permalink
formatting after prettier managed to run
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkonecny committed Dec 10, 2022
1 parent 066ca08 commit 1747802
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion schemas/fortls.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@
"type": "boolean"
}
}
}
}
23 changes: 12 additions & 11 deletions src/lib/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ export async function pipInstall(pyPackage: string): Promise<string> {

/**
* Checks whether python can be called from the shell.
*
*
* Tries `python` on Windows and `python3` on other platforms.
*
*
* TODO: this could also check for python version, which has to be > 3.7 for fortls.
*
*
* @returns name of the command to run python on the current platform
*/
export async function checkPython(): Promise<string> {
let py = "";
if (os.platform() == "win32") {
let py = '';
if (os.platform() == 'win32') {
py = 'python';
} else {
py = 'python3';
Expand All @@ -170,19 +170,20 @@ export async function checkPython(): Promise<string> {
await shellTask(py, args, 'getting python version');
return py;
} catch (e) {
let errMsg = "";
if (os.platform() == "win32") {
errMsg = py + " isn't callable from the shell. " +
"Please make sure python is installed and added to the PATH.";
let errMsg = '';
if (os.platform() == 'win32') {
errMsg =
py +
" isn't callable from the shell. " +
'Please make sure python is installed and added to the PATH.';
} else {
errMsg = py + " isn't callable from the shell. Please make sure python is installed";
}
}

return await new Promise<string>((result, reject) => {
reject(errMsg);
});
}

}

export async function shellTask(command: string, args: string[], name: string): Promise<string> {
Expand Down
26 changes: 12 additions & 14 deletions src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class FortlsClient {
// restart this class
this.deactivate();
this.activate();

} catch (error) {
this.logger.error(`[lsp.client] Error installing ${LS_NAME}: ${error}`);
window.showErrorMessage(error);
Expand All @@ -83,7 +82,6 @@ export class FortlsClient {
this.logger.info(`[lsp.client] ${LS_NAME} disabled in settings`);
}
});

} else {
workspace.onDidOpenTextDocument(this.didOpenTextDocument, this);
workspace.textDocuments.forEach(this.didOpenTextDocument, this);
Expand All @@ -100,7 +98,6 @@ export class FortlsClient {
}

return;

}

public async deactivate(): Promise<void> {
Expand Down Expand Up @@ -296,11 +293,11 @@ export class FortlsClient {

/**
* Tries to find fortls and saves its path to this.path.
*
*
* If a user path is configured, then only use this.
* If not, try running fortls globally, or from python user scripts folder on Windows.
*
* @returns true if fortls found, false if not
*
* @returns true if fortls found, false if not
*/
private getLSPath(): boolean {
const config = workspace.getConfiguration(EXTENSION_ID);
Expand All @@ -311,29 +308,31 @@ export class FortlsClient {
// if there's a user configured path to the executable, check if it's absolute
if (configuredPath !== '') {
if (!path.isAbsolute(configuredPath)) {
window.showErrorMessage("The path to fortls (fortran.fortls.path) must be absolute.");
window.showErrorMessage('The path to fortls (fortran.fortls.path) must be absolute.');
return false;
}

pathsToCheck.push(configuredPath);
} else {
// no user configured path => perform standard search for fortls

} else { // no user configured path => perform standard search for fortls

pathsToCheck.push('fortls');

// On Windows, `pip install fortls --user` installs fortls to the userbase\PythonXY\Scripts path,
// so we want to look for it in this path as well.
if (os.platform() == 'win32') {
const result = spawnSync('python', ['-c', 'import site; print(site.getusersitepackages())']);
const result = spawnSync('python', [
'-c',
'import site; print(site.getusersitepackages())',
]);
const userSitePackagesStr = result.stdout.toString().trim();

// check if the call above returned something, in case the site module in python ever changes...
if (userSitePackagesStr) {
const userScriptsPath = path.resolve(userSitePackagesStr, '../Scripts/fortls');
pathsToCheck.push(userScriptsPath);
}
}

}

// try to run `fortls --version` for all the given paths
Expand Down Expand Up @@ -400,7 +399,6 @@ export class FortlsClient {
return results.stdout.toString().trim();
}


/**
* Restart the language server
*/
Expand Down

0 comments on commit 1747802

Please sign in to comment.