Skip to content

Commit 5f45c99

Browse files
authored
Add new command to kick off (refresh) interpreter discovery (#7762)
Addresses #4269 This PR adds a new command `workbench.action.language.runtime.discoverAllRuntimes` to kick off runtime discovery. I just have it accessible from the command palette (no keybindings, no UI), which is a good option for now, I think. I put this in with other commands in `languageRuntimeActions.ts`, although I do want to highlight that all the other commands in there apply to a _single_ interpreter, not to all of them as a whole. This command can only add new interpreters. If the user _removes_ an interpreter while Positron is running, this new command does not get rid of it because the runtime is still registered; discovery can only add runtimes. We could totally clear all the registered runtimes but that seems pretty destructive, and removing runtimes hasn't been a big concern so far. Thoughts? ### Release Notes #### New Features - Adds new command "Interpreter: Discover All Interpreters" to kick off interpreter discovery, for example if you have just made a new Python environment that Positron doesn't know about yet #### Bug Fixes - N/A ### QA Notes I think the easiest way to see if this is doing what we expect is to watch the output channel for either the R or Python Language Pack and execute the command. You'll see all the logging for interpreter discovery go by each time you do so. Alternatively, you could: - Look at all your interpreter options in Positron - Add a new one via the regular terminal (for example, a new rig version) - Look at all your interpreter choices and see that your new one is not there yet - Execute the command - Look at all your interpreter choices and see that now the new one is there --------- Signed-off-by: Julia Silge <[email protected]>
1 parent deabe86 commit 5f45c99

File tree

6 files changed

+89
-3
lines changed

6 files changed

+89
-3
lines changed

extensions/positron-python/src/client/positron/discoverer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function* pythonRuntimeDiscoverer(
4848
traceInfo(`pythonRuntimeDiscoverer: recommended interpreter: ${recommendedInterpreter?.path}`);
4949

5050
// Discover Python interpreters
51+
await interpreterService.triggerRefresh().ignoreErrors();
5152
let interpreters = interpreterService.getInterpreters();
5253

5354
traceInfo(`pythonRuntimeDiscoverer: discovered ${interpreters.length} Python interpreters`);

src/vs/workbench/contrib/languageRuntime/browser/languageRuntimeActions.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export const LANGUAGE_RUNTIME_RESTART_ACTIVE_SESSION_ID = 'workbench.action.lang
4444
export const LANGUAGE_RUNTIME_RENAME_SESSION_ID = 'workbench.action.language.runtime.renameSession';
4545
export const LANGUAGE_RUNTIME_RENAME_ACTIVE_SESSION_ID = 'workbench.action.language.runtime.renameActiveSession';
4646
export const LANGUAGE_RUNTIME_DUPLICATE_ACTIVE_SESSION_ID = 'workbench.action.language.runtime.duplicateActiveSession';
47-
4847
export const LANGUAGE_RUNTIME_SELECT_RUNTIME_ID = 'workbench.action.languageRuntime.selectRuntime';
48+
export const LANGUAGE_RUNTIME_DISCOVER_RUNTIMES_ID = 'workbench.action.language.runtime.discoverAllRuntimes';
4949

5050
/**
5151
* Helper function that askses the user to select a language from the list of registered language
@@ -967,6 +967,29 @@ export function registerLanguageRuntimeActions() {
967967
}
968968
});
969969

970+
registerAction2(class extends Action2 {
971+
/**
972+
* Constructor.
973+
*/
974+
constructor() {
975+
super({
976+
id: LANGUAGE_RUNTIME_DISCOVER_RUNTIMES_ID,
977+
title: nls.localize2('workbench.action.language.runtime.discoverAllRuntimes', "Discover All Interpreters"),
978+
f1: true,
979+
category
980+
});
981+
}
982+
983+
async run(accessor: ServicesAccessor) {
984+
// Access service.
985+
const runtimeStartupService = accessor.get(IRuntimeStartupService);
986+
987+
// Kick off discovery.
988+
runtimeStartupService.rediscoverAllRuntimes();
989+
}
990+
});
991+
992+
970993
/**
971994
* Arguments passed to the Execute Code actions.
972995
*/

src/vs/workbench/services/positronHistory/test/common/executionHistoryService.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ class TestRuntimeStartupService implements IRuntimeStartupService {
319319
// No-op in test implementation
320320
}
321321

322+
public async rediscoverAllRuntimes() {
323+
// No-op in test implementation
324+
}
325+
322326
registerRuntimeManager(_manager: IRuntimeManager): IDisposable {
323327
return Disposable.None;
324328
}

src/vs/workbench/services/runtimeStartup/common/runtimeStartup.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,52 @@ export class RuntimeStartupService extends Disposable implements IRuntimeStartup
637637
};
638638
}
639639

640+
/**
641+
* Kicks off a refresh of runtime discovery, after initial discovery.
642+
*/
643+
public async rediscoverAllRuntimes(): Promise<void> {
644+
645+
// If we haven't completed discovery once already, don't do anything.
646+
if (this._startupPhase !== RuntimeStartupPhase.Complete) {
647+
this._logService.warn('[Runtime startup] Runtime discovery refresh called before initial discovery is complete.');
648+
return;
649+
}
650+
651+
// Set up event to notify when runtimes are added.
652+
const oldRuntimes = this._languageRuntimeService.registeredRuntimes;
653+
this._register(
654+
this._languageRuntimeService.onDidChangeRuntimeStartupPhase(
655+
(phase) => {
656+
if (phase === RuntimeStartupPhase.Complete) {
657+
const newRuntimes = this._languageRuntimeService.registeredRuntimes;
658+
const addedRuntimes = newRuntimes.filter(newRuntime => {
659+
return !oldRuntimes.some(oldRuntime => {
660+
return oldRuntime.runtimeId === newRuntime.runtimeId;
661+
});
662+
});
663+
664+
// If any runtimes were added, show a notification.
665+
if (addedRuntimes.length > 0) {
666+
this._notificationService.info(nls.localize('positron.runtimeStartupService.runtimesAddedMessage',
667+
"Found {0} new interpreter{1}: {2}.",
668+
addedRuntimes.length,
669+
addedRuntimes.length > 1 ? 's' : '',
670+
addedRuntimes.map(runtime => { return runtime.runtimeName; }).join(', ')));
671+
}
672+
}
673+
}
674+
)
675+
);
676+
677+
this._logService.debug('[Runtime startup] Refreshing runtime discovery.');
678+
this._discoveryCompleteByExtHostId.forEach((_, extHostId, m) => {
679+
m.set(extHostId, false);
680+
});
681+
682+
this.discoverAllRuntimes();
683+
684+
}
685+
640686
/**
641687
* Runs as an event handler when the active runtime changes.
642688
*
@@ -693,7 +739,7 @@ export class RuntimeStartupService extends Disposable implements IRuntimeStartup
693739
}
694740

695741
/**
696-
* Activates all of the extensions that provides language runtimes, then
742+
* Activates all of the extensions that provide language runtimes, then
697743
* enters the discovery phase, in which each extension is asked to supply
698744
* its language runtime metadata.
699745
*/
@@ -739,7 +785,7 @@ export class RuntimeStartupService extends Disposable implements IRuntimeStartup
739785
// language runtime providers.
740786
this.setStartupPhase(RuntimeStartupPhase.Discovering);
741787

742-
// Ask each extension to provide its language runtime metadata.
788+
// Ask each extension host to provide its language runtime metadata.
743789
for (const manager of this._runtimeManagers) {
744790
manager.discoverAllRuntimes(disabledLanguages);
745791
}

src/vs/workbench/services/runtimeStartup/common/runtimeStartupService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ export interface IRuntimeStartupService {
124124
*/
125125
completeDiscovery(id: number): void;
126126

127+
/**
128+
* Kick off a user-driven refresh of runtime discovery, after the initial discovery.
129+
*/
130+
rediscoverAllRuntimes(): Promise<void>;
131+
127132
/**
128133
* Get the sessions that were (or will be) restored into this window.
129134
*/

src/vs/workbench/services/runtimeStartup/test/common/testRuntimeStartupService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ export class TestRuntimeStartupService implements IRuntimeStartupService {
110110
// No-op in test implementation
111111
}
112112

113+
/**
114+
* {@inheritDoc}
115+
*/
116+
public async rediscoverAllRuntimes() {
117+
// No-op in test implementation
118+
}
119+
113120
/**
114121
* {@inheritDoc}
115122
*/

0 commit comments

Comments
 (0)