mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
Remove API compatibility layer for VS Code notebook extensions (#21225)
This commit is contained in:
@@ -35,7 +35,6 @@ import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
import { ICellMetadata } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { alert } from 'vs/base/browser/ui/aria/aria';
|
||||
import { CELL_URI_PATH_PREFIX } from 'sql/workbench/common/constants';
|
||||
import { DotnetInteractiveLanguagePrefix } from 'sql/workbench/api/common/notebooks/notebookUtils';
|
||||
import { IModelContentChangedEvent } from 'vs/editor/common/textModelEvents';
|
||||
|
||||
let modelId = 0;
|
||||
@@ -659,10 +658,7 @@ export class CellModel extends Disposable implements ICellModel {
|
||||
if (tryMatchCellMagic(this.source[0]) !== ads_execute_command || !this._isCommandExecutionSettingEnabled) {
|
||||
const future = kernel.requestExecute({
|
||||
code: content,
|
||||
cellIndex: this.notebookModel.findCellIndex(this),
|
||||
stop_on_error: true,
|
||||
notebookUri: this.notebookModel.notebookUri,
|
||||
cellUri: this.cellUri,
|
||||
language: this.language
|
||||
}, false);
|
||||
this.setFuture(future as FutureInternal);
|
||||
@@ -1020,10 +1016,6 @@ export class CellModel extends Disposable implements ICellModel {
|
||||
if (this._configurationService?.getValue('notebook.saveConnectionName')) {
|
||||
metadata.connection_name = this._savedConnectionName;
|
||||
}
|
||||
// Set .NET Interactive language field for vscode compatibility
|
||||
if (this._language?.startsWith(DotnetInteractiveLanguagePrefix)) {
|
||||
(cellJson.metadata as ICellMetadata).dotnet_interactive = { language: this._language.replace(DotnetInteractiveLanguagePrefix, '') };
|
||||
}
|
||||
} else if (this._cellType === CellTypes.Markdown && this._attachments) {
|
||||
cellJson.attachments = this._attachments;
|
||||
}
|
||||
@@ -1110,8 +1102,6 @@ export class CellModel extends Disposable implements ICellModel {
|
||||
this._language = 'markdown';
|
||||
} else if (metadata?.language) {
|
||||
this._language = metadata.language;
|
||||
} else if (metadata?.dotnet_interactive?.language) {
|
||||
this._language = `dotnet-interactive.${metadata.dotnet_interactive.language}`;
|
||||
} else {
|
||||
this._language = this._options?.notebook?.language;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
import { AddCellEdit, CellOutputEdit, ConvertCellTypeEdit, DeleteCellEdit, MoveCellEdit, CellOutputDataEdit, SplitCellEdit } from 'sql/workbench/services/notebook/browser/models/cellEdit';
|
||||
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
|
||||
import { deepClone } from 'vs/base/common/objects';
|
||||
import { DotnetInteractiveDisplayName } from 'sql/workbench/api/common/notebooks/notebookUtils';
|
||||
import { IPYKERNEL_DISPLAY_NAME } from 'sql/workbench/common/constants';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
@@ -1404,11 +1403,6 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
let standardKernel = this._standardKernels.find(kernel => kernel.displayName === displayName || displayName.startsWith(kernel.displayName));
|
||||
if (standardKernel) {
|
||||
if (this._savedKernelInfo.name && this._savedKernelInfo.name !== standardKernel.name) {
|
||||
// Special case .NET Interactive kernel name to handle inconsistencies between notebook providers and jupyter kernel specs
|
||||
if (this._savedKernelInfo.display_name === DotnetInteractiveDisplayName) {
|
||||
this._savedKernelInfo.oldName = this._savedKernelInfo.name;
|
||||
}
|
||||
|
||||
this._savedKernelInfo.name = standardKernel.name;
|
||||
this._savedKernelInfo.display_name = standardKernel.displayName;
|
||||
} else if (displayName === IPYKERNEL_DISPLAY_NAME && this._savedKernelInfo.name === standardKernel.name) {
|
||||
@@ -1500,9 +1494,6 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
display_name: spec.display_name,
|
||||
language: spec.language,
|
||||
supportedLanguages: spec.supportedLanguages,
|
||||
oldName: spec.oldName,
|
||||
oldDisplayName: spec.oldDisplayName,
|
||||
oldLanguage: spec.oldLanguage
|
||||
};
|
||||
this.clientSession?.configureKernel(this._savedKernelInfo);
|
||||
} catch (err) {
|
||||
@@ -1631,26 +1622,6 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
delete metadata.kernelspec?.supportedLanguages;
|
||||
|
||||
metadata.language_info = this.languageInfo;
|
||||
|
||||
// Undo special casing for .NET Interactive
|
||||
if (metadata.kernelspec?.oldName) {
|
||||
metadata.kernelspec.name = metadata.kernelspec.oldName;
|
||||
delete metadata.kernelspec.oldName;
|
||||
}
|
||||
if (metadata.kernelspec?.oldDisplayName) {
|
||||
metadata.kernelspec.display_name = metadata.kernelspec.oldDisplayName;
|
||||
delete metadata.kernelspec.oldDisplayName;
|
||||
}
|
||||
if (metadata.kernelspec?.oldLanguage) {
|
||||
metadata.kernelspec.language = metadata.kernelspec.oldLanguage;
|
||||
delete metadata.kernelspec.oldLanguage;
|
||||
}
|
||||
if (metadata.language_info?.oldName) {
|
||||
metadata.language_info.name = metadata.language_info?.oldName;
|
||||
delete metadata.language_info?.oldName;
|
||||
}
|
||||
|
||||
|
||||
metadata.tags = this._tags;
|
||||
metadata.multi_connection_mode = this._multiConnectionMode ? this._multiConnectionMode : undefined;
|
||||
if (this.configurationService.getValue(saveConnectionNameConfigName)) {
|
||||
|
||||
@@ -21,7 +21,6 @@ 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';
|
||||
import { NotebookViewsExtension } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViewsExtension';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { ICodeEditorViewState } from 'vs/editor/common/editorCommon';
|
||||
import { JUPYTER_PROVIDER_ID } from 'sql/workbench/common/constants';
|
||||
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||
@@ -145,13 +144,9 @@ export interface INotebookService {
|
||||
*/
|
||||
notifyCellExecutionStarted(): void;
|
||||
|
||||
createNotebookInputFromContents(providerId: string, contents?: azdata.nb.INotebookContents, resource?: UriComponents): Promise<EditorInput | undefined>;
|
||||
|
||||
openNotebook(resource: UriComponents, options: INotebookShowOptions): Promise<IEditorPane | undefined>;
|
||||
|
||||
getUntitledUriPath(originalTitle: string): string;
|
||||
|
||||
getNotebookURIForCell(cellUri: URI): URI | undefined;
|
||||
}
|
||||
|
||||
export interface IExecuteProvider {
|
||||
|
||||
@@ -50,7 +50,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
|
||||
import { IEditorPane, IUntypedFileEditorInput } from 'vs/workbench/common/editor';
|
||||
import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface';
|
||||
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||
import { DEFAULT_NOTEBOOK_FILETYPE, INTERACTIVE_PROVIDER_ID, NotebookLanguage } from 'sql/workbench/common/constants';
|
||||
import { DEFAULT_NOTEBOOK_FILETYPE, NotebookLanguage } from 'sql/workbench/common/constants';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { SqlSerializationProvider } from 'sql/workbench/services/notebook/browser/sql/sqlSerializationProvider';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
@@ -263,22 +263,6 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public async createNotebookInputFromContents(providerId: string, contents?: nb.INotebookContents, resource?: UriComponents): Promise<EditorInput> {
|
||||
let uri: URI;
|
||||
if (resource) {
|
||||
uri = URI.revive(resource);
|
||||
} else {
|
||||
uri = this.getUntitledFileUri();
|
||||
resource = uri;
|
||||
}
|
||||
|
||||
let options: INotebookShowOptions = {
|
||||
providerId: providerId,
|
||||
initialContent: contents
|
||||
};
|
||||
return this.createNotebookInput(options, resource);
|
||||
}
|
||||
|
||||
private async createNotebookInput(options: INotebookShowOptions, resource?: UriComponents): Promise<EditorInput | undefined> {
|
||||
let uri: URI;
|
||||
if (resource) {
|
||||
@@ -292,7 +276,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
let isUntitled: boolean = uri.scheme === Schemas.untitled;
|
||||
|
||||
let fileInput: EditorInput;
|
||||
let languageId = options.providerId === INTERACTIVE_PROVIDER_ID ? NotebookLanguage.Interactive : NotebookLanguage.Notebook;
|
||||
let languageId = NotebookLanguage.Notebook;
|
||||
let initialStringContents: string;
|
||||
if (options.initialContent) {
|
||||
if (typeof options.initialContent === 'string') {
|
||||
@@ -385,19 +369,6 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
return title;
|
||||
}
|
||||
|
||||
public getNotebookURIForCell(cellUri: URI): URI | undefined {
|
||||
for (let editor of this.listNotebookEditors()) {
|
||||
if (editor.cells) {
|
||||
for (let cell of editor.cells) {
|
||||
if (cell.cellUri === cellUri) {
|
||||
return editor.notebookParams.notebookUri;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private updateSQLRegistrationWithConnectionProviders() {
|
||||
// Update the SQL extension
|
||||
let sqlNotebookKernels = this._providerToStandardKernels.get(notebookConstants.SQL);
|
||||
@@ -439,12 +410,6 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
this._executeProviders.set(p.id, new ExecuteProviderDescriptor(p.id));
|
||||
}
|
||||
this.addStandardKernels(registration, registration.fileExtensions);
|
||||
} else {
|
||||
// Standard kernels might get registered later for VSCode notebooks, so add a descriptor to wait on
|
||||
if (!this._providerToStandardKernels.has(p.id)) {
|
||||
let descriptor = new StandardKernelsDescriptor(p.id);
|
||||
this._providerToStandardKernels.set(p.id.toUpperCase(), descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// Emit activation event if the provider is not one of the default options
|
||||
|
||||
@@ -55,26 +55,12 @@ export const textRendererFactory: IRenderMime.IRendererFactory = {
|
||||
mimeTypes: [
|
||||
'text/plain',
|
||||
'application/vnd.jupyter.stdout',
|
||||
'application/vnd.jupyter.stderr',
|
||||
'application/vnd.code.notebook.stdout',
|
||||
'application/vnd.code.notebook.stderr'
|
||||
'application/vnd.jupyter.stderr'
|
||||
],
|
||||
defaultRank: 120,
|
||||
createRenderer: options => new widgets.RenderedText(options)
|
||||
};
|
||||
|
||||
/**
|
||||
* A mime renderer factory for VS Code Notebook error data.
|
||||
*/
|
||||
export const errorRendererFactory: IRenderMime.IRendererFactory = {
|
||||
safe: true,
|
||||
mimeTypes: [
|
||||
'application/vnd.code.notebook.error'
|
||||
],
|
||||
defaultRank: 121,
|
||||
createRenderer: options => new widgets.ErrorText(options)
|
||||
};
|
||||
|
||||
/**
|
||||
* A placeholder factory for deprecated rendered JavaScript.
|
||||
*/
|
||||
@@ -115,7 +101,6 @@ export const standardRendererFactories: ReadonlyArray<IRenderMime.IRendererFacto
|
||||
imageRendererFactory,
|
||||
javaScriptRendererFactory,
|
||||
textRendererFactory,
|
||||
errorRendererFactory,
|
||||
dataResourceRendererFactory,
|
||||
ipywidgetFactory
|
||||
];
|
||||
|
||||
@@ -319,34 +319,6 @@ export class RenderedText extends RenderedCommon {
|
||||
}
|
||||
}
|
||||
|
||||
export class ErrorText extends RenderedCommon {
|
||||
/**
|
||||
* Construct a new error text widget.
|
||||
*
|
||||
* @param options - The options for initializing the widget.
|
||||
*/
|
||||
constructor(options: IRenderMime.IRendererOptions) {
|
||||
super(options);
|
||||
this.addClass('jp-ErrorText');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a mime model.
|
||||
*
|
||||
* @param model - The mime model to render.
|
||||
*
|
||||
* @returns A promise which resolves when rendering is complete.
|
||||
*/
|
||||
render(model: IRenderMime.IMimeModel): Promise<void> {
|
||||
let err = JSON.parse(String(model.data[this.mimeType]));
|
||||
let text = err.name && err.message ? `${err.name}: ${err.message}` : err.name || err.message;
|
||||
return renderers.renderText({
|
||||
host: this.node,
|
||||
source: text
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A widget for displaying deprecated JavaScript output.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,6 @@ import { localize } from 'vs/nls';
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import * as azdata from 'azdata';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { DEFAULT_NOTEBOOK_FILETYPE, VSCODE_JUPYTER_PROVIDER_ID } from 'sql/workbench/common/constants';
|
||||
|
||||
export const NotebookProviderRegistryId = 'notebooks.providers.registry';
|
||||
|
||||
@@ -119,8 +118,6 @@ export interface INotebookProviderRegistry {
|
||||
|
||||
readonly onNewDescriptionRegistration: Event<{ id: string, registration: ProviderDescriptionRegistration }>;
|
||||
|
||||
updateProviderKernels(providerId: string, kernels: azdata.nb.IStandardKernel[]): void;
|
||||
updateKernelLanguages(providerId: string, kernelName: string, languages: string[]): void;
|
||||
registerProviderDescription(provider: ProviderDescriptionRegistration): void;
|
||||
registerNotebookLanguageMagic(magic: NotebookLanguageMagicRegistration): void;
|
||||
}
|
||||
@@ -132,43 +129,6 @@ class NotebookProviderRegistry implements INotebookProviderRegistry {
|
||||
private _onNewDescriptionRegistration = new Emitter<{ id: string, registration: ProviderDescriptionRegistration }>();
|
||||
public readonly onNewDescriptionRegistration: Event<{ id: string, registration: ProviderDescriptionRegistration }> = this._onNewDescriptionRegistration.event;
|
||||
|
||||
private readonly providerNotInRegistryError = (providerId: string): string => localize('providerNotInRegistryError', "The specified provider '{0}' is not present in the notebook registry.", providerId);
|
||||
|
||||
updateProviderKernels(providerId: string, kernels: azdata.nb.IStandardKernel[]): void {
|
||||
let registration = this._providerDescriptionRegistration.get(providerId);
|
||||
if (!registration) {
|
||||
// Newer versions of the Jupyter extension don't contribute a provider for the default file type, so
|
||||
// register the original provider details here to preserve backwards compatibility for .NET Interactive
|
||||
if (providerId === VSCODE_JUPYTER_PROVIDER_ID) {
|
||||
registration = {
|
||||
provider: VSCODE_JUPYTER_PROVIDER_ID,
|
||||
fileExtensions: [DEFAULT_NOTEBOOK_FILETYPE],
|
||||
standardKernels: undefined
|
||||
};
|
||||
} else {
|
||||
throw new Error(this.providerNotInRegistryError(providerId));
|
||||
}
|
||||
}
|
||||
registration.standardKernels = kernels;
|
||||
|
||||
// Update provider description with new info
|
||||
this.registerProviderDescription(registration);
|
||||
}
|
||||
|
||||
updateKernelLanguages(providerId: string, kernelName: string, languages: string[]): void {
|
||||
let registration = this._providerDescriptionRegistration.get(providerId);
|
||||
if (!registration) {
|
||||
throw new Error(this.providerNotInRegistryError(providerId));
|
||||
}
|
||||
let kernel = registration.standardKernels?.find(kernel => kernel.name === kernelName);
|
||||
if (kernel) {
|
||||
kernel.supportedLanguages = languages;
|
||||
}
|
||||
|
||||
// Update provider description with new info
|
||||
this.registerProviderDescription(registration);
|
||||
}
|
||||
|
||||
registerProviderDescription(registration: ProviderDescriptionRegistration): void {
|
||||
this._providerDescriptionRegistration.set(registration.provider, registration);
|
||||
this._onNewDescriptionRegistration.fire({ id: registration.provider, registration: registration });
|
||||
|
||||
Reference in New Issue
Block a user