diff --git a/src/sql/parts/notebook/notebook.component.ts b/src/sql/parts/notebook/notebook.component.ts index 1068d53622..797533292d 100644 --- a/src/sql/parts/notebook/notebook.component.ts +++ b/src/sql/parts/notebook/notebook.component.ts @@ -102,9 +102,15 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe private updateProfile(): void { this.profile = this.notebookParams ? this.notebookParams.profile : undefined; + let profile: IConnectionProfile; if (!this.profile) { - // use global connection if possible - let profile = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService); + // Use connectionProfile passed in first + if (this._notebookParams.connectionProfileId !== undefined && this._notebookParams.connectionProfileId) { + profile = this.connectionManagementService.getConnectionProfileById(this._notebookParams.connectionProfileId); + } else { + // Second use global connection if possible + profile = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService); + } // TODO use generic method to match kernel with valid connection that's compatible. For now, we only have 1 if (profile && profile.providerName) { this.profile = profile; @@ -481,10 +487,10 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe */ private fillInActionsForCurrentContext(): void { let primary: IAction[] = []; - let secondary: IAction[] = []; + let secondary: IAction[] = []; let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService); let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true }); - fillInActions(groups, {primary, secondary}, false, (group: string) => group === undefined); + fillInActions(groups, { primary, secondary }, false, (group: string) => group === undefined); this.addPrimaryContributedActions(primary); } diff --git a/src/sql/parts/notebook/notebookEditor.ts b/src/sql/parts/notebook/notebookEditor.ts index 906966598f..6d91ee090b 100644 --- a/src/sql/parts/notebook/notebookEditor.ts +++ b/src/sql/parts/notebook/notebookEditor.ts @@ -92,7 +92,8 @@ export class NotebookEditor extends BaseEditor { input: input, providerId: input.providerId ? input.providerId : DEFAULT_NOTEBOOK_PROVIDER, providers: input.providers ? input.providers : [DEFAULT_NOTEBOOK_PROVIDER], - isTrusted: input.isTrusted + isTrusted: input.isTrusted, + connectionProfileId: input.connectionProfileId }; bootstrapAngular(this.instantiationService, NotebookModule, diff --git a/src/sql/parts/notebook/notebookInput.ts b/src/sql/parts/notebook/notebookInput.ts index 03ddcfe051..aac4bc0d45 100644 --- a/src/sql/parts/notebook/notebookInput.ts +++ b/src/sql/parts/notebook/notebookInput.ts @@ -28,7 +28,14 @@ export class NotebookInputModel extends EditorModel { private _providerId: string; private _standardKernels: IStandardKernelWithProvider[]; private _defaultKernel: sqlops.nb.IKernelSpec; - constructor(public readonly notebookUri: URI, private readonly handle: number, private _isTrusted: boolean = false, private saveHandler?: ModeViewSaveHandler, provider?: string, private _providers?: string[]) { + constructor(public readonly notebookUri: URI, + private readonly handle: number, + private _isTrusted: boolean = false, + private saveHandler?: ModeViewSaveHandler, + provider?: string, + private _providers?: string[], + private _connectionProfileId?: string) { + super(); this.dirty = false; this._providerId = provider; @@ -51,6 +58,10 @@ export class NotebookInputModel extends EditorModel { this._providers = value; } + public get connectionProfileId(): string { + return this._connectionProfileId; + } + public get standardKernels(): IStandardKernelWithProvider[] { return this._standardKernels; } @@ -131,6 +142,10 @@ export class NotebookInput extends EditorInput { return this._model.providers; } + public get connectionProfileId(): string { + return this._model.connectionProfileId; + } + public get standardKernels(): IStandardKernelWithProvider[] { return this._model.standardKernels; } diff --git a/src/sql/platform/connection/common/connectionManagement.ts b/src/sql/platform/connection/common/connectionManagement.ts index ba7cdffbb4..f8cfd8cdbd 100644 --- a/src/sql/platform/connection/common/connectionManagement.ts +++ b/src/sql/platform/connection/common/connectionManagement.ts @@ -272,6 +272,11 @@ export interface IConnectionManagementService { * Serialize connection string with optional provider */ buildConnectionInfo(connectionString: string, provider?: string): Thenable; + + /** + * Get connection profile by id + */ + getConnectionProfileById(profileId: string): IConnectionProfile; } export const IConnectionDialogService = createDecorator('connectionDialogService'); diff --git a/src/sql/platform/connection/common/connectionManagementService.ts b/src/sql/platform/connection/common/connectionManagementService.ts index 7dc26bca2e..bce270a8a5 100644 --- a/src/sql/platform/connection/common/connectionManagementService.ts +++ b/src/sql/platform/connection/common/connectionManagementService.ts @@ -1378,6 +1378,14 @@ export class ConnectionManagementService extends Disposable implements IConnecti return serverInfo; } + public getConnectionProfileById(profileId: string): IConnectionProfile { + let profile = this._connectionStatusManager.findConnectionByProfileId(profileId); + if (!profile) { + return undefined; + } + return profile.connectionProfile; + } + /** * Get the connection string for the provided connection ID */ diff --git a/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts index b40bc3cbb7..a01e5465be 100644 --- a/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts @@ -361,7 +361,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements pinned: !options.preview }; let trusted = uri.scheme === Schemas.untitled; - let model = new NotebookInputModel(uri, undefined, trusted, undefined); + let model = new NotebookInputModel(uri, undefined, trusted, undefined, undefined, undefined, options.connectionId); let providerId = options.providerId; let providers: string[] = undefined; // Ensure there is always a sensible provider ID for this file type diff --git a/src/sql/workbench/services/notebook/common/notebookService.ts b/src/sql/workbench/services/notebook/common/notebookService.ts index b47476f35d..09d6832d22 100644 --- a/src/sql/workbench/services/notebook/common/notebookService.ts +++ b/src/sql/workbench/services/notebook/common/notebookService.ts @@ -94,6 +94,7 @@ export interface INotebookParams extends IBootstrapParams { isTrusted: boolean; profile?: IConnectionProfile; modelFactory?: ModelFactory; + connectionProfileId?: string; } export interface INotebookEditor { diff --git a/src/sqltest/stubs/connectionManagementService.test.ts b/src/sqltest/stubs/connectionManagementService.test.ts index 2f70c3cfa3..50fbe7c6eb 100644 --- a/src/sqltest/stubs/connectionManagementService.test.ts +++ b/src/sqltest/stubs/connectionManagementService.test.ts @@ -265,4 +265,8 @@ export class TestConnectionManagementService implements IConnectionManagementSer buildConnectionInfo(connectionString: string, provider?: string): Thenable { return undefined; } + + getConnectionProfileById(profileId: string): IConnectionProfile { + return undefined; + } } \ No newline at end of file