Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions extensions/positron-reticulate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"lint": "eslint src --ext ts"
},
"contributes": {
"languageRuntimes": [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the reason the extension was eagerly activated during discoverAllRuntimes, but the languageId: "reticulate" anchor was a no-op (the actual runtime metadata registers under languageId: 'python').

{
"languageId": "reticulate"
}
],
"configuration": {
"type": "object",
"title": "%configurationTitle%",
Expand All @@ -41,10 +36,6 @@
}
}
},
"extensionDependencies": [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These forced the Python and R extensions to fully activate before reticulate's own activate() could even start, but that's not necessary.

"ms-python.python",
"positron.positron-r"
],
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.0",
Expand Down
32 changes: 18 additions & 14 deletions extensions/positron-reticulate/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {

private kernel: JupyterKernel | undefined;
public started = new Barrier();
private pythonSession: positron.LanguageRuntimeSession;
private pythonSession!: positron.LanguageRuntimeSession;

// To create a reticulate runtime session we need to first create a python
// runtime session using the exported interface from the positron-python
Expand Down Expand Up @@ -433,11 +433,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {
// Create the session itself.
const session = new ReticulateRuntimeSession(
rSession,
metadata,
sessionMetadata,
ReticulateRuntimeSessionType.Create,
progress
);
await session.initializePythonSession(metadata);

return session;
}
Expand All @@ -456,11 +456,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {
// Create the session itself.
const session = new ReticulateRuntimeSession(
rSession,
metadata,
sessionMetadata,
ReticulateRuntimeSessionType.Restore,
progress
);
await session.initializePythonSession(metadata);

return session;
}
Expand Down Expand Up @@ -620,15 +620,21 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {

constructor(
readonly rSession: positron.LanguageRuntimeSession,
runtimeMetadata: positron.LanguageRuntimeMetadata,
readonly sessionMetadata: positron.RuntimeSessionMetadata,
readonly sessionType: ReticulateRuntimeSessionType,
readonly progress: vscode.Progress<{ message?: string; increment?: number }>
) {
this.onDidReceiveRuntimeMessage = this._messageEmitter.event;
this.onDidChangeRuntimeState = this._stateEmitter.event;
this.onDidEndSession = this._exitEmitter.event;
this.onDidUpdateResourceUsage = this._resourceUsageEmitter.event;
}

private async initializePythonSession(runtimeMetadata: positron.LanguageRuntimeMetadata): Promise<void> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new, to split out the async work out of the ReticulateRuntimeSession constructor. The create and restore factories now await session.initializePythonSession(metadata) after construction. The restart() path's createPythonRuntimeSession call is also now awaited.

// When the kernelSpec is undefined, the PythonRuntimeSession
// will perform a restore session.
let kernelSpec: JupyterKernelSpec | undefined = undefined;
if (sessionType === ReticulateRuntimeSessionType.Create) {
if (this.sessionType === ReticulateRuntimeSessionType.Create) {
kernelSpec = {
'argv': [],
'display_name': "Reticulate Python Session", // eslint-disable-line
Expand All @@ -651,16 +657,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {
};
}

this.onDidReceiveRuntimeMessage = this._messageEmitter.event;
this.onDidChangeRuntimeState = this._stateEmitter.event;
this.onDidEndSession = this._exitEmitter.event;
this.onDidUpdateResourceUsage = this._resourceUsageEmitter.event;

this.progress.report({ increment: 10, message: vscode.l10n.t('Creating the Python session') });

this.pythonSession = this.createPythonRuntimeSession(
this.pythonSession = await this.createPythonRuntimeSession(
runtimeMetadata,
sessionMetadata,
this.sessionMetadata,
kernelSpec
);
}
Expand All @@ -669,11 +670,14 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {
return this.pythonSession.getDynState();
}

createPythonRuntimeSession(runtimeMetadata: positron.LanguageRuntimeMetadata, sessionMetadata: positron.RuntimeSessionMetadata, kernelSpec?: JupyterKernelSpec): positron.LanguageRuntimeSession {
async createPythonRuntimeSession(runtimeMetadata: positron.LanguageRuntimeMetadata, sessionMetadata: positron.RuntimeSessionMetadata, kernelSpec?: JupyterKernelSpec): Promise<positron.LanguageRuntimeSession> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're making this async and explicitly await-ing api.activate() when the Python extension isn't yet active (needed now because, without extensionDependencies, api.exports is only populated post-activation).

const api = vscode.extensions.getExtension('ms-python.python');
if (!api) {
throw new Error(vscode.l10n.t('Failed to find the Python extension API.'));
}
if (!api.isActive) {
await api.activate();
}

const pythonSession: positron.LanguageRuntimeSession = api.exports.positron.createPythonRuntimeSession(
runtimeMetadata,
Expand Down Expand Up @@ -875,7 +879,7 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession {
const metadata: positron.RuntimeSessionMetadata = { ...this.sessionMetadata, sessionId: `reticulate-python-${randomId}` };

// When the R session is ready, we can start a new Reticulate session.
this.pythonSession = this.createPythonRuntimeSession(
this.pythonSession = await this.createPythonRuntimeSession(
this.runtimeMetadata,
metadata,
kernelSpec
Expand Down
Loading