@@ -58,12 +58,8 @@ async function activateHie(context: ExtensionContext, document: TextDocument) {
58
58
59
59
const uri = document . uri ;
60
60
const folder = workspace . getWorkspaceFolder ( uri ) ;
61
- // Don't handle files outside of a folder.
62
- if ( ! folder ) {
63
- return ;
64
- }
65
- // If the client already has an LSP server, then don't start a new one.
66
- if ( clients . has ( folder . uri . toString ( ) ) ) {
61
+ // If the client already has an LSP server for this folder, then don't start a new one.
62
+ if ( folder && clients . has ( folder . uri . toString ( ) ) ) {
67
63
return ;
68
64
}
69
65
@@ -98,18 +94,18 @@ async function activateHie(context: ExtensionContext, document: TextDocument) {
98
94
const forceStart : string = 'Force Start' ;
99
95
window . showErrorMessage ( notInstalledMsg , forceStart ) . then ( option => {
100
96
if ( option === forceStart ) {
101
- activateHieNoCheck ( context , folder , uri ) ;
97
+ activateHieNoCheck ( context , uri , folder ) ;
102
98
}
103
99
} ) ;
104
100
} else {
105
- activateHieNoCheck ( context , folder , uri ) ;
101
+ activateHieNoCheck ( context , uri , folder ) ;
106
102
}
107
103
} catch ( e ) {
108
104
console . error ( e ) ;
109
105
}
110
106
}
111
107
112
- function activateHieNoCheck ( context : ExtensionContext , folder : WorkspaceFolder , uri : Uri ) {
108
+ function activateHieNoCheck ( context : ExtensionContext , uri : Uri , folder ?: WorkspaceFolder ) {
113
109
// Stop right here, if HIE is disabled in the resource/workspace folder.
114
110
const enableHIE = workspace . getConfiguration ( 'languageServerHaskell' , uri ) . enableHIE ;
115
111
if ( ! enableHIE ) {
@@ -131,11 +127,14 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
131
127
// Substitute path variables with their corresponding locations.
132
128
if ( hieExecutablePath !== '' ) {
133
129
hieExecutablePath = hieExecutablePath
134
- . replace ( '${workspaceFolder}' , folder . uri . path )
135
- . replace ( '${workspaceRoot}' , folder . uri . path )
136
130
. replace ( '${HOME}' , os . homedir )
137
131
. replace ( '${home}' , os . homedir )
138
132
. replace ( / ^ ~ / , os . homedir ) ;
133
+ if ( folder ) {
134
+ hieExecutablePath = hieExecutablePath
135
+ . replace ( '${workspaceFolder}' , folder . uri . path )
136
+ . replace ( '${workspaceRoot}' , folder . uri . path ) ;
137
+ }
139
138
}
140
139
141
140
// Set the executable, based on the settings.
@@ -181,16 +180,17 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
181
180
} ;
182
181
183
182
// Set a unique name per workspace folder (useful for multi-root workspaces).
184
- const langName = 'Haskell HIE (' + folder . name + ')' ;
183
+ const langName = 'Haskell' + ( folder ? ` ( ${ folder . name } )` : '' ) ;
185
184
const outputChannel : OutputChannel = window . createOutputChannel ( langName ) ;
186
185
outputChannel . appendLine ( '[client] run command = "' + serverPath + ' ' + runArgs . join ( ' ' ) + '"' ) ;
187
186
outputChannel . appendLine ( '[client] debug command = "' + serverPath + ' ' + debugArgs . join ( ' ' ) + '"' ) ;
187
+ const pat = folder ? `${ folder . uri . fsPath } /**/*` : '**/*' ;
188
188
const clientOptions : LanguageClientOptions = {
189
189
// Use the document selector to only notify the LSP on files inside the folder
190
190
// path for the specific workspace.
191
191
documentSelector : [
192
- { scheme : 'file' , language : 'haskell' , pattern : ` ${ folder . uri . fsPath } /**/*` } ,
193
- { scheme : 'file' , language : 'literate haskell' , pattern : ` ${ folder . uri . fsPath } /**/*` }
192
+ { scheme : 'file' , language : 'haskell' , pattern : pat } ,
193
+ { scheme : 'file' , language : 'literate haskell' , pattern : pat }
194
194
] ,
195
195
synchronize : {
196
196
// Synchronize the setting section 'languageServerHaskell' to the server.
@@ -238,13 +238,15 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
238
238
239
239
// If the client already has an LSP server, then don't start a new one.
240
240
// We check this again, as there may be multiple parallel requests.
241
- if ( clients . has ( folder . uri . toString ( ) ) ) {
241
+ if ( folder && clients . has ( folder . uri . toString ( ) ) ) {
242
242
return ;
243
243
}
244
244
245
245
// Finally start the client and add it to the list of clients.
246
246
langClient . start ( ) ;
247
- clients . set ( folder . uri . toString ( ) , langClient ) ;
247
+ if ( folder ) {
248
+ clients . set ( folder . uri . toString ( ) , langClient ) ;
249
+ }
248
250
}
249
251
250
252
/*
0 commit comments