@@ -15,29 +15,34 @@ import { ToolConfig, Tool, initDefaultGHCup, GHCup, GHCupConfig } from './ghcup'
15
15
import { getHlsMetadata } from './metadata' ;
16
16
export { IEnvVars } ;
17
17
18
- type ManageHLS = 'GHCup' | 'PATH' ;
19
- let manageHLS = workspace . getConfiguration ( 'haskell' ) . get ( 'manageHLS' ) as ManageHLS ;
20
-
21
18
export type Context = {
22
19
manageHls : ManageHLS ;
23
20
storagePath : string ;
24
21
serverExecutable ?: HlsExecutable ;
25
22
logger : Logger ;
26
23
} ;
27
24
25
+ /**
26
+ * Global configuration for this extension.
27
+ */
28
+ const haskellConfig = workspace . getConfiguration ( 'haskell' ) ;
29
+
28
30
/**
29
31
* On Windows the executable needs to be stored somewhere with an .exe extension
30
32
*/
31
33
const exeExt = process . platform === 'win32' ? '.exe' : '' ;
32
34
35
+ type ManageHLS = 'GHCup' | 'PATH' ;
36
+ let manageHLS = haskellConfig . get ( 'manageHLS' ) as ManageHLS ;
37
+
33
38
/**
34
39
* Gets serverExecutablePath and fails if it's not set.
35
40
* @param logger Log progress.
36
41
* @param folder Workspace folder. Used for resolving variables in the `serverExecutablePath`.
37
42
* @returns Path to an HLS executable binary.
38
43
*/
39
44
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 ;
41
46
logger . info ( `Trying to find the server executable in: ${ rawExePath } ` ) ;
42
47
const resolvedExePath = resolvePathPlaceHolders ( rawExePath , folder ) ;
43
48
logger . log ( `Location after path variables substitution: ${ resolvedExePath } ` ) ;
@@ -114,7 +119,7 @@ export async function findHaskellLanguageServer(
114
119
) : Promise < HlsExecutable > {
115
120
logger . info ( 'Finding haskell-language-server' ) ;
116
121
117
- const hasConfigForExecutable = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
122
+ const hasConfigForExecutable = haskellConfig . get ( 'serverExecutablePath' ) as string ;
118
123
if ( hasConfigForExecutable ) {
119
124
const exe = findServerExecutable ( logger , folder ) ;
120
125
return {
@@ -152,9 +157,7 @@ export async function findHaskellLanguageServer(
152
157
let projectGhc : string | undefined | null ;
153
158
154
159
// 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 ;
158
161
if ( toolchainConfig ) {
159
162
latestHLS = toolchainConfig . get ( 'hls' ) ;
160
163
latestCabal = toolchainConfig . get ( 'cabal' ) ;
@@ -182,7 +185,7 @@ export async function findHaskellLanguageServer(
182
185
}
183
186
184
187
// download popups
185
- const promptBeforeDownloads = workspace . getConfiguration ( 'haskell' ) . get ( 'promptBeforeDownloads' ) as boolean ;
188
+ const promptBeforeDownloads = haskellConfig . get ( 'promptBeforeDownloads' ) as boolean ;
186
189
if ( promptBeforeDownloads ) {
187
190
const hlsInstalled = latestHLS ? await installationStatusOfGhcupTool ( ghcup , 'hls' , latestHLS ) : undefined ;
188
191
const cabalInstalled = latestCabal ? await installationStatusOfGhcupTool ( ghcup , 'cabal' , latestCabal ) : undefined ;
@@ -212,7 +215,7 @@ export async function findHaskellLanguageServer(
212
215
logger . info (
213
216
`User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
214
217
) ;
215
- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
218
+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
216
219
} else {
217
220
toInstall . forEach ( ( tool ) => {
218
221
if ( tool !== undefined && ! tool . installed ) {
@@ -285,7 +288,7 @@ export async function findHaskellLanguageServer(
285
288
logger . info (
286
289
`User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
287
290
) ;
288
- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
291
+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
289
292
} else {
290
293
toInstall . forEach ( ( tool ) => {
291
294
if ( ! tool . installed ) {
@@ -364,7 +367,7 @@ async function promptUserForManagingHls(context: ExtensionContext, manageHlsSett
364
367
) ;
365
368
howToManage = 'PATH' ;
366
369
}
367
- workspace . getConfiguration ( 'haskell' ) . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
370
+ haskellConfig . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
368
371
context . globalState . update ( 'pluginInitialized' , true ) ;
369
372
return howToManage ;
370
373
} else {
@@ -469,8 +472,15 @@ export async function getProjectGhcVersion(
469
472
) ;
470
473
}
471
474
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
+ */
472
482
export function getStoragePath ( context : ExtensionContext ) : string {
473
- let storagePath : string | undefined = workspace . getConfiguration ( 'haskell' ) . get ( 'releasesDownloadStoragePath' ) ;
483
+ let storagePath : string | undefined = haskellConfig . get ( 'releasesDownloadStoragePath' ) ;
474
484
475
485
if ( ! storagePath ) {
476
486
storagePath = context . globalStorageUri . fsPath ;
0 commit comments