Skip to content

Commit c9b422a

Browse files
committed
Prettier
1 parent 21dc371 commit c9b422a

File tree

3 files changed

+92
-58
lines changed

3 files changed

+92
-58
lines changed

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
201201
const newPath = await addPathToProcessPath(addInternalServerPath, logger);
202202
serverEnvironment = {
203203
...serverEnvironment,
204-
...{PATH: newPath},
204+
...{ PATH: newPath },
205205
};
206206
}
207207
const exeOptions: ExecutableOptions = {
208208
cwd: folder ? undefined : path.dirname(uri.fsPath),
209-
env: {...process.env, ...serverEnvironment},
209+
env: { ...process.env, ...serverEnvironment },
210210
};
211211

212212
// We don't want empty strings in our args

src/hlsBinaries.ts

Lines changed: 81 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ import {
1717
WorkspaceFolder,
1818
} from 'vscode';
1919
import { Logger } from 'vscode-languageclient';
20-
import { executableExists, httpsGetSilently, resolvePathPlaceHolders, IEnvVars, addPathToProcessPath, resolveServerEnvironmentPATH } from './utils';
21-
export { IEnvVars }
20+
import {
21+
executableExists,
22+
httpsGetSilently,
23+
resolvePathPlaceHolders,
24+
IEnvVars,
25+
addPathToProcessPath,
26+
resolveServerEnvironmentPATH,
27+
} from './utils';
28+
export { IEnvVars };
2229

2330
export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
2431

@@ -99,9 +106,11 @@ async function callAsync(
99106
reject: (reason?: any) => void
100107
) => void
101108
): Promise<string> {
102-
let newEnv: IEnvVars = await resolveServerEnvironmentPATH(workspace.getConfiguration('haskell').get('serverEnvironment') || {});
103-
newEnv = {...process.env as IEnvVars, ...newEnv};
104-
newEnv = {...newEnv, ...(envAdd || {})};
109+
let newEnv: IEnvVars = await resolveServerEnvironmentPATH(
110+
workspace.getConfiguration('haskell').get('serverEnvironment') || {}
111+
);
112+
newEnv = { ...(process.env as IEnvVars), ...newEnv };
113+
newEnv = { ...newEnv, ...(envAdd || {}) };
105114
return window.withProgress(
106115
{
107116
location: ProgressLocation.Notification,
@@ -158,7 +167,11 @@ async function callAsync(
158167

159168
/** Gets serverExecutablePath and fails if it's not set.
160169
*/
161-
async function findServerExecutable(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
170+
async function findServerExecutable(
171+
context: ExtensionContext,
172+
logger: Logger,
173+
folder?: WorkspaceFolder
174+
): Promise<string> {
162175
let exePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
163176
logger.info(`Trying to find the server executable in: ${exePath}`);
164177
exePath = resolvePathPlaceHolders(exePath, folder);
@@ -225,14 +238,15 @@ export async function findHaskellLanguageServer(
225238
const promptMessage = 'How do you want the extension to manage/discover HLS and the relevant toolchain?';
226239

227240
const decision =
228-
(await window.showInformationMessage(promptMessage, 'automatically via GHCup', 'manually via PATH')) ||
229-
null;
241+
(await window.showInformationMessage(promptMessage, 'automatically via GHCup', 'manually via PATH')) || null;
230242
if (decision === 'automatically via GHCup') {
231243
manageHLS = 'GHCup';
232244
} else if (decision === 'manually via PATH') {
233245
manageHLS = 'PATH';
234246
} else {
235-
window.showWarningMessage('Choosing default PATH method for HLS discovery. You can change this via \'haskell.manageHLS\' in the settings.');
247+
window.showWarningMessage(
248+
"Choosing default PATH method for HLS discovery. You can change this via 'haskell.manageHLS' in the settings."
249+
);
236250
manageHLS = 'PATH';
237251
}
238252
workspace.getConfiguration('haskell').update('manageHLS', manageHLS, ConfigurationTarget.Global);
@@ -254,26 +268,28 @@ export async function findHaskellLanguageServer(
254268
? await getLatestToolFromGHCup(context, logger, 'stack')
255269
: null;
256270
const recGHC =
257-
(!(await executableExists('ghc')) && (workspace.getConfiguration('haskell').get('installGHC') as boolean))
271+
!(await executableExists('ghc')) && (workspace.getConfiguration('haskell').get('installGHC') as boolean)
258272
? await getLatestAvailableToolFromGHCup(context, logger, 'ghc', 'recommended')
259273
: null;
260274

261275
const latestToolchainBindir = await callGHCup(
262-
context,
263-
logger,
264-
[ 'run'
265-
, '--hls', latestHLS
266-
, ...(latestCabal ? ['--cabal', latestCabal] : [])
267-
, ...(latestStack ? ['--stack', latestStack] : [])
268-
, ...(recGHC ? ['--ghc', 'recommended'] : [])
269-
, '--install'
270-
],
271-
'Installing latest toolchain for bootstrap',
272-
true,
273-
(err, stdout, _stderr, resolve, reject) => {
274-
err ? reject("Couldn't install latest toolchain") : resolve(stdout?.trim());
275-
}
276-
);
276+
context,
277+
logger,
278+
[
279+
'run',
280+
'--hls',
281+
latestHLS,
282+
...(latestCabal ? ['--cabal', latestCabal] : []),
283+
...(latestStack ? ['--stack', latestStack] : []),
284+
...(recGHC ? ['--ghc', 'recommended'] : []),
285+
'--install',
286+
],
287+
'Installing latest toolchain for bootstrap',
288+
true,
289+
(err, stdout, _stderr, resolve, reject) => {
290+
err ? reject("Couldn't install latest toolchain") : resolve(stdout?.trim());
291+
}
292+
);
277293

278294
// now figure out the project GHC version and the latest supported HLS version
279295
// we need for it (e.g. this might in fact be a downgrade for old GHCs)
@@ -283,16 +299,19 @@ export async function findHaskellLanguageServer(
283299
const hlsBinDir = await callGHCup(
284300
context,
285301
logger,
286-
[ 'run'
287-
, '--hls', projectHls
288-
, ...(latestCabal ? ['--cabal', latestCabal] : [])
289-
, ...(latestStack ? ['--stack', latestStack] : [])
290-
, ...((workspace.getConfiguration('haskell').get('installGHC') as boolean) ? ['--ghc', projectGhc] : [])
291-
, '--install'],
302+
[
303+
'run',
304+
'--hls',
305+
projectHls,
306+
...(latestCabal ? ['--cabal', latestCabal] : []),
307+
...(latestStack ? ['--stack', latestStack] : []),
308+
...((workspace.getConfiguration('haskell').get('installGHC') as boolean) ? ['--ghc', projectGhc] : []),
309+
'--install',
310+
],
292311
`Installing project specific toolchain: HLS-${projectHls}, GHC-${projectGhc}, cabal-${latestCabal}, stack-${latestStack}`,
293312
true
294313
);
295-
return (path.join(hlsBinDir, `haskell-language-server-wrapper${exeExt}`))
314+
return path.join(hlsBinDir, `haskell-language-server-wrapper${exeExt}`);
296315
}
297316
}
298317

@@ -370,7 +389,11 @@ async function getLatestProjectHLS(
370389
* @param logger Logger for feedback.
371390
* @returns The GHC version, or fail with an `Error`.
372391
*/
373-
export async function getProjectGHCVersion(toolchainBindir: string, workingDir: string, logger: Logger): Promise<string> {
392+
export async function getProjectGHCVersion(
393+
toolchainBindir: string,
394+
workingDir: string,
395+
logger: Logger
396+
): Promise<string> {
374397
const title = 'Working out the project GHC version. This might take a while...';
375398
logger.info(title);
376399

@@ -409,7 +432,11 @@ export async function getProjectGHCVersion(toolchainBindir: string, workingDir:
409432
}
410433
reject(new MissingToolError('unknown'));
411434
}
412-
reject(Error(`haskell-language-server --project-ghc-version exited with exit code ${err.code}:\n${stdout}\n${stderr}`));
435+
reject(
436+
Error(
437+
`haskell-language-server --project-ghc-version exited with exit code ${err.code}:\n${stdout}\n${stderr}`
438+
)
439+
);
413440
} else {
414441
logger.info(`The GHC version for the project or file: ${stdout?.trim()}`);
415442
resolve(stdout?.trim());
@@ -422,7 +449,7 @@ export async function upgradeGHCup(context: ExtensionContext, logger: Logger): P
422449
if (manageHLS === 'GHCup') {
423450
const upgrade = workspace.getConfiguration('haskell').get('upgradeGHCup') as boolean;
424451
if (upgrade) {
425-
await callGHCup(context, logger, ['upgrade'], 'Upgrading ghcup', true);
452+
await callGHCup(context, logger, ['upgrade'], 'Upgrading ghcup', true);
426453
}
427454
} else {
428455
throw new Error(`Internal error: tried to call ghcup while haskell.manageHLS is set to ${manageHLS}. Aborting!`);
@@ -447,7 +474,7 @@ export async function findGHCup(context: ExtensionContext, logger: Logger, folde
447474
throw new MissingToolError('ghcup');
448475
} else {
449476
logger.info(`found ghcup at ${localGHCup}`);
450-
return localGHCup
477+
return localGHCup;
451478
}
452479
}
453480
}
@@ -516,7 +543,7 @@ async function getLatestToolFromGHCup(context: ExtensionContext, logger: Logger,
516543
const latestInstalledVersion = latestInstalled.split(/\s+/)[1];
517544

518545
let bin = await callGHCup(context, logger, ['whereis', tool, `${latestInstalledVersion}`], undefined, false);
519-
const ver = await callAsync(`${bin}`, ['--numeric-version'], logger, undefined, undefined, false)
546+
const ver = await callAsync(`${bin}`, ['--numeric-version'], logger, undefined, undefined, false);
520547
if (ver) {
521548
return ver;
522549
} else {
@@ -527,38 +554,45 @@ async function getLatestToolFromGHCup(context: ExtensionContext, logger: Logger,
527554
return getLatestAvailableToolFromGHCup(context, logger, tool);
528555
}
529556

530-
async function getLatestAvailableToolFromGHCup(context: ExtensionContext, logger: Logger, tool: string, tag?: string, criteria?: string): Promise<string> {
557+
async function getLatestAvailableToolFromGHCup(
558+
context: ExtensionContext,
559+
logger: Logger,
560+
tool: string,
561+
tag?: string,
562+
criteria?: string
563+
): Promise<string> {
531564
// fall back to installable versions
532565
const availableVersions = await callGHCup(
533566
context,
534567
logger,
535568
['list', '-t', tool, '-c', criteria ? criteria : 'available', '-r'],
536569
undefined,
537570
false
538-
).then(s => s.split(/\r?\n/));
571+
).then((s) => s.split(/\r?\n/));
539572

540573
let latestAvailable: string | null = null;
541574
availableVersions.forEach((ver) => {
542-
if (ver.split(/\s+/)[2].split(',').includes(tag ? tag : 'latest')) {
575+
if (
576+
ver
577+
.split(/\s+/)[2]
578+
.split(',')
579+
.includes(tag ? tag : 'latest')
580+
) {
543581
latestAvailable = ver.split(/\s+/)[1];
544582
}
545583
});
546584
if (!latestAvailable) {
547-
throw new Error(`Unable to find ${tag ? tag : 'latest'} tool ${tool}`)
585+
throw new Error(`Unable to find ${tag ? tag : 'latest'} tool ${tool}`);
548586
} else {
549587
return latestAvailable;
550588
}
551589
}
552590

553-
554591
// complements getLatestHLSfromMetadata, by checking possibly locally compiled
555592
// HLS in ghcup
556593
// If 'targetGhc' is omitted, picks the latest 'haskell-language-server-wrapper',
557594
// otherwise ensures the specified GHC is supported.
558-
async function getHLSesFromGHCup(
559-
context: ExtensionContext,
560-
logger: Logger
561-
): Promise<Map<string, string[]> | null> {
595+
async function getHLSesFromGHCup(context: ExtensionContext, logger: Logger): Promise<Map<string, string[]> | null> {
562596
const hlsVersions = await callGHCup(
563597
context,
564598
logger,
@@ -604,10 +638,7 @@ async function getHLSesFromGHCup(
604638
* @param logger Logger for feedback
605639
* @returns
606640
*/
607-
async function getHLSesfromMetadata(
608-
context: ExtensionContext,
609-
logger: Logger
610-
): Promise<Map<string, string[]> | null> {
641+
async function getHLSesfromMetadata(context: ExtensionContext, logger: Logger): Promise<Map<string, string[]> | null> {
611642
const storagePath: string = await getStoragePath(context);
612643
const metadata = await getReleaseMetadata(context, storagePath, logger).catch((e) => null);
613644
if (!metadata) {

src/utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ function getWithRedirects(opts: https.RequestOptions, f: (res: http.IncomingMess
286286
*/
287287
export async function executableExists(exe: string): Promise<boolean> {
288288
const isWindows = process.platform === 'win32';
289-
let newEnv: IEnvVars = await resolveServerEnvironmentPATH(workspace.getConfiguration('haskell').get('serverEnvironment') || {});
290-
newEnv = {...process.env as IEnvVars, ...newEnv};
289+
let newEnv: IEnvVars = await resolveServerEnvironmentPATH(
290+
workspace.getConfiguration('haskell').get('serverEnvironment') || {}
291+
);
292+
newEnv = { ...(process.env as IEnvVars), ...newEnv };
291293
const cmd: string = isWindows ? 'where' : 'which';
292294
const out = child_process.spawnSync(cmd, [exe], { env: newEnv });
293295
return out.status === 0 || (which.sync(exe, { nothrow: true, path: newEnv.PATH }) ?? '') !== '';
@@ -333,10 +335,11 @@ export async function addPathToProcessPath(extraPath: string, logger: Logger): P
333335

334336
export async function resolveServerEnvironmentPATH(serverEnv: IEnvVars): Promise<IEnvVars> {
335337
const pathSep = process.platform === 'win32' ? ';' : ':';
336-
const path: string[] | null = serverEnv.PATH ? serverEnv.PATH.split(pathSep).map((p) => resolvePATHPlaceHolders(p)) : null;
338+
const path: string[] | null = serverEnv.PATH
339+
? serverEnv.PATH.split(pathSep).map((p) => resolvePATHPlaceHolders(p))
340+
: null;
337341
return {
338342
...serverEnv,
339-
...(path ? { PATH: path.join(pathSep)} : {})
340-
}
343+
...(path ? { PATH: path.join(pathSep) } : {}),
344+
};
341345
}
342-

0 commit comments

Comments
 (0)