Skip to content

Commit f07e89d

Browse files
committed
Add docs and extract constant to top-level scope
1 parent d690b8b commit f07e89d

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/hlsBinaries.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,34 @@ import { ToolConfig, Tool, initDefaultGHCup, GHCup } from './ghcup';
1515
import { getHlsMetadata } from './metadata';
1616
export { IEnvVars };
1717

18-
type ManageHLS = 'GHCup' | 'PATH';
19-
let manageHLS = workspace.getConfiguration('haskell').get('manageHLS') as ManageHLS;
20-
2118
export type Context = {
2219
manageHls: ManageHLS;
2320
storagePath: string;
2421
serverExecutable?: HlsExecutable;
2522
logger: Logger;
2623
};
2724

25+
/**
26+
* Global configuration for this extension.
27+
*/
28+
const haskellConfig = workspace.getConfiguration('haskell');
29+
2830
/**
2931
* On Windows the executable needs to be stored somewhere with an .exe extension
3032
*/
3133
const exeExt = process.platform === 'win32' ? '.exe' : '';
3234

35+
type ManageHLS = 'GHCup' | 'PATH';
36+
let manageHLS = haskellConfig.get('manageHLS') as ManageHLS;
37+
3338
/**
3439
* Gets serverExecutablePath and fails if it's not set.
3540
* @param logger Log progress.
3641
* @param folder Workspace folder. Used for resolving variables in the `serverExecutablePath`.
3742
* @returns Path to an HLS executable binary.
3843
*/
3944
function findServerExecutable(logger: Logger, folder?: WorkspaceFolder): string {
40-
const rawExePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
45+
const rawExePath = haskellConfig.get('serverExecutablePath') as string;
4146
logger.info(`Trying to find the server executable in: ${rawExePath}`);
4247
const resolvedExePath = resolvePathPlaceHolders(rawExePath, folder);
4348
logger.log(`Location after path variables substitution: ${resolvedExePath}`);
@@ -113,7 +118,7 @@ export async function findHaskellLanguageServer(
113118
): Promise<HlsExecutable> {
114119
logger.info('Finding haskell-language-server');
115120

116-
const hasConfigForExecutable = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
121+
const hasConfigForExecutable = haskellConfig.get('serverExecutablePath') as string;
117122
if (hasConfigForExecutable) {
118123
const exe = findServerExecutable(logger, folder);
119124
return {
@@ -151,9 +156,7 @@ export async function findHaskellLanguageServer(
151156
let projectGhc: string | undefined | null;
152157

153158
// support explicit toolchain config
154-
const toolchainConfig = new Map(
155-
Object.entries(workspace.getConfiguration('haskell').get('toolchain') as ToolConfig),
156-
) as ToolConfig;
159+
const toolchainConfig = new Map(Object.entries(haskellConfig.get('toolchain') as ToolConfig)) as ToolConfig;
157160
if (toolchainConfig) {
158161
latestHLS = toolchainConfig.get('hls');
159162
latestCabal = toolchainConfig.get('cabal');
@@ -181,7 +184,7 @@ export async function findHaskellLanguageServer(
181184
}
182185

183186
// download popups
184-
const promptBeforeDownloads = workspace.getConfiguration('haskell').get('promptBeforeDownloads') as boolean;
187+
const promptBeforeDownloads = haskellConfig.get('promptBeforeDownloads') as boolean;
185188
if (promptBeforeDownloads) {
186189
const hlsInstalled = latestHLS ? await installationStatusOfGhcupTool(ghcup, 'hls', latestHLS) : undefined;
187190
const cabalInstalled = latestCabal ? await installationStatusOfGhcupTool(ghcup, 'cabal', latestCabal) : undefined;
@@ -211,7 +214,7 @@ export async function findHaskellLanguageServer(
211214
logger.info(
212215
`User accepted download for ${toInstall.map((t) => t.nameWithVersion).join(', ')} and won't be asked again.`,
213216
);
214-
workspace.getConfiguration('haskell').update('promptBeforeDownloads', false);
217+
haskellConfig.update('promptBeforeDownloads', false);
215218
} else {
216219
toInstall.forEach((tool) => {
217220
if (tool !== undefined && !tool.installed) {
@@ -284,7 +287,7 @@ export async function findHaskellLanguageServer(
284287
logger.info(
285288
`User accepted download for ${toInstall.map((t) => t.nameWithVersion).join(', ')} and won't be asked again.`,
286289
);
287-
workspace.getConfiguration('haskell').update('promptBeforeDownloads', false);
290+
haskellConfig.update('promptBeforeDownloads', false);
288291
} else {
289292
toInstall.forEach((tool) => {
290293
if (!tool.installed) {
@@ -363,7 +366,7 @@ async function promptUserForManagingHls(context: ExtensionContext, manageHlsSett
363366
);
364367
howToManage = 'PATH';
365368
}
366-
workspace.getConfiguration('haskell').update('manageHLS', howToManage, ConfigurationTarget.Global);
369+
haskellConfig.update('manageHLS', howToManage, ConfigurationTarget.Global);
367370
context.globalState.update('pluginInitialized', true);
368371
return howToManage;
369372
} else {
@@ -468,8 +471,15 @@ export async function getProjectGhcVersion(
468471
);
469472
}
470473

474+
/**
475+
* Find the storage path for the extension.
476+
* If no custom location was given
477+
*
478+
* @param context Extension context for the 'Storage Path'.
479+
* @returns
480+
*/
471481
export function getStoragePath(context: ExtensionContext): string {
472-
let storagePath: string | undefined = workspace.getConfiguration('haskell').get('releasesDownloadStoragePath');
482+
let storagePath: string | undefined = haskellConfig.get('releasesDownloadStoragePath');
473483

474484
if (!storagePath) {
475485
storagePath = context.globalStorageUri.fsPath;

src/metadata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { match } from 'ts-pattern';
55
import { promisify } from 'util';
66
import { window, workspace } from 'vscode';
77
import { Logger } from 'vscode-languageclient';
8-
import { httpsGetSilently, IEnvVars } from './utils';
9-
export { IEnvVars };
8+
import { httpsGetSilently } from './utils';
109

1110
/**
1211
* Metadata of release information.

0 commit comments

Comments
 (0)