No kernel is shown when open a new notebook from command palette (#3374)

Fixes #3271. Ensure a provider is defined when opening through command palette
This commit is contained in:
Raj
2018-12-03 18:12:25 -08:00
committed by Kevin Cunnane
parent 86e54ce145
commit cb162b16f2
2 changed files with 18 additions and 2 deletions

View File

@@ -18,7 +18,12 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { NotebookInput, NotebookInputModel, notebooksEnabledCondition } from 'sql/parts/notebook/notebookInput';
import { NotebookEditor } from 'sql/parts/notebook/notebookEditor';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { INotebookProviderRegistry } from 'sql/services/notebook/notebookRegistry';
const DEFAULT_NOTEBOOK_FILETYPE = 'IPYNB';
const Extensions = {
NotebookProviderContribution: 'notebook.providers'
};
let counter = 0;
@@ -44,6 +49,11 @@ export class NewNotebookAction extends Action {
let title = `Untitled-${counter++}`;
let untitledUri = URI.from({ scheme: Schemas.untitled, path: title });
let model = new NotebookInputModel(untitledUri, undefined, false, undefined);
if(!model.providerId)
{
let notebookRegistry = Registry.as<INotebookProviderRegistry>(Extensions.NotebookProviderContribution);
model.providerId = notebookRegistry.getProviderForFileType(DEFAULT_NOTEBOOK_FILETYPE);
}
let input = this._instantiationService.createInstance(NotebookInput, title, model);
return this._editorService.openEditor(input, { pinned: true }).then(() => undefined);
}

View File

@@ -86,11 +86,17 @@ export class NotebookService implements INotebookService {
// PRIVATE HELPERS /////////////////////////////////////////////////////
private doWithProvider<T>(providerId: string, op: (provider: INotebookProvider) => Thenable<T>): Thenable<T> {
// Make sure the provider exists before attempting to retrieve accounts
let provider = this._providers.get(providerId);
let provider: INotebookProvider;
if (this._providers.has(providerId)) {
provider = this._providers.get(providerId);
}
else {
provider = this._providers.get(DEFAULT_NOTEBOOK_PROVIDER);
}
if (!provider) {
return Promise.reject(new Error(localize('notebookServiceNoProvider', 'Notebook provider does not exist'))).then();
}
return op(provider);
}