1
1
'use strict' ;
2
2
import * as child_process from 'child_process' ;
3
3
import * as os from 'os' ;
4
- import * as path from 'path' ;
5
4
import {
6
5
commands ,
7
6
ExtensionContext ,
@@ -69,13 +68,13 @@ async function activateHie(context: ExtensionContext, document: TextDocument) {
69
68
}
70
69
71
70
try {
72
- const useCustomWrapper = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapper ;
73
71
const hieExecutablePath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieExecutablePath ;
74
72
// Check if hie is installed.
75
- if ( ! await isHieInstalled ( ) && ! useCustomWrapper && hieExecutablePath === '' ) {
73
+ const exeName = 'hie' ;
74
+ if ( ! await isHieInstalled ( exeName ) && hieExecutablePath === '' ) {
76
75
// TODO: Once haskell-ide-engine is on hackage/stackage, enable an option to install it via cabal/stack.
77
76
const notInstalledMsg : string =
78
- 'hie executable missing, please make sure it is installed, see github.com/haskell/haskell-ide-engine.';
77
+ exeName + ' executable missing, please make sure it is installed, see github.com/haskell/haskell-ide-engine.';
79
78
const forceStart : string = 'Force Start' ;
80
79
window . showErrorMessage ( notInstalledMsg , forceStart ) . then ( option => {
81
80
if ( option === forceStart ) {
@@ -104,22 +103,13 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
104
103
docsBrowserRegistered = true ;
105
104
}
106
105
107
- const useCustomWrapper = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapper ;
106
+ const hieVariant = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieVariant ;
108
107
let hieExecutablePath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieExecutablePath ;
109
- let customWrapperPath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapperPath ;
110
- const noLspParam = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . noLspParam ;
111
108
const logLevel = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . trace . server ;
112
109
const logFile = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . logFile ;
113
110
114
111
// Substitute path variables with their corresponding locations.
115
- if ( useCustomWrapper ) {
116
- customWrapperPath = customWrapperPath
117
- . replace ( '${workspaceFolder}' , folder . uri . path )
118
- . replace ( '${workspaceRoot}' , folder . uri . path )
119
- . replace ( '${HOME}' , os . homedir )
120
- . replace ( '${home}' , os . homedir )
121
- . replace ( / ^ ~ / , os . homedir ) ;
122
- } else if ( hieExecutablePath !== '' ) {
112
+ if ( hieExecutablePath !== '' ) {
123
113
hieExecutablePath = hieExecutablePath
124
114
. replace ( '${workspaceFolder}' , folder . uri . path )
125
115
. replace ( '${workspaceRoot}' , folder . uri . path )
@@ -128,30 +118,33 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
128
118
. replace ( / ^ ~ / , os . homedir ) ;
129
119
}
130
120
131
- // Set the executable, based on the settings. The order goes: First
132
- // check useCustomWrapper, then check hieExecutablePath, else retain
133
- // original path.
134
- let hieLaunchScript = process . platform === 'win32' ? 'hie-vscode.bat' : 'hie-vscode.sh' ;
135
- if ( useCustomWrapper ) {
136
- hieLaunchScript = customWrapperPath ;
137
- } else if ( hieExecutablePath !== '' ) {
121
+ // Set the executable, based on the settings.
122
+ let hieLaunchScript = 'hie' ; // should get set below
123
+ switch ( hieVariant ) {
124
+ case 'haskell-ide-engine' :
125
+ hieLaunchScript = 'hie-wrapper' ;
126
+ break ;
127
+ case 'haskell-language-server' :
128
+ hieLaunchScript = 'haskell-language-server-wrapper' ;
129
+ break ;
130
+ case 'ghcide' :
131
+ hieLaunchScript = 'ghcide' ;
132
+ break ;
133
+ }
134
+ if ( hieExecutablePath !== '' ) {
138
135
hieLaunchScript = hieExecutablePath ;
139
136
}
140
137
141
138
// If using a custom wrapper or specificed an executable path, the path is assumed to already
142
139
// be absolute.
143
- const serverPath =
144
- useCustomWrapper || hieExecutablePath ? hieLaunchScript : context . asAbsolutePath ( path . join ( '.' , hieLaunchScript ) ) ;
140
+ const serverPath = hieLaunchScript ;
145
141
146
- const runArgs : string [ ] = [ ] ;
147
- let debugArgs : string [ ] = [ ] ;
142
+ const runArgs : string [ ] = [ '--lsp' ] ;
143
+ let debugArgs : string [ ] = [ '--lsp' ] ;
148
144
if ( logLevel === 'messages' ) {
149
145
debugArgs = [ '-d' ] ;
150
146
}
151
- if ( ! noLspParam ) {
152
- runArgs . unshift ( '--lsp' ) ;
153
- debugArgs . unshift ( '--lsp' ) ;
154
- }
147
+
155
148
if ( logFile !== '' ) {
156
149
debugArgs = debugArgs . concat ( [ '-l' , logFile ] ) ;
157
150
}
@@ -242,9 +235,9 @@ export function deactivate(): Thenable<void> {
242
235
/*
243
236
* Check if HIE is installed.
244
237
*/
245
- async function isHieInstalled ( ) : Promise < boolean > {
238
+ async function isHieInstalled ( exeName : string ) : Promise < boolean > {
246
239
return new Promise < boolean > ( ( resolve , reject ) => {
247
- const cmd : string = process . platform === 'win32' ? 'where hie' : 'which hie' ;
240
+ const cmd : string = process . platform === 'win32' ? 'where ' + exeName : 'which ' + exeName ;
248
241
child_process . exec ( cmd , ( error , stdout , stderr ) => resolve ( ! error ) ) ;
249
242
} ) ;
250
243
}
0 commit comments