Skip to content

Commit

Permalink
Clean up the API we expose (#5673)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Apr 28, 2021
1 parent 4ffc77b commit aa2f524
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 32 deletions.
19 changes: 0 additions & 19 deletions src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { traceError } from './common/logger';
import { VSCodeNotebookProvider } from './datascience/constants';
import { IDataViewerDataProvider, IDataViewerFactory } from './datascience/data-viewing/types';
import { NotebookCellRunState } from './datascience/jupyter/kernels/types';
import { CreationOptionService } from './datascience/notebook/creation/creationOptionsService';
import { KernelStateEventArgs } from './datascience/notebookExtensibility';
import {
IJupyterUriProvider,
Expand Down Expand Up @@ -58,19 +57,6 @@ export interface IExtensionApi {
*/
registerRemoteServerProvider(serverProvider: IJupyterUriProvider): void;
registerPythonApi(pythonApi: PythonApi): void;
/**
* When called by other extensions we will display these extensions in a dropdown list when creating a new notebook.
*/
registerNewNotebookContent(options: {
/**
* Use this language as the language of cells for new notebooks created (when user picks this extension).
*/
defaultCellLanguage: string;
/**
* Value in the quickpick (if not provided, will use the displayName of the extension).
*/
label: string;
}): Promise<void>;
/**
* Creates a blank notebook and defaults the empty cell to the language provided.
*/
Expand Down Expand Up @@ -110,11 +96,6 @@ export function buildApi(
},
onKernelStateChange: notebookExtensibility.onKernelStateChange.bind(notebookExtensibility),
registerCellToolbarButton: webviewExtensibility.registerCellToolbarButton.bind(webviewExtensibility),
registerNewNotebookContent(options: { defaultCellLanguage: string; label?: string }) {
return serviceContainer
.get<CreationOptionService>(CreationOptionService)
.registerNewNotebookContent(options);
},
createBlankNotebook: async (options: { defaultCellLanguage: string }): Promise<void> => {
const service = serviceContainer.get<INotebookEditorProvider>(VSCodeNotebookProvider);
await service.createNew(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ import { Telemetry } from '../../constants';
@injectable()
export class CreationOptionService {
private readonly _registrations: { extensionId: string; displayName: string; defaultCellLanguage: string }[] = [];
constructor(@inject(IExtensions) private readonly extensions: IExtensions) {
constructor(@inject(IExtensions) extensions: IExtensions) {
const contributingExtensions = extensions.all.filter((item) =>
item.packageJSON.contributes && item.packageJSON.contributes['jupyter.kernels'] ? true : false
);
contributingExtensions.forEach((ext) => {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ext.packageJSON.contributes['jupyter.kernels'].forEach((kernel: any) => {
sendTelemetryEvent(Telemetry.OpenNotebookSelectionRegistered, undefined, { extensionId: ext.id });
this._registrations.push({
extensionId: ext.id,
displayName: kernel['title'],
defaultCellLanguage: kernel['defaultlanguage']
defaultCellLanguage: kernel['defaultlanguage'] || kernel['defaultLanguage']
});
});
} catch {
traceError(`${ext.id} is not contributing jupyter kernels as expected.`);
}
});
}
public async registerNewNotebookContent(options: { defaultCellLanguage: string; label?: string }): Promise<void> {
const info = await this.extensions.determineExtensionFromCallStack();
if (this._registrations.find((item) => item.extensionId.toLowerCase() === info.extensionId)) {
return;
}
sendTelemetryEvent(Telemetry.OpenNotebookSelectionRegistered, undefined, { extensionId: info.extensionId });
this._registrations.push({ ...info, ...options, displayName: options.label || info.displayName });
/**
* Used purely for testing purposes.
*/
public async registerNewNotebookContent(defaultCellLanguage: string): Promise<void> {
this._registrations.push({ displayName: defaultCellLanguage, defaultCellLanguage, extensionId: '<bogus>' });
}
public get registrations() {
return this._registrations;
Expand Down
1 change: 0 additions & 1 deletion src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export async function activate(context: IExtensionContext): Promise<IExtensionAp
onKernelStateChange: () => ({ dispose: noop }),
ready: Promise.resolve(),
registerCellToolbarButton: () => ({ dispose: noop }),
registerNewNotebookContent: () => Promise.resolve(),
registerPythonApi: noop,
registerRemoteServerProvider: noop,
showDataViewer: () => Promise.resolve()
Expand Down
1 change: 0 additions & 1 deletion src/test/datascience/dataScienceIocContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ export class DataScienceIocContainer extends UnitTestIocContainer {

this.serviceManager.addSingletonInstance<NotebookCreator>(NotebookCreator, instance(mock(NotebookCreator)));
const creationService = mock<CreationOptionService>();
when(creationService.registerNewNotebookContent(anything())).thenResolve();
when(creationService.registrations).thenReturn([]);
this.serviceManager.addSingletonInstance<CreationOptionService>(
CreationOptionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"title": "Create new blank Julia notebook",
"category": "Notebook"
}
],
"jupyter.kernels": [
{
"title": "Julia",
"defaultLanguage": "julia"
}
]
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function activate(_context: vscode.ExtensionContext) {
await jupyter.exports.ready;
}
jupyter.exports.registerRemoteServerProvider(new RemoteServerPickerExample());
jupyter.exports.registerNewNotebookContent({ defaultCellLanguage: 'julia' });
vscode.commands.registerCommand(
'ms-toolsai-test.createBlankNotebook',
() => void jupyter.exports.createBlankNotebook({ defaultCellLanguage: 'julia' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ suite('DataScience - VSCode Notebook - (Creation Integration)', function () {
);
}
test('With 3rd party integration, display quick pick when selecting create blank notebook command', async function () {
await creationOptions.registerNewNotebookContent({ defaultCellLanguage: 'julia' });
await creationOptions.registerNewNotebookContent('julia');
assert.equal(creationOptions.registrations.length, 1);
assert.isUndefined(vscodeNotebook.activeNotebookEditor);

Expand Down

0 comments on commit aa2f524

Please sign in to comment.