Skip to content

Commit 4c05c15

Browse files
committed
Cleanups
1 parent 902204c commit 4c05c15

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

src/hlsBinaries.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { stat } from 'fs/promises';
55
import * as https from 'https';
66
import * as path from 'path';
77
import { match } from 'ts-pattern';
8-
import * as url from 'url';
98
import { promisify } from 'util';
109
import { ConfigurationTarget, ExtensionContext, ProgressLocation, window, workspace, WorkspaceFolder } from 'vscode';
1110
import { Logger } from 'vscode-languageclient';
@@ -68,7 +67,7 @@ async function callAsync(
6867
envAdd?: IEnvVars,
6968
callback?: ProcessCallback
7069
): Promise<string> {
71-
let newEnv: IEnvVars = await resolveServerEnvironmentPATH(
70+
let newEnv: IEnvVars = resolveServerEnvironmentPATH(
7271
workspace.getConfiguration('haskell').get('serverEnvironment') || {}
7372
);
7473
newEnv = { ...(process.env as IEnvVars), ...newEnv, ...(envAdd || {}) };
@@ -135,15 +134,15 @@ async function callAsync(
135134
/** Gets serverExecutablePath and fails if it's not set.
136135
*/
137136
async function findServerExecutable(
138-
context: ExtensionContext,
137+
_context: ExtensionContext,
139138
logger: Logger,
140139
folder?: WorkspaceFolder
141140
): Promise<string> {
142141
let exePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
143142
logger.info(`Trying to find the server executable in: ${exePath}`);
144143
exePath = resolvePathPlaceHolders(exePath, folder);
145144
logger.log(`Location after path variables substitution: ${exePath}`);
146-
if (await executableExists(exePath)) {
145+
if (executableExists(exePath)) {
147146
return exePath;
148147
} else {
149148
const msg = `Could not find a HLS binary at ${exePath}! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.`;
@@ -153,13 +152,13 @@ async function findServerExecutable(
153152

154153
/** Searches the PATH. Fails if nothing is found.
155154
*/
156-
async function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
155+
async function findHLSinPATH(_context: ExtensionContext, logger: Logger): Promise<string> {
157156
// try PATH
158157
const exes: string[] = ['haskell-language-server-wrapper', 'haskell-language-server'];
159158
logger.info(`Searching for server executables ${exes.join(',')} in $PATH`);
160159
logger.info(`$PATH environment variable: ${process.env.PATH}`);
161160
for (const exe of exes) {
162-
if (await executableExists(exe)) {
161+
if (executableExists(exe)) {
163162
logger.info(`Found server executable in $PATH: ${exe}`);
164163
return exe;
165164
}
@@ -226,7 +225,7 @@ export async function findHaskellLanguageServer(
226225
}
227226

228227
if (manageHLS === 'PATH') {
229-
const exe = await findHLSinPATH(context, logger, folder);
228+
const exe = await findHLSinPATH(context, logger);
230229
return [exe, undefined];
231230
} else {
232231
// we manage HLS, make sure ghcup is installed/available
@@ -267,7 +266,7 @@ export async function findHaskellLanguageServer(
267266
latestStack = await getLatestToolFromGHCup(context, logger, 'stack');
268267
}
269268
if (recGHC === undefined) {
270-
recGHC = !(await executableExists('ghc'))
269+
recGHC = !(executableExists('ghc'))
271270
? await getLatestAvailableToolFromGHCup(context, logger, 'ghc', 'recommended')
272271
: null;
273272
}
@@ -407,7 +406,7 @@ export async function findHaskellLanguageServer(
407406
if (projectHls) {
408407
return [path.join(hlsBinDir, `haskell-language-server-wrapper${exeExt}`), hlsBinDir];
409408
} else {
410-
const exe = await findHLSinPATH(context, logger, folder);
409+
const exe = await findHLSinPATH(context, logger);
411410
return [exe, hlsBinDir];
412411
}
413412
}
@@ -470,8 +469,8 @@ async function getLatestProjectHLS(
470469
const merged = new Map<string, string[]>([...metadataMap, ...ghcupMap]); // right-biased
471470
// now sort and get the latest suitable version
472471
const latest = [...merged]
473-
.filter(([k, v]) => v.some((x) => x === projectGhc))
474-
.sort(([k1, v1], [k2, v2]) => comparePVP(k1, k2))
472+
.filter(([_k, v]) => v.some((x) => x === projectGhc))
473+
.sort(([k1, _v1], [k2, _v2]) => comparePVP(k1, k2))
475474
.pop();
476475

477476
if (!latest) {
@@ -484,7 +483,7 @@ async function getLatestProjectHLS(
484483
/**
485484
* Obtain the project ghc version from the HLS - Wrapper (which must be in PATH now).
486485
* Also, serves as a sanity check.
487-
* @param wrapper Path to the Haskell-Language-Server wrapper
486+
* @param toolchainBindir Path to the toolchainn bin directory (added to PATH)
488487
* @param workingDir Directory to run the process, usually the root of the workspace.
489488
* @param logger Logger for feedback.
490489
* @returns The GHC version, or fail with an `Error`.
@@ -550,14 +549,14 @@ export async function upgradeGHCup(context: ExtensionContext, logger: Logger): P
550549
}
551550
}
552551

553-
export async function findGHCup(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
552+
export async function findGHCup(_context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
554553
logger.info('Checking for ghcup installation');
555554
let exePath = workspace.getConfiguration('haskell').get('ghcupExecutablePath') as string;
556555
if (exePath) {
557556
logger.info(`Trying to find the ghcup executable in: ${exePath}`);
558557
exePath = resolvePathPlaceHolders(exePath, folder);
559558
logger.log(`Location after path variables substitution: ${exePath}`);
560-
if (await executableExists(exePath)) {
559+
if (executableExists(exePath)) {
561560
return exePath;
562561
} else {
563562
throw new Error(`Could not find a ghcup binary at ${exePath}!`);
@@ -684,8 +683,8 @@ async function toolInstalled(
684683
version: string
685684
): Promise<InstalledTool> {
686685
const b = await callGHCup(context, logger, ['whereis', tool, version], undefined, false)
687-
.then((x) => true)
688-
.catch((x) => false);
686+
.then((_x) => true)
687+
.catch((_x) => false);
689688
return new InstalledTool(tool, version, b);
690689
}
691690

@@ -737,7 +736,7 @@ export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
737736
*/
738737
async function getHLSesfromMetadata(context: ExtensionContext, logger: Logger): Promise<Map<string, string[]> | null> {
739738
const storagePath: string = await getStoragePath(context);
740-
const metadata = await getReleaseMetadata(context, storagePath, logger).catch((e) => null);
739+
const metadata = await getReleaseMetadata(context, storagePath, logger).catch((_e) => null);
741740
if (!metadata) {
742741
window.showErrorMessage('Could not get release metadata');
743742
return null;
@@ -803,23 +802,23 @@ export function findSupportedHlsPerGhc(
803802
/**
804803
* Download GHCUP metadata.
805804
*
806-
* @param context Extension context.
805+
* @param _context Extension context.
807806
* @param storagePath Path to put in binary files and caches.
808807
* @param logger Logger for feedback.
809808
* @returns Metadata of releases, or null if the cache can not be found.
810809
*/
811810
async function getReleaseMetadata(
812-
context: ExtensionContext,
811+
_context: ExtensionContext,
813812
storagePath: string,
814813
logger: Logger
815814
): Promise<ReleaseMetadata | null> {
816815
const releasesUrl = workspace.getConfiguration('haskell').releasesURL
817-
? url.parse(workspace.getConfiguration('haskell').releasesURL)
816+
? new URL(workspace.getConfiguration('haskell').releasesURL)
818817
: undefined;
819818
const opts: https.RequestOptions = releasesUrl
820819
? {
821820
host: releasesUrl.host,
822-
path: releasesUrl.path,
821+
path: releasesUrl.pathname,
823822
}
824823
: {
825824
host: 'raw.githubusercontent.com',

src/utils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as http from 'http';
66
import * as https from 'https';
77
import * as os from 'os';
88
import { extname } from 'path';
9-
import * as url from 'url';
109
import { promisify } from 'util';
1110
import { OutputChannel, ProgressLocation, window, workspace, WorkspaceFolder } from 'vscode';
1211
import { Logger } from 'vscode-languageclient';
@@ -215,10 +214,10 @@ export async function downloadFile(titleMsg: string, src: string, dest: string):
215214
},
216215
async (progress) => {
217216
const p = new Promise<void>((resolve, reject) => {
218-
const srcUrl = url.parse(src);
217+
const srcUrl = new URL(src);
219218
const opts: https.RequestOptions = {
220219
host: srcUrl.host,
221-
path: srcUrl.path,
220+
path: srcUrl.pathname,
222221
protocol: srcUrl.protocol,
223222
port: srcUrl.port,
224223
headers: userAgentHeader,
@@ -230,9 +229,9 @@ export async function downloadFile(titleMsg: string, src: string, dest: string):
230229

231230
// Decompress it if it's a gzip or zip
232231
const needsGunzip =
233-
res.headers['content-type'] === 'application/gzip' || extname(srcUrl.path ?? '') === '.gz';
232+
res.headers['content-type'] === 'application/gzip' || extname(srcUrl.pathname ?? '') === '.gz';
234233
const needsUnzip =
235-
res.headers['content-type'] === 'application/zip' || extname(srcUrl.path ?? '') === '.zip';
234+
res.headers['content-type'] === 'application/zip' || extname(srcUrl.pathname ?? '') === '.zip';
236235
if (needsGunzip) {
237236
const gunzip = createGunzip();
238237
gunzip.on('error', reject);
@@ -360,7 +359,7 @@ export function resolvePATHPlaceHolders(path: string) {
360359
}
361360

362361
// also honours serverEnvironment.PATH
363-
export async function addPathToProcessPath(extraPath: string, logger: Logger): Promise<string> {
362+
export async function addPathToProcessPath(extraPath: string, _logger: Logger): Promise<string> {
364363
const pathSep = process.platform === 'win32' ? ';' : ':';
365364
const serverEnvironment: IEnvVars = (await workspace.getConfiguration('haskell').get('serverEnvironment')) || {};
366365
const path: string[] = serverEnvironment.PATH

0 commit comments

Comments
 (0)