mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 17:23:25 -05:00
Kusto Kernel New Notebook Changes (#12085)
* Kusto New Notebook Action Changes * Kusto Cluster properly switches context when kernel changes * SQL Connections kernel change to Kusto works properly * Multiple New Kusto Notebooks open properly and change kernels properly * Fix SQL Notebook - Change to Kusto Kernel * Fix unit tests * Address comments * Add test, and finalize changes
This commit is contained in:
@@ -83,6 +83,8 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
private _textCellsLoading: number = 0;
|
||||
private _standardKernels: notebookUtils.IStandardKernelWithProvider[];
|
||||
private _kernelAliases: string[] = [];
|
||||
private _currentKernelAlias: string;
|
||||
private _selectedKernelDisplayName: string;
|
||||
|
||||
public requestConnectionHandler: () => Promise<boolean>;
|
||||
|
||||
@@ -240,6 +242,14 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
return this._kernelAliases;
|
||||
}
|
||||
|
||||
public get currentKernelAlias(): string {
|
||||
return this._currentKernelAlias;
|
||||
}
|
||||
|
||||
public get selectedKernelDisplayName(): string {
|
||||
return this._selectedKernelDisplayName;
|
||||
}
|
||||
|
||||
public set trustedMode(isTrusted: boolean) {
|
||||
this._trustedMode = isTrusted;
|
||||
|
||||
@@ -629,7 +639,12 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
if (this._standardKernels) {
|
||||
let standardKernels = find(this._standardKernels, kernel => this._defaultKernel && kernel.displayName === this._defaultKernel.display_name);
|
||||
let connectionProviderIds = standardKernels ? standardKernels.connectionProviderIds : undefined;
|
||||
return profile && connectionProviderIds && find(connectionProviderIds, provider => provider === profile.providerName) !== undefined;
|
||||
let providerFeatures = this._capabilitiesService.getCapabilities(profile.providerName);
|
||||
if (connectionProviderIds.length > 0) {
|
||||
this._currentKernelAlias = providerFeatures?.connection.notebookKernelAlias;
|
||||
this._kernelDisplayNameToConnectionProviderIds.set(this._currentKernelAlias, [profile.providerName]);
|
||||
}
|
||||
return this._currentKernelAlias || profile && connectionProviderIds && find(connectionProviderIds, provider => provider === profile.providerName) !== undefined;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -706,8 +721,15 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
}
|
||||
|
||||
public changeKernel(displayName: string): void {
|
||||
this._contextsLoadingEmitter.fire();
|
||||
this.doChangeKernel(displayName, true).catch(e => this.logService.error(e));
|
||||
this._selectedKernelDisplayName = displayName;
|
||||
this._currentKernelAlias = this.context?.serverCapabilities.notebookKernelAlias;
|
||||
if (this.kernelAliases.includes(this.currentKernelAlias) && displayName === this.currentKernelAlias) {
|
||||
this.doChangeKernel(displayName, true).catch(e => this.logService.error(e));
|
||||
} else {
|
||||
this._currentKernelAlias = undefined;
|
||||
this._contextsLoadingEmitter.fire();
|
||||
this.doChangeKernel(displayName, true).catch(e => this.logService.error(e));
|
||||
}
|
||||
}
|
||||
|
||||
private async doChangeKernel(displayName: string, mustSetProvider: boolean = true, restoreOnFail: boolean = true): Promise<void> {
|
||||
@@ -718,8 +740,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
let oldDisplayName = this._activeClientSession && this._activeClientSession.kernel ? this._activeClientSession.kernel.name : undefined;
|
||||
let nbKernelAlias: string;
|
||||
if (this.kernelAliases.includes(displayName)) {
|
||||
this._currentKernelAlias = displayName;
|
||||
displayName = 'SQL';
|
||||
nbKernelAlias = 'Kusto';
|
||||
nbKernelAlias = this._currentKernelAlias;
|
||||
this._kernelDisplayNameToConnectionProviderIds.set(this.currentKernelAlias, [this.currentKernelAlias.toUpperCase()]);
|
||||
}
|
||||
try {
|
||||
let changeKernelNeeded = true;
|
||||
@@ -798,6 +822,16 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
}
|
||||
|
||||
if (newConnection) {
|
||||
if (newConnection.serverCapabilities?.notebookKernelAlias) {
|
||||
this._currentKernelAlias = newConnection.serverCapabilities.notebookKernelAlias;
|
||||
let sqlConnectionProvider = this._kernelDisplayNameToConnectionProviderIds.get('SQL');
|
||||
let index = sqlConnectionProvider.indexOf(newConnection.serverCapabilities.notebookKernelAlias.toUpperCase());
|
||||
if (index > -1) {
|
||||
sqlConnectionProvider.splice(index, 1);
|
||||
}
|
||||
this._kernelDisplayNameToConnectionProviderIds.set('SQL', sqlConnectionProvider);
|
||||
this._kernelDisplayNameToConnectionProviderIds.set(newConnection.serverCapabilities.notebookKernelAlias, [newConnection.providerName]);
|
||||
}
|
||||
this._activeConnection = newConnection;
|
||||
this.setActiveConnectionIfDifferent(newConnection);
|
||||
this._activeClientSession.updateConnection(newConnection.toIConnectionProfile()).then(
|
||||
|
||||
Reference in New Issue
Block a user