Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display kernelSpec src only if kernels are found #12517

Merged
merged 1 commit into from
Jan 10, 2023
Merged
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
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);
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved
this.localDisposables.push(
commands.registerCommand(
'jupyter.kernel.selectLocalKernelSpec',
Expand Down