@@ -14,7 +14,7 @@ import { Disposable, DocumentFilter, LanguageClientOptions } from 'vscode-langua
1414
1515import { compare } from 'semver' ;
1616import { EXTENSION_ROOT_DIR , PYTHON_LANGUAGE } from '../../common/constants' ;
17- import { IConfigurationService , IInstaller , InstallerResponse , Product , Resource } from '../../common/types' ;
17+ import { IConfigurationService , IDisposableRegistry , IInstaller , InstallerResponse , Product , Resource } from '../../common/types' ;
1818import { InstallOptions } from '../../common/installer/types' ;
1919import { IInterpreterService } from '../../interpreter/contracts' ;
2020import { IServiceContainer } from '../../ioc/types' ;
@@ -37,7 +37,7 @@ const base64EncodedIconSvg = fs.readFileSync(path.join(EXTENSION_ROOT_DIR, 'reso
3737 */
3838export class PositronJediLanguageServerProxy implements ILanguageServerProxy {
3939
40- private readonly disposables : Disposable [ ] = [ ] ;
40+ private readonly disposables : IDisposableRegistry ;
4141
4242 private extensionVersion : string | undefined ;
4343
@@ -47,6 +47,8 @@ export class PositronJediLanguageServerProxy implements ILanguageServerProxy {
4747 // which has issues waiting for the outcome of the install.
4848 private readonly installOptions : InstallOptions = { installAsProcess : true } ;
4949
50+ private registered = false ;
51+
5052 constructor (
5153 private readonly serviceContainer : IServiceContainer ,
5254 private readonly interpreterService : IInterpreterService ,
@@ -61,6 +63,7 @@ export class PositronJediLanguageServerProxy implements ILanguageServerProxy {
6163 traceVerbose ( "Unable to read package.json to determine our extension version" , e ) ;
6264 }
6365
66+ this . disposables = serviceContainer . get < IDisposableRegistry > ( IDisposableRegistry ) ;
6467 this . installer = this . serviceContainer . get < IInstaller > ( IInstaller ) ;
6568 }
6669
@@ -72,6 +75,17 @@ export class PositronJediLanguageServerProxy implements ILanguageServerProxy {
7275 options : LanguageClientOptions ,
7376 ) : Promise < void > {
7477
78+ // Positron manages the language server lifecycle instead of the extension. We instead use
79+ // this method to register the language runtime with Positron. Keeping the registration logic
80+ // in `ILanguageServerProxy` lets us benefit from the existing setup of `resource` (the
81+ // workspace folder URI), `interpreter`, and language server `options`, as well as disposing.
82+
83+ // Only register language runtimes with Positron once.
84+ if ( this . registered ) {
85+ return ;
86+ }
87+ this . registered = true ;
88+
7589 // Determine if our Jupyter Adapter extension is installed
7690 const ext = vscode . extensions . getExtension ( 'vscode.jupyter-adapter' ) ;
7791 if ( ! ext ) {
@@ -108,16 +122,12 @@ export class PositronJediLanguageServerProxy implements ILanguageServerProxy {
108122 }
109123
110124 public async stop ( ) : Promise < void > {
111-
112- // Dispose of any runtimes and related resources
113- while ( this . disposables . length > 0 ) {
114- const r = this . disposables . shift ( ) ! ;
115- r . dispose ( ) ;
116- }
125+ // Do nothing. Let Positron manage the language server lifecycle.
117126 }
118127
119128 public dispose ( ) : void {
120- this . stop ( ) . ignoreErrors ( ) ;
129+ // Do nothing. Let Positron manage the language server lifecycle, and this is called on
130+ // stopLanguageServer.
121131 }
122132
123133 /**
0 commit comments