Skip to content

Commit 26e4c97

Browse files
committed
Cleanups
1 parent 902204c commit 26e4c97

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
223223

224224
let serverEnvironment: IEnvVars = await workspace.getConfiguration('haskell', uri).serverEnvironment;
225225
if (addInternalServerPath !== undefined) {
226-
const newPath = await addPathToProcessPath(addInternalServerPath, logger);
226+
const newPath = await addPathToProcessPath(addInternalServerPath);
227227
serverEnvironment = {
228228
...serverEnvironment,
229229
...{ PATH: newPath },

src/hlsBinaries.ts

Lines changed: 21 additions & 23 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,14 @@ async function callAsync(
135134
/** Gets serverExecutablePath and fails if it's not set.
136135
*/
137136
async function findServerExecutable(
138-
context: ExtensionContext,
139137
logger: Logger,
140138
folder?: WorkspaceFolder
141139
): Promise<string> {
142140
let exePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
143141
logger.info(`Trying to find the server executable in: ${exePath}`);
144142
exePath = resolvePathPlaceHolders(exePath, folder);
145143
logger.log(`Location after path variables substitution: ${exePath}`);
146-
if (await executableExists(exePath)) {
144+
if (executableExists(exePath)) {
147145
return exePath;
148146
} else {
149147
const msg = `Could not find a HLS binary at ${exePath}! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.`;
@@ -153,13 +151,13 @@ async function findServerExecutable(
153151

154152
/** Searches the PATH. Fails if nothing is found.
155153
*/
156-
async function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
154+
async function findHLSinPATH(_context: ExtensionContext, logger: Logger): Promise<string> {
157155
// try PATH
158156
const exes: string[] = ['haskell-language-server-wrapper', 'haskell-language-server'];
159157
logger.info(`Searching for server executables ${exes.join(',')} in $PATH`);
160158
logger.info(`$PATH environment variable: ${process.env.PATH}`);
161159
for (const exe of exes) {
162-
if (await executableExists(exe)) {
160+
if (executableExists(exe)) {
163161
logger.info(`Found server executable in $PATH: ${exe}`);
164162
return exe;
165163
}
@@ -189,7 +187,7 @@ export async function findHaskellLanguageServer(
189187
logger.info('Finding haskell-language-server');
190188

191189
if (workspace.getConfiguration('haskell').get('serverExecutablePath') as string) {
192-
const exe = await findServerExecutable(context, logger, folder);
190+
const exe = await findServerExecutable(logger, folder);
193191
return [exe, undefined];
194192
}
195193

@@ -226,7 +224,7 @@ export async function findHaskellLanguageServer(
226224
}
227225

228226
if (manageHLS === 'PATH') {
229-
const exe = await findHLSinPATH(context, logger, folder);
227+
const exe = await findHLSinPATH(context, logger);
230228
return [exe, undefined];
231229
} else {
232230
// we manage HLS, make sure ghcup is installed/available
@@ -267,7 +265,7 @@ export async function findHaskellLanguageServer(
267265
latestStack = await getLatestToolFromGHCup(context, logger, 'stack');
268266
}
269267
if (recGHC === undefined) {
270-
recGHC = !(await executableExists('ghc'))
268+
recGHC = !(executableExists('ghc'))
271269
? await getLatestAvailableToolFromGHCup(context, logger, 'ghc', 'recommended')
272270
: null;
273271
}
@@ -407,7 +405,7 @@ export async function findHaskellLanguageServer(
407405
if (projectHls) {
408406
return [path.join(hlsBinDir, `haskell-language-server-wrapper${exeExt}`), hlsBinDir];
409407
} else {
410-
const exe = await findHLSinPATH(context, logger, folder);
408+
const exe = await findHLSinPATH(context, logger);
411409
return [exe, hlsBinDir];
412410
}
413411
}
@@ -470,8 +468,8 @@ async function getLatestProjectHLS(
470468
const merged = new Map<string, string[]>([...metadataMap, ...ghcupMap]); // right-biased
471469
// now sort and get the latest suitable version
472470
const latest = [...merged]
473-
.filter(([k, v]) => v.some((x) => x === projectGhc))
474-
.sort(([k1, v1], [k2, v2]) => comparePVP(k1, k2))
471+
.filter(([_k, v]) => v.some((x) => x === projectGhc))
472+
.sort(([k1, _v1], [k2, _v2]) => comparePVP(k1, k2))
475473
.pop();
476474

477475
if (!latest) {
@@ -484,7 +482,7 @@ async function getLatestProjectHLS(
484482
/**
485483
* Obtain the project ghc version from the HLS - Wrapper (which must be in PATH now).
486484
* Also, serves as a sanity check.
487-
* @param wrapper Path to the Haskell-Language-Server wrapper
485+
* @param toolchainBindir Path to the toolchainn bin directory (added to PATH)
488486
* @param workingDir Directory to run the process, usually the root of the workspace.
489487
* @param logger Logger for feedback.
490488
* @returns The GHC version, or fail with an `Error`.
@@ -499,7 +497,7 @@ export async function getProjectGHCVersion(
499497

500498
const args = ['--project-ghc-version'];
501499

502-
const newPath = await addPathToProcessPath(toolchainBindir, logger);
500+
const newPath = await addPathToProcessPath(toolchainBindir);
503501
const environmentNew: IEnvVars = {
504502
PATH: newPath,
505503
};
@@ -550,14 +548,14 @@ export async function upgradeGHCup(context: ExtensionContext, logger: Logger): P
550548
}
551549
}
552550

553-
export async function findGHCup(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
551+
export async function findGHCup(_context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
554552
logger.info('Checking for ghcup installation');
555553
let exePath = workspace.getConfiguration('haskell').get('ghcupExecutablePath') as string;
556554
if (exePath) {
557555
logger.info(`Trying to find the ghcup executable in: ${exePath}`);
558556
exePath = resolvePathPlaceHolders(exePath, folder);
559557
logger.log(`Location after path variables substitution: ${exePath}`);
560-
if (await executableExists(exePath)) {
558+
if (executableExists(exePath)) {
561559
return exePath;
562560
} else {
563561
throw new Error(`Could not find a ghcup binary at ${exePath}!`);
@@ -684,8 +682,8 @@ async function toolInstalled(
684682
version: string
685683
): Promise<InstalledTool> {
686684
const b = await callGHCup(context, logger, ['whereis', tool, version], undefined, false)
687-
.then((x) => true)
688-
.catch((x) => false);
685+
.then((_x) => true)
686+
.catch((_x) => false);
689687
return new InstalledTool(tool, version, b);
690688
}
691689

@@ -737,7 +735,7 @@ export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
737735
*/
738736
async function getHLSesfromMetadata(context: ExtensionContext, logger: Logger): Promise<Map<string, string[]> | null> {
739737
const storagePath: string = await getStoragePath(context);
740-
const metadata = await getReleaseMetadata(context, storagePath, logger).catch((e) => null);
738+
const metadata = await getReleaseMetadata(context, storagePath, logger).catch((_e) => null);
741739
if (!metadata) {
742740
window.showErrorMessage('Could not get release metadata');
743741
return null;
@@ -803,23 +801,23 @@ export function findSupportedHlsPerGhc(
803801
/**
804802
* Download GHCUP metadata.
805803
*
806-
* @param context Extension context.
804+
* @param _context Extension context.
807805
* @param storagePath Path to put in binary files and caches.
808806
* @param logger Logger for feedback.
809807
* @returns Metadata of releases, or null if the cache can not be found.
810808
*/
811809
async function getReleaseMetadata(
812-
context: ExtensionContext,
810+
_context: ExtensionContext,
813811
storagePath: string,
814812
logger: Logger
815813
): Promise<ReleaseMetadata | null> {
816814
const releasesUrl = workspace.getConfiguration('haskell').releasesURL
817-
? url.parse(workspace.getConfiguration('haskell').releasesURL)
815+
? new URL(workspace.getConfiguration('haskell').releasesURL)
818816
: undefined;
819817
const opts: https.RequestOptions = releasesUrl
820818
? {
821819
host: releasesUrl.host,
822-
path: releasesUrl.path,
820+
path: releasesUrl.pathname,
823821
}
824822
: {
825823
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): 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)