Skip to content

Commit

Permalink
Display kernelSpec src only if kernels are found
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jan 10, 2023
1 parent d546b4d commit 6287c89
Showing 1 changed file with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContributedKernelFinderKind } from '../../../kernels/internalTypes';
import { IJupyterUriProviderRegistration } from '../../../kernels/jupyter/types';
import { initializeInteractiveOrNotebookTelemetryBasedOnUserAction } from '../../../kernels/telemetry/helper';
import { sendKernelTelemetryEvent } from '../../../kernels/telemetry/sendKernelTelemetryEvent';
import { KernelConnectionMetadata } from '../../../kernels/types';
import { IKernelFinder, KernelConnectionMetadata } from '../../../kernels/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { InteractiveWindowView, JupyterNotebookView, Telemetry } from '../../../platform/common/constants';
import { disposeAllDisposables } from '../../../platform/common/helpers';
Expand All @@ -22,11 +22,13 @@ import { IControllerRegistration, INotebookKernelSourceSelector } from '../types
export class KernelSourceCommandHandler implements IExtensionSyncActivationService {
private localDisposables: IDisposable[] = [];
private readonly providerMappings = new Map<string, IDisposable[]>();
private kernelSpecsSourceRegistered = false;
constructor(
@inject(IFeaturesManager) private readonly featuresManager: IFeaturesManager,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(IControllerRegistration) private readonly controllerRegistration: IControllerRegistration,
@inject(IsWebExtension) private readonly isWebExtension: boolean
@inject(IsWebExtension) private readonly isWebExtension: boolean,
@inject(IKernelFinder) private readonly kernelFinder: IKernelFinder
) {
disposables.push(this);
}
Expand All @@ -42,6 +44,7 @@ export class KernelSourceCommandHandler implements IExtensionSyncActivationServi
disposeAllDisposables(this.localDisposables);
this.localDisposables = [];
this.providerMappings.clear();
this.kernelSpecsSourceRegistered = false;
}
};

Expand All @@ -57,10 +60,6 @@ export class KernelSourceCommandHandler implements IExtensionSyncActivationServi
{
label: DataScience.localPythonEnvironments(),
command: 'jupyter.kernel.selectLocalPythonEnvironment'
},
{
label: DataScience.localKernelSpecs(),
command: 'jupyter.kernel.selectLocalKernelSpec'
}
];
}
Expand All @@ -73,15 +72,45 @@ export class KernelSourceCommandHandler implements IExtensionSyncActivationServi
{
label: DataScience.localPythonEnvironments(),
command: 'jupyter.kernel.selectLocalPythonEnvironment'
},
{
label: DataScience.localKernelSpecs(),
command: 'jupyter.kernel.selectLocalKernelSpec'
}
];
}
})
);
const registerKernelSpecsSource = () => {
if (this.kernelSpecsSourceRegistered) {
return;
}
if (this.kernelFinder.kernels.some((k) => k.kind === 'startUsingLocalKernelSpec')) {
this.kernelSpecsSourceRegistered = true;
this.localDisposables.push(
notebooks.registerKernelSourceActionProvider(JupyterNotebookView, {
provideNotebookKernelSourceActions: () => {
return [
{
label: DataScience.localKernelSpecs(),
command: 'jupyter.kernel.selectLocalKernelSpec'
}
];
}
})
);
this.localDisposables.push(
notebooks.registerKernelSourceActionProvider(InteractiveWindowView, {
provideNotebookKernelSourceActions: () => {
return [
{
label: DataScience.localKernelSpecs(),
command: 'jupyter.kernel.selectLocalKernelSpec'
}
];
}
})
);
}
};
registerKernelSpecsSource();
this.kernelFinder.onDidChangeKernels(() => registerKernelSpecsSource(), this, this.localDisposables);
this.localDisposables.push(
commands.registerCommand(
'jupyter.kernel.selectLocalKernelSpec',
Expand Down

0 comments on commit 6287c89

Please sign in to comment.