@@ -15,29 +15,34 @@ import { ToolConfig, Tool, initDefaultGHCup, GHCup } 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 } ` ) ;
@@ -113,7 +118,7 @@ export async function findHaskellLanguageServer(
113
118
) : Promise < HlsExecutable > {
114
119
logger . info ( 'Finding haskell-language-server' ) ;
115
120
116
- const hasConfigForExecutable = workspace . getConfiguration ( 'haskell' ) . get ( 'serverExecutablePath' ) as string ;
121
+ const hasConfigForExecutable = haskellConfig . get ( 'serverExecutablePath' ) as string ;
117
122
if ( hasConfigForExecutable ) {
118
123
const exe = findServerExecutable ( logger , folder ) ;
119
124
return {
@@ -151,9 +156,7 @@ export async function findHaskellLanguageServer(
151
156
let projectGhc : string | undefined | null ;
152
157
153
158
// 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 ;
157
160
if ( toolchainConfig ) {
158
161
latestHLS = toolchainConfig . get ( 'hls' ) ;
159
162
latestCabal = toolchainConfig . get ( 'cabal' ) ;
@@ -181,7 +184,7 @@ export async function findHaskellLanguageServer(
181
184
}
182
185
183
186
// download popups
184
- const promptBeforeDownloads = workspace . getConfiguration ( 'haskell' ) . get ( 'promptBeforeDownloads' ) as boolean ;
187
+ const promptBeforeDownloads = haskellConfig . get ( 'promptBeforeDownloads' ) as boolean ;
185
188
if ( promptBeforeDownloads ) {
186
189
const hlsInstalled = latestHLS ? await installationStatusOfGhcupTool ( ghcup , 'hls' , latestHLS ) : undefined ;
187
190
const cabalInstalled = latestCabal ? await installationStatusOfGhcupTool ( ghcup , 'cabal' , latestCabal ) : undefined ;
@@ -211,7 +214,7 @@ export async function findHaskellLanguageServer(
211
214
logger . info (
212
215
`User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
213
216
) ;
214
- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
217
+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
215
218
} else {
216
219
toInstall . forEach ( ( tool ) => {
217
220
if ( tool !== undefined && ! tool . installed ) {
@@ -284,7 +287,7 @@ export async function findHaskellLanguageServer(
284
287
logger . info (
285
288
`User accepted download for ${ toInstall . map ( ( t ) => t . nameWithVersion ) . join ( ', ' ) } and won't be asked again.` ,
286
289
) ;
287
- workspace . getConfiguration ( 'haskell' ) . update ( 'promptBeforeDownloads' , false ) ;
290
+ haskellConfig . update ( 'promptBeforeDownloads' , false ) ;
288
291
} else {
289
292
toInstall . forEach ( ( tool ) => {
290
293
if ( ! tool . installed ) {
@@ -363,7 +366,7 @@ async function promptUserForManagingHls(context: ExtensionContext, manageHlsSett
363
366
) ;
364
367
howToManage = 'PATH' ;
365
368
}
366
- workspace . getConfiguration ( 'haskell' ) . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
369
+ haskellConfig . update ( 'manageHLS' , howToManage , ConfigurationTarget . Global ) ;
367
370
context . globalState . update ( 'pluginInitialized' , true ) ;
368
371
return howToManage ;
369
372
} else {
@@ -468,8 +471,15 @@ export async function getProjectGhcVersion(
468
471
) ;
469
472
}
470
473
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
+ */
471
481
export function getStoragePath ( context : ExtensionContext ) : string {
472
- let storagePath : string | undefined = workspace . getConfiguration ( 'haskell' ) . get ( 'releasesDownloadStoragePath' ) ;
482
+ let storagePath : string | undefined = haskellConfig . get ( 'releasesDownloadStoragePath' ) ;
473
483
474
484
if ( ! storagePath ) {
475
485
storagePath = context . globalStorageUri . fsPath ;
0 commit comments