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,33 @@ async function activateHie(context: ExtensionContext, document: TextDocument) {
69
68
}
70
69
71
70
try {
72
- const useCustomWrapper = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapper ;
71
+ const hieVariant = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieVariant ;
73
72
const hieExecutablePath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieExecutablePath ;
74
73
// Check if hie is installed.
75
- if ( ! await isHieInstalled ( ) && ! useCustomWrapper && hieExecutablePath === '' ) {
74
+ let exeName = 'hie' ;
75
+ switch ( hieVariant ) {
76
+ case 'haskell-ide-engine' :
77
+ break ;
78
+ case 'haskell-language-server' :
79
+ case 'ghcide' :
80
+ exeName = hieVariant ;
81
+ break ;
82
+ }
83
+ if ( ! await isHieInstalled ( exeName ) && hieExecutablePath === '' ) {
76
84
// TODO: Once haskell-ide-engine is on hackage/stackage, enable an option to install it via cabal/stack.
85
+ let hieProjectUrl = '/haskell/haskell-ide-engine' ;
86
+ switch ( hieVariant ) {
87
+ case 'haskell-ide-engine' :
88
+ break ;
89
+ case 'haskell-language-server' :
90
+ hieProjectUrl = '/haskell/haskell-language-server' ;
91
+ break ;
92
+ case 'ghcide' :
93
+ hieProjectUrl = '/digital-asset/ghcide' ;
94
+ break ;
95
+ }
77
96
const notInstalledMsg : string =
78
- 'hie executable missing, please make sure it is installed, see github.com/haskell/haskell-ide-engine .';
97
+ exeName + ' executable missing, please make sure it is installed, see https:// github.com' + hieProjectUrl + ' .';
79
98
const forceStart : string = 'Force Start' ;
80
99
window . showErrorMessage ( notInstalledMsg , forceStart ) . then ( option => {
81
100
if ( option === forceStart ) {
@@ -104,22 +123,13 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
104
123
docsBrowserRegistered = true ;
105
124
}
106
125
107
- const useCustomWrapper = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapper ;
126
+ const hieVariant = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieVariant ;
108
127
let hieExecutablePath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . hieExecutablePath ;
109
- let customWrapperPath = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . useCustomHieWrapperPath ;
110
- const noLspParam = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . noLspParam ;
111
128
const logLevel = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . trace . server ;
112
129
const logFile = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . logFile ;
113
130
114
131
// 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 !== '' ) {
132
+ if ( hieExecutablePath !== '' ) {
123
133
hieExecutablePath = hieExecutablePath
124
134
. replace ( '${workspaceFolder}' , folder . uri . path )
125
135
. replace ( '${workspaceRoot}' , folder . uri . path )
@@ -128,32 +138,39 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
128
138
. replace ( / ^ ~ / , os . homedir ) ;
129
139
}
130
140
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 !== '' ) {
141
+ // Set the executable, based on the settings.
142
+ let hieLaunchScript = 'hie' ; // should get set below
143
+ switch ( hieVariant ) {
144
+ case 'haskell-ide-engine' :
145
+ hieLaunchScript = 'hie-wrapper' ;
146
+ break ;
147
+ case 'haskell-language-server' :
148
+ hieLaunchScript = 'haskell-language-server-wrapper' ;
149
+ break ;
150
+ case 'ghcide' :
151
+ hieLaunchScript = 'ghcide' ;
152
+ break ;
153
+ }
154
+ if ( hieExecutablePath !== '' ) {
138
155
hieLaunchScript = hieExecutablePath ;
139
156
}
140
157
141
158
// If using a custom wrapper or specificed an executable path, the path is assumed to already
142
159
// be absolute.
143
- const serverPath =
144
- useCustomWrapper || hieExecutablePath ? hieLaunchScript : context . asAbsolutePath ( path . join ( '.' , hieLaunchScript ) ) ;
160
+ const serverPath = hieLaunchScript ;
145
161
146
- const runArgs : string [ ] = [ ] ;
147
- let debugArgs : string [ ] = [ ] ;
148
- if ( logLevel === 'messages' ) {
149
- debugArgs = [ '-d' ] ;
150
- }
151
- if ( ! noLspParam ) {
152
- runArgs . unshift ( '--lsp' ) ;
153
- debugArgs . unshift ( '--lsp' ) ;
154
- }
155
- if ( logFile !== '' ) {
156
- debugArgs = debugArgs . concat ( [ '-l' , logFile ] ) ;
162
+ const runArgs : string [ ] = [ '--lsp' ] ;
163
+ let debugArgs : string [ ] = [ '--lsp' ] ;
164
+
165
+ // ghcide does not accept -d and -l params
166
+ if ( hieVariant !== 'ghcide' ) {
167
+ if ( logLevel === 'messages' ) {
168
+ debugArgs = debugArgs . concat ( [ '-d' ] ) ;
169
+ }
170
+
171
+ if ( logFile !== '' ) {
172
+ debugArgs = debugArgs . concat ( [ '-l' , logFile ] ) ;
173
+ }
157
174
}
158
175
159
176
// If the extension is launched in debug mode then the debug server options are used,
@@ -166,6 +183,8 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
166
183
// Set a unique name per workspace folder (useful for multi-root workspaces).
167
184
const langName = 'Haskell HIE (' + folder . name + ')' ;
168
185
const outputChannel : OutputChannel = window . createOutputChannel ( langName ) ;
186
+ outputChannel . appendLine ( '[client] run command = "' + serverPath + ' ' + runArgs . join ( ' ' ) + '"' ) ;
187
+ outputChannel . appendLine ( '[client] debug command = "' + serverPath + ' ' + debugArgs . join ( ' ' ) + '"' ) ;
169
188
const clientOptions : LanguageClientOptions = {
170
189
// Use the document selector to only notify the LSP on files inside the folder
171
190
// path for the specific workspace.
@@ -242,9 +261,9 @@ export function deactivate(): Thenable<void> {
242
261
/*
243
262
* Check if HIE is installed.
244
263
*/
245
- async function isHieInstalled ( ) : Promise < boolean > {
264
+ async function isHieInstalled ( exeName : string ) : Promise < boolean > {
246
265
return new Promise < boolean > ( ( resolve , reject ) => {
247
- const cmd : string = process . platform === 'win32' ? 'where hie' : 'which hie' ;
266
+ const cmd : string = process . platform === 'win32' ? 'where ' + exeName : 'which ' + exeName ;
248
267
child_process . exec ( cmd , ( error , stdout , stderr ) => resolve ( ! error ) ) ;
249
268
} ) ;
250
269
}
0 commit comments