@@ -15,29 +15,34 @@ import { ToolConfig, Tool, initDefaultGHCup, GHCup, GHCupConfig } from './ghcup'
1515import { getHlsMetadata } from './metadata' ;
1616export { IEnvVars } ;
1717
18- type ManageHLS = 'GHCup' | 'PATH' ;
19- let manageHLS = workspace . getConfiguration ( 'haskell' ) . get ( 'manageHLS' ) as ManageHLS ;
20-
2118export 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 */
3133const 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 */
3944function 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 } ` ) ;
@@ -114,7 +119,7 @@ export async function findHaskellLanguageServer(
114119) : Promise < HlsExecutable > {
115120 logger . info ( 'Finding haskell-language-server' ) ;
116121
117- const hasConfigForExecutable = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
122+ const hasConfigForExecutable = haskellConfig . get ( 'serverExecutablePath' ) as string ;
118123 if ( hasConfigForExecutable ) {
119124 const exe = findServerExecutable ( logger , folder ) ;
120125 return {
@@ -152,9 +157,7 @@ export async function findHaskellLanguageServer(
152157 let projectGhc : string | undefined | null ;
153158
154159 // support explicit toolchain config
155- const toolchainConfig = new Map (
156- Object . entries ( workspace . getConfiguration ( 'haskell' ) . get ( 'toolchain' ) as ToolConfig ) ,
157- ) as ToolConfig ;
160+ const toolchainConfig = new Map ( Object . entries ( haskellConfig . get ( 'toolchain' ) as ToolConfig ) ) as ToolConfig ;
158161 if ( toolchainConfig ) {
159162 latestHLS = toolchainConfig . get ( 'hls' ) ;
160163 latestCabal = toolchainConfig . get ( 'cabal' ) ;
@@ -182,7 +185,7 @@ export async function findHaskellLanguageServer(
182185 }
183186
184187 // download popups
185- const promptBeforeDownloads = workspace . getConfiguration ( 'haskell' ) . get ( 'promptBeforeDownloads' ) as boolean ;
188+ const promptBeforeDownloads = haskellConfig . get ( 'promptBeforeDownloads' ) as boolean ;
186189 if ( promptBeforeDownloads ) {
187190 const hlsInstalled = latestHLS ? await installationStatusOfGhcupTool ( ghcup , 'hls' , latestHLS ) : undefined ;
188191 const cabalInstalled = latestCabal ? await installationStatusOfGhcupTool ( ghcup , 'cabal' , latestCabal ) : undefined ;
@@ -212,7 +215,7 @@ export async function findHaskellLanguageServer(
212215 logger . info (
213216 `User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
214217 ) ;
215- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
218+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
216219 } else {
217220 toInstall . forEach ( ( tool ) => {
218221 if ( tool !== undefined && ! tool . installed ) {
@@ -285,7 +288,7 @@ export async function findHaskellLanguageServer(
285288 logger . info (
286289 `User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
287290 ) ;
288- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
291+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
289292 } else {
290293 toInstall . forEach ( ( tool ) => {
291294 if ( ! tool . installed ) {
@@ -364,7 +367,7 @@ async function promptUserForManagingHls(context: ExtensionContext, manageHlsSett
364367 ) ;
365368 howToManage = 'PATH' ;
366369 }
367- workspace . getConfiguration ( 'haskell' ) . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
370+ haskellConfig . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
368371 context . globalState . update ( 'pluginInitialized' , true ) ;
369372 return howToManage ;
370373 } else {
@@ -469,8 +472,15 @@ export async function getProjectGhcVersion(
469472 ) ;
470473}
471474
475+ /**
476+ * Find the storage path for the extension.
477+ * If no custom location was given
478+ *
479+ * @param context Extension context for the 'Storage Path'.
480+ * @returns
481+ */
472482export function getStoragePath ( context : ExtensionContext ) : string {
473- let storagePath : string | undefined = workspace . getConfiguration ( 'haskell' ) . get ( 'releasesDownloadStoragePath' ) ;
483+ let storagePath : string | undefined = haskellConfig . get ( 'releasesDownloadStoragePath' ) ;
474484
475485 if ( ! storagePath ) {
476486 storagePath = context . globalStorageUri . fsPath ;
0 commit comments