Skip to content

Commit bf3ba30

Browse files
seeMwesm
authored andcommitted
Merged PR posit-dev/positron-python#112: fix runtime integration
Merge pull request #112 from posit-dev/fix-runtime-integration fix runtime integration -------------------- Commit message for posit-dev/positron-python@d03ba77: fix runtime integration Only register runtimes once. Use `IDisposableRegistry` instead of `ILanguageServerProxy.dispose` to dispose the runtime to delay disposing instead of disposing when `vscode-python` tries to stop the language server. Fixes #658. Authored-by: Wasim Lorgat <[email protected]> Signed-off-by: Wasim Lorgat <[email protected]>
1 parent 6dcba32 commit bf3ba30

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

extensions/positron-python/src/client/activation/jedi/positronLanguageRuntimes.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Disposable, DocumentFilter, LanguageClientOptions } from 'vscode-langua
1414

1515
import { compare } from 'semver';
1616
import { 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';
1818
import { InstallOptions } from '../../common/installer/types';
1919
import { IInterpreterService } from '../../interpreter/contracts';
2020
import { IServiceContainer } from '../../ioc/types';
@@ -37,7 +37,7 @@ const base64EncodedIconSvg = fs.readFileSync(path.join(EXTENSION_ROOT_DIR, 'reso
3737
*/
3838
export 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

Comments
 (0)