@@ -7,16 +7,9 @@ import * as path from 'path';
7
7
import { match } from 'ts-pattern' ;
8
8
import * as url from 'url' ;
9
9
import { promisify } from 'util' ;
10
- import {
11
- ConfigurationTarget ,
12
- ExtensionContext ,
13
- ProgressLocation ,
14
- Uri ,
15
- window ,
16
- workspace ,
17
- WorkspaceFolder ,
18
- } from 'vscode' ;
10
+ import { ConfigurationTarget , ExtensionContext , ProgressLocation , window , workspace , WorkspaceFolder } from 'vscode' ;
19
11
import { Logger } from 'vscode-languageclient' ;
12
+ import { HlsError , MissingToolError , NoMatchingHls } from './errors' ;
20
13
import {
21
14
addPathToProcessPath ,
22
15
executableExists ,
@@ -39,52 +32,6 @@ let manageHLS = workspace.getConfiguration('haskell').get('manageHLS') as Manage
39
32
// On Windows the executable needs to be stored somewhere with an .exe extension
40
33
const exeExt = process . platform === 'win32' ? '.exe' : '' ;
41
34
42
- export class MissingToolError extends Error {
43
- public readonly tool : string ;
44
- constructor ( tool : string ) {
45
- let prettyTool : string ;
46
- switch ( tool . toLowerCase ( ) ) {
47
- case 'stack' :
48
- prettyTool = 'Stack' ;
49
- break ;
50
- case 'cabal' :
51
- prettyTool = 'Cabal' ;
52
- break ;
53
- case 'ghc' :
54
- prettyTool = 'GHC' ;
55
- break ;
56
- case 'ghcup' :
57
- prettyTool = 'GHCup' ;
58
- break ;
59
- case 'haskell-language-server' :
60
- prettyTool = 'HLS' ;
61
- break ;
62
- case 'hls' :
63
- prettyTool = 'HLS' ;
64
- break ;
65
- default :
66
- prettyTool = tool ;
67
- break ;
68
- }
69
- super ( `Project requires ${ prettyTool } but it isn't installed` ) ;
70
- this . tool = prettyTool ;
71
- }
72
-
73
- public installLink ( ) : Uri | null {
74
- switch ( this . tool ) {
75
- case 'Stack' :
76
- return Uri . parse ( 'https://docs.haskellstack.org/en/stable/install_and_upgrade/' ) ;
77
- case 'GHCup' :
78
- case 'Cabal' :
79
- case 'HLS' :
80
- case 'GHC' :
81
- return Uri . parse ( 'https://www.haskell.org/ghcup/' ) ;
82
- default :
83
- return null ;
84
- }
85
- }
86
- }
87
-
88
35
/**
89
36
* Call a process asynchronously.
90
37
* While doing so, update the windows with progress information.
@@ -489,7 +436,7 @@ async function callGHCup(
489
436
callback
490
437
) ;
491
438
} else {
492
- throw new Error ( `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ) ;
439
+ throw new HlsError ( `Internal error: tried to call ghcup while haskell.manageHLS is set to ${ manageHLS } . Aborting!` ) ;
493
440
}
494
441
}
495
442
@@ -498,7 +445,7 @@ async function getLatestProjectHLS(
498
445
logger : Logger ,
499
446
workingDir : string ,
500
447
toolchainBindir : string
501
- ) : Promise < [ string , string | null ] > {
448
+ ) : Promise < [ string , string ] > {
502
449
// get project GHC version, but fallback to system ghc if necessary.
503
450
const projectGhc = toolchainBindir
504
451
? await getProjectGHCVersion ( toolchainBindir , workingDir , logger ) . catch ( async ( e ) => {
@@ -509,7 +456,6 @@ async function getLatestProjectHLS(
509
456
return await callAsync ( `ghc${ exeExt } ` , [ '--numeric-version' ] , logger , undefined , undefined , false ) ;
510
457
} )
511
458
: await callAsync ( `ghc${ exeExt } ` , [ '--numeric-version' ] , logger , undefined , undefined , false ) ;
512
- const noMatchingHLS = `No HLS version was found for supporting GHC ${ projectGhc } .` ;
513
459
514
460
// first we get supported GHC versions from available HLS bindists (whether installed or not)
515
461
const metadataMap = ( await getHLSesfromMetadata ( context , logger ) ) || new Map < string , string [ ] > ( ) ;
@@ -526,7 +472,7 @@ async function getLatestProjectHLS(
526
472
. pop ( ) ;
527
473
528
474
if ( ! latest ) {
529
- throw new Error ( noMatchingHLS ) ;
475
+ throw new NoMatchingHls ( projectGhc ) ;
530
476
} else {
531
477
return [ latest [ 0 ] , projectGhc ] ;
532
478
}
0 commit comments