Fix #4356 New Notebook from connection doesn't connect (#4364)

* Fix #4356 New Notebook from connection doesn't connect
Fix new notebook error by passing profile instead of ID.
- I could've just sent the ID over, but this fix sets the stage for disconnected connections to work (since we have enough info to properly connect).
- There's a bug in NotebookModel blocking the disconnected connection part working, but Yurong's in progress fixes will unblock this. Hence checking in as-is and working to properly unblock once that's in.

* Support connection profile in commandline service
- Added new context API for things that want to work on commandline and object explorer
- Refactored commandlineservice slightly to be async & have a simpler execution flow (far fewer if/else statements)

* Fix unit tests
- Fixed 2 issues raised by tests (sholdn't do new query if no profile passed, shouldn't error on new query failing)
- Updated unit tests to pass as expected given changes to the APIs.
This commit is contained in:
Kevin Cunnane
2019-03-12 12:14:08 -07:00
committed by GitHub
parent 77a3be6fd7
commit 7226f25c67
16 changed files with 166 additions and 143 deletions

View File

@@ -408,6 +408,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
}
let profile = new ConnectionProfile(this._notebookOptions.capabilitiesService, this.connectionProfile);
// TODO: this code needs to be fixed since it is called before the this._savedKernelInfo is set.
// This means it always fails, and we end up using the default connection instead. If you right-click
// and run "New Notebook" on a disconnected server this means you get the wrong connection (global active)
// instead of the one you chose, or it'll fail to connect in general
if (this.isValidConnection(profile)) {
this._activeConnection = profile;
} else {

View File

@@ -104,23 +104,18 @@ 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 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);
}
// Second use global connection if possible
let profile: IConnectionProfile = 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;
} else {
// if not, try 1st active connection that matches our filter
let profiles = this.connectionManagementService.getActiveConnections();
if (profiles && profiles.length > 0) {
this.profile = profiles[0];
let activeProfiles = this.connectionManagementService.getActiveConnections();
if (activeProfiles && activeProfiles.length > 0) {
this.profile = activeProfiles[0];
}
}
}

View File

@@ -95,7 +95,7 @@ export class NotebookEditor extends BaseEditor {
providerId: input.providerId ? input.providerId : DEFAULT_NOTEBOOK_PROVIDER,
providers: input.providers ? input.providers : [DEFAULT_NOTEBOOK_PROVIDER],
isTrusted: input.isTrusted,
connectionProfileId: input.connectionProfileId
profile: input.connectionProfile
};
bootstrapAngular(this.instantiationService,
NotebookModule,

View File

@@ -27,6 +27,7 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
import { notebookModeId } from 'sql/common/constants';
import { ITextFileService, ISaveOptions } from 'vs/workbench/services/textfile/common/textfiles';
import { LocalContentManager } from 'sql/workbench/services/notebook/node/localContentManager';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
@@ -128,7 +129,7 @@ export class NotebookInput extends EditorInput {
private _providerId: string;
private _providers: string[];
private _standardKernels: IStandardKernelWithProvider[];
private _connectionProfileId: string;
private _connectionProfile: IConnectionProfile;
private _defaultKernel: azdata.nb.IKernelSpec;
private _isTrusted: boolean = false;
public hasBootstrapped = false;
@@ -191,12 +192,12 @@ export class NotebookInput extends EditorInput {
this._isTrusted = value;
}
public set connectionProfileId(value: string) {
this._connectionProfileId = value;
public set connectionProfile(value: IConnectionProfile) {
this._connectionProfile = value;
}
public get connectionProfileId(): string {
return this._connectionProfileId;
public get connectionProfile(): IConnectionProfile {
return this._connectionProfile;
}
public get standardKernels(): IStandardKernelWithProvider[] {