@@ -95,36 +95,42 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy {
9595 this . cancellationStrategy = new FileBasedCancellationStrategy ( ) ;
9696 options . connectionOptions = { cancellationStrategy : this . cancellationStrategy } ;
9797
98- this . languageClient = await this . factory . createLanguageClient ( resource , interpreter , options ) ;
99- this . registerHandlers ( resource ) ;
98+ const client = await this . factory . createLanguageClient ( resource , interpreter , options ) ;
99+ this . registerHandlers ( client , resource ) ;
100100
101101 this . disposables . push (
102102 this . workspace . onDidGrantWorkspaceTrust ( ( ) => {
103- this . languageClient ! . sendNotification ( 'python/workspaceTrusted' , { isTrusted : true } ) ;
103+ client . sendNotification ( 'python/workspaceTrusted' , { isTrusted : true } ) ;
104104 } ) ,
105105 ) ;
106106
107- await this . languageClient . start ( ) ;
107+ await client . start ( ) ;
108+
109+ this . languageClient = client ;
108110 }
109111
110112 @traceDecoratorVerbose ( 'Disposing language server' )
111113 public async stop ( ) : Promise < void > {
114+ while ( this . disposables . length > 0 ) {
115+ const d = this . disposables . shift ( ) ! ;
116+ d . dispose ( ) ;
117+ }
118+
112119 if ( this . languageClient ) {
120+ const client = this . languageClient ;
121+ this . languageClient = undefined ;
122+
113123 try {
114- await this . languageClient . stop ( ) ;
124+ await client . stop ( ) ;
115125 } catch ( ex ) {
116126 traceError ( 'Stopping language client failed' , ex ) ;
117127 }
118- this . languageClient = undefined ;
119128 }
129+
120130 if ( this . cancellationStrategy ) {
121131 this . cancellationStrategy . dispose ( ) ;
122132 this . cancellationStrategy = undefined ;
123133 }
124- while ( this . disposables . length > 0 ) {
125- const d = this . disposables . shift ( ) ! ;
126- d . dispose ( ) ;
127- }
128134 }
129135
130136 // eslint-disable-next-line class-methods-use-this
@@ -139,8 +145,8 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy {
139145 undefined ,
140146 NodeLanguageServerProxy . versionTelemetryProps ,
141147 )
142- private registerHandlers ( _resource : Resource ) {
143- const progressReporting = new ProgressReporting ( this . languageClient ! ) ;
148+ private registerHandlers ( client : LanguageClient , _resource : Resource ) {
149+ const progressReporting = new ProgressReporting ( client ) ;
144150 this . disposables . push ( progressReporting ) ;
145151
146152 this . disposables . push (
@@ -149,28 +155,28 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy {
149155 // the workspace configurations (to then pick up pythonPath set in the middleware).
150156 // This is needed as interpreter changes via the interpreter path service happen
151157 // outside of VS Code's settings (which would mean VS Code sends the config updates itself).
152- this . languageClient ! . sendNotification ( DidChangeConfigurationNotification . type , {
158+ client . sendNotification ( DidChangeConfigurationNotification . type , {
153159 settings : null ,
154160 } ) ;
155161 } ) ,
156162 ) ;
157163 this . disposables . push (
158164 this . environmentService . onDidEnvironmentVariablesChange ( ( ) => {
159- this . languageClient ! . sendNotification ( DidChangeConfigurationNotification . type , {
165+ client . sendNotification ( DidChangeConfigurationNotification . type , {
160166 settings : null ,
161167 } ) ;
162168 } ) ,
163169 ) ;
164170
165- this . languageClient ! . onRequest (
171+ client . onRequest (
166172 InExperiment . Method ,
167173 async ( params : InExperiment . IRequest ) : Promise < InExperiment . IResponse > => {
168174 const inExperiment = await this . experimentService . inExperiment ( params . experimentName ) ;
169175 return { inExperiment } ;
170176 } ,
171177 ) ;
172178
173- this . languageClient ! . onRequest (
179+ client . onRequest (
174180 GetExperimentValue . Method ,
175181 async < T extends boolean | number | string > (
176182 params : GetExperimentValue . IRequest ,
@@ -181,7 +187,7 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy {
181187 ) ;
182188
183189 this . disposables . push (
184- this . languageClient ! . onRequest ( 'python/isTrustedWorkspace' , async ( ) => ( {
190+ client . onRequest ( 'python/isTrustedWorkspace' , async ( ) => ( {
185191 isTrusted : this . workspace . isTrusted ,
186192 } ) ) ,
187193 ) ;
0 commit comments