@@ -9,7 +9,14 @@ import {
99import { logger } from './extension' ;
1010import { logErrorAndThrow , setTerminalEnvironment } from './helpers' ;
1111
12- class AdaLanguageClient extends LanguageClient {
12+ export class AdaLanguageClient extends LanguageClient {
13+ /**
14+ * Used to store the client's process environment.
15+ * Changes are taken into account when calling the
16+ * {@link vscode.LanguageClient.restart} function.
17+ */
18+ public serverEnv : NodeJS . ProcessEnv = { } ;
19+
1320 /**
1421 * Override this function to avoid displaying popup notifications on LSP errors when
1522 * the 'showNotificationsOnErrors' setting is disabled.
@@ -29,14 +36,29 @@ class AdaLanguageClient extends LanguageClient {
2936
3037 return super . handleFailedRequest ( type , token , error , defaultValue , showNotification ) ;
3138 }
39+
40+ /**
41+ * Override this function to update the client's process environment according to
42+ * VS Code settings before restarting it.
43+ */
44+ override restart ( ) : Promise < void > {
45+ // Update the process environment before restarting the language servers, so
46+ // that potential changes in VS Code settings related to the environment are
47+ // taken into account.
48+ setTerminalEnvironment ( this . serverEnv ) ;
49+
50+ // Restart the server
51+ logger . info ( 'Restarting language server: ' + this . name ) ;
52+ return super . restart ( ) ;
53+ }
3254}
3355export function createClient (
3456 context : vscode . ExtensionContext ,
3557 id : string ,
3658 name : string ,
3759 extra : string [ ] ,
3860 pattern : string ,
39- ) {
61+ ) : AdaLanguageClient {
4062 let serverExecPath : string ;
4163
4264 // If the ALS environment variable is specified, use it as the path of the
@@ -91,14 +113,6 @@ export function createClient(
91113 // Set custom environment
92114 setTerminalEnvironment ( serverEnv ) ;
93115
94- logger . debug ( `Environment for ${ name } :` ) ;
95- for ( const key in serverEnv ) {
96- const value = serverEnv [ key ] ;
97- if ( value ) {
98- logger . debug ( `${ key } =${ value } ` ) ;
99- }
100- }
101-
102116 // Options to control the server
103117 const serverOptions : ServerOptions = {
104118 run : { command : serverExecPath , args : extra , options : { env : serverEnv } } ,
@@ -119,5 +133,7 @@ export function createClient(
119133 initializationOptions : ( ) => ( { ada : vscode . workspace . getConfiguration ( 'ada' ) } ) ,
120134 } ;
121135 // Create the language client
122- return new AdaLanguageClient ( id , name , serverOptions , clientOptions ) ;
136+ const client = new AdaLanguageClient ( id , name , serverOptions , clientOptions ) ;
137+ client . serverEnv = serverEnv ;
138+ return client ;
123139}
0 commit comments