Skip to content

Commit

Permalink
Add a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalbel committed Sep 27, 2024
1 parent 5f3a1fa commit 4a96add
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
13 changes: 12 additions & 1 deletion extensions/positron-reticulate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@
{
"languageId": "reticulate"
}
]
],
"configuration": {
"type": "object",
"title": "%configurationTitle%",
"properties": {
"positron.reticulate.enabled": {
"type": "boolean",
"default": false,
"description": "%enabledDescription%"
}
}
}
},
"extensionDependencies": [
"ms-python.python",
Expand Down
4 changes: 3 additions & 1 deletion extensions/positron-reticulate/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"displayName": "Positron Reticulate",
"description": "Provides reticulate support for positron"
"description": "Provides reticulate support for positron",
"configurationTitle": "Reticulate settings",
"enabledDescription": "Enables reticulate console sessions"
}
29 changes: 27 additions & 2 deletions extensions/positron-reticulate/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,33 @@ export class ReticulateRuntimeManager implements positron.LanguageRuntimeManager
) {
this.onDidDiscoverRuntimeEmmiter = new vscode.EventEmitter<positron.LanguageRuntimeMetadata>;
this.onDidDiscoverRuntime = this.onDidDiscoverRuntimeEmmiter.event;
this.maybeRegisterReticulateRuntime();

vscode.workspace.onDidChangeConfiguration((event) => {
if (this._metadata) {
return; // If the runtime is already registered, don't do anything
}
if (event.affectsConfiguration('positron.reticulate.enabled') && this.featureEnabled()) {
this.maybeRegisterReticulateRuntime();
}
});

if (this.featureEnabled()) {
this.maybeRegisterReticulateRuntime();
}
}

featureEnabled(): boolean | undefined {
// If it's disabled, don't do any registration
const config = vscode.workspace.getConfiguration('positron.reticulate');
return config.get<boolean>('enabled');
}

async maybeRegisterReticulateRuntime() {

if (this._metadata) {
return; // No-op if session is already registered.
}

// Get a fixed list of all current runtimes.
const runtimes = await positron.runtime.getRegisteredRuntimes();

Expand Down Expand Up @@ -614,7 +637,9 @@ export class ReticulateProvider {
}

this._client = client;

// We'll force the registration when the user calls `reticulate::repl_python()`
// even if the flag is not enabled.
await this.manager.maybeRegisterReticulateRuntime();
await positron.runtime.selectLanguageRuntime('reticulate');

this.manager._session?.onDidEndSession(() => {
Expand Down

0 comments on commit 4a96add

Please sign in to comment.