mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 09:35:40 -05:00
[Notebook] Run Parameters Action openNotebook Functionality in Core (#14978)
* NotebookService update * openNotebook functionality in NbService * Add tests for RunParametersAction
This commit is contained in:
36
src/sql/workbench/services/notebook/browser/interface.ts
Normal file
36
src/sql/workbench/services/notebook/browser/interface.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IContentManager } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||
|
||||
export interface INotebookInput {
|
||||
defaultKernel: azdata.nb.IKernelSpec,
|
||||
connectionProfile: azdata.IConnectionProfile,
|
||||
isDirty(): boolean;
|
||||
setDirty(boolean);
|
||||
readonly notebookUri: URI;
|
||||
updateModel(): void;
|
||||
readonly editorOpenedTimestamp: number;
|
||||
readonly layoutChanged: Event<void>;
|
||||
readonly contentManager: IContentManager;
|
||||
readonly standardKernels: IStandardKernelWithProvider[];
|
||||
}
|
||||
|
||||
export function isINotebookInput(value: any): value is INotebookInput {
|
||||
if (typeof value.defaultKernel === 'object' &&
|
||||
typeof value.connectionProfile === 'object' &&
|
||||
typeof value.isDirty === 'boolean' &&
|
||||
value.notebookUri instanceof URI &&
|
||||
typeof value.editorOpenedTimestamp === 'number' &&
|
||||
typeof value.layoutChanged === 'object' &&
|
||||
typeof value.contentManager === 'object' &&
|
||||
typeof value.standardKernels === 'object') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -7,17 +7,19 @@ import * as azdata from 'azdata';
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { RenderMimeRegistry } from 'sql/workbench/services/notebook/browser/outputs/registry';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ICellModel, INotebookModel, IContentManager } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { NotebookChangeType, CellType } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
|
||||
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||
import { IEditorPane } from 'vs/workbench/common/editor';
|
||||
import { INotebookInput } from 'sql/workbench/services/notebook/browser/interface';
|
||||
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||
|
||||
export const SERVICE_ID = 'sqlNotebookService';
|
||||
export const INotebookService = createDecorator<INotebookService>(SERVICE_ID);
|
||||
@@ -139,6 +141,8 @@ export interface INotebookService {
|
||||
* Fires the onCodeCellExecutionStart event.
|
||||
*/
|
||||
notifyCellExecutionStarted(): void;
|
||||
|
||||
openNotebook(resource: UriComponents, options: INotebookShowOptions): Promise<IEditorPane | undefined>;
|
||||
}
|
||||
|
||||
export interface INotebookProvider {
|
||||
@@ -159,17 +163,6 @@ export interface IProviderInfo {
|
||||
providers: string[];
|
||||
}
|
||||
|
||||
export interface INotebookInput {
|
||||
readonly notebookUri: URI;
|
||||
updateModel(): void;
|
||||
isDirty(): boolean;
|
||||
readonly defaultKernel: azdata.nb.IKernelSpec;
|
||||
readonly editorOpenedTimestamp: number;
|
||||
readonly contentManager: IContentManager;
|
||||
readonly standardKernels: IStandardKernelWithProvider[];
|
||||
readonly layoutChanged: Event<void>;
|
||||
}
|
||||
|
||||
export interface INotebookParams extends IBootstrapParams {
|
||||
notebookUri: URI;
|
||||
input: INotebookInput;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { nb } from 'azdata';
|
||||
import { localize } from 'vs/nls';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
import {
|
||||
@@ -36,6 +36,23 @@ import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { notebookConstants } from 'sql/workbench/services/notebook/browser/interfaces';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { viewColumnToEditorGroup } from 'vs/workbench/api/common/shared/editor';
|
||||
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { Extensions as LanguageAssociationExtensions, ILanguageAssociationRegistry } from 'sql/workbench/services/languageAssociation/common/languageAssociation';
|
||||
|
||||
import * as path from 'vs/base/common/path';
|
||||
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
|
||||
import { IEditorInput, IEditorPane } from 'vs/workbench/common/editor';
|
||||
import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface';
|
||||
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||
import { NotebookLanguage } from 'sql/workbench/common/constants';
|
||||
|
||||
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
|
||||
|
||||
export interface NotebookProviderProperties {
|
||||
provider: string;
|
||||
@@ -120,7 +137,10 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@IQueryManagementService private readonly _queryManagementService: IQueryManagementService,
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@IProductService private readonly productService: IProductService
|
||||
@IProductService private readonly productService: IProductService,
|
||||
@IEditorService private _editorService: IEditorService,
|
||||
@IUntitledTextEditorService private _untitledEditorService: IUntitledTextEditorService,
|
||||
@IEditorGroupsService private _editorGroupService: IEditorGroupsService
|
||||
) {
|
||||
super();
|
||||
this._providersMemento = new Memento('notebookProviders', this._storageService);
|
||||
@@ -163,8 +183,45 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
lifecycleService.onWillShutdown(() => this.shutdown());
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
super.dispose();
|
||||
public async openNotebook(resource: UriComponents, options: INotebookShowOptions): Promise<IEditorPane | undefined> {
|
||||
const uri = URI.revive(resource);
|
||||
|
||||
const editorOptions: ITextEditorOptions = {
|
||||
preserveFocus: options.preserveFocus,
|
||||
pinned: !options.preview
|
||||
};
|
||||
let isUntitled: boolean = uri.scheme === Schemas.untitled;
|
||||
|
||||
let fileInput: IEditorInput;
|
||||
if (isUntitled && path.isAbsolute(uri.fsPath)) {
|
||||
const model = this._untitledEditorService.create({ associatedResource: uri, mode: 'notebook', initialValue: options.initialContent });
|
||||
fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model);
|
||||
} else {
|
||||
if (isUntitled) {
|
||||
const model = this._untitledEditorService.create({ untitledResource: uri, mode: 'notebook', initialValue: options.initialContent });
|
||||
fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model);
|
||||
} else {
|
||||
fileInput = this._editorService.createEditorInput({ forceFile: true, resource: uri, mode: 'notebook' });
|
||||
}
|
||||
}
|
||||
// We only need to get the Notebook language association as such we only need to use ipynb
|
||||
const inputCreator = languageAssociationRegistry.getAssociationForLanguage(NotebookLanguage.Ipynb);
|
||||
if (inputCreator) {
|
||||
fileInput = await inputCreator.convertInput(fileInput);
|
||||
if (isINotebookInput(fileInput)) {
|
||||
fileInput.defaultKernel = options.defaultKernel;
|
||||
fileInput.connectionProfile = options.connectionProfile;
|
||||
|
||||
if (isUntitled) {
|
||||
let untitledModel = await fileInput.resolve();
|
||||
await untitledModel.load();
|
||||
if (options.initialDirtyState === false) {
|
||||
fileInput.setDirty(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return await this._editorService.openEditor(fileInput, editorOptions, viewColumnToEditorGroup(this._editorGroupService, options.position));
|
||||
}
|
||||
|
||||
private updateSQLRegistrationWithConnectionProviders() {
|
||||
@@ -350,7 +407,8 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
if (!notebookUri) {
|
||||
return undefined;
|
||||
}
|
||||
let uriString = notebookUri.toString();
|
||||
// The NotebookEditor will not be found if there is query or fragments attached to the URI
|
||||
let uriString = notebookUri.with({ query: '', fragment: '' }).toString();
|
||||
let editor = this.listNotebookEditors().find(n => n.id === uriString);
|
||||
return editor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user