Notebook cleanup (#20954)

This commit is contained in:
Charles Gagnon
2022-10-24 15:32:42 -07:00
committed by GitHub
parent a64a33e091
commit 5032685162
4 changed files with 25 additions and 16 deletions

View File

@@ -41,8 +41,6 @@ export const RESOURCE_VIEWER_TYPEID = 'workbench.editorInput.resourceViewerInput
export const JUPYTER_PROVIDER_ID = 'jupyter'; export const JUPYTER_PROVIDER_ID = 'jupyter';
export const IPYKERNEL_DISPLAY_NAME = 'Python 3 (ipykernel)'; export const IPYKERNEL_DISPLAY_NAME = 'Python 3 (ipykernel)';
export const INTERACTIVE_PROVIDER_ID = 'dotnet-interactive'; export const INTERACTIVE_PROVIDER_ID = 'dotnet-interactive';
export const INTERACTIVE_LANGUAGE_MODE = 'dib';
export const DEFAULT_NB_LANGUAGE_MODE = 'notebook';
export const TSGOPS_WEB_QUALITY = 'tsgops-image'; export const TSGOPS_WEB_QUALITY = 'tsgops-image';
export const CELL_URI_PATH_PREFIX = 'notebook-editor-'; export const CELL_URI_PATH_PREFIX = 'notebook-editor-';
@@ -52,7 +50,8 @@ export const NBFORMAT_MINOR = 2;
export const enum NotebookLanguage { export const enum NotebookLanguage {
Notebook = 'notebook', Notebook = 'notebook',
Ipynb = 'ipynb' Ipynb = 'ipynb',
Interactive = 'dib'
} }
export interface INotebookSearchConfigurationProperties { export interface INotebookSearchConfigurationProperties {
exclude: glob.IExpression; exclude: glob.IExpression;

View File

@@ -458,11 +458,11 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
private async assignProviders(): Promise<void> { private async assignProviders(): Promise<void> {
await this.extensionService.whenInstalledExtensionsRegistered(); await this.extensionService.whenInstalledExtensionsRegistered();
let mode: string; let languageId: string | undefined = undefined;
if (this._textInput instanceof UntitledTextEditorInput) { if (this._textInput instanceof UntitledTextEditorInput) {
mode = this._textInput.model.getLanguageId(); languageId = this._textInput.model.getLanguageId();
} }
let providerIds: string[] = getProvidersForFileName(this._title, this.notebookService, mode); let providerIds: string[] = getProvidersForFileName(this._title, this.notebookService, languageId);
if (providerIds && providerIds.length > 0) { if (providerIds && providerIds.length > 0) {
this._providerId = providerIds.filter(provider => provider !== DEFAULT_NOTEBOOK_PROVIDER)[0]; this._providerId = providerIds.filter(provider => provider !== DEFAULT_NOTEBOOK_PROVIDER)[0];
this._providers = providerIds; this._providers = providerIds;

View File

@@ -7,7 +7,7 @@ import * as path from 'vs/base/common/path';
import { nb, ServerInfo } from 'azdata'; import { nb, ServerInfo } from 'azdata';
import { DEFAULT_NOTEBOOK_PROVIDER, DEFAULT_NOTEBOOK_FILETYPE, INotebookService, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/browser/notebookService'; import { DEFAULT_NOTEBOOK_PROVIDER, DEFAULT_NOTEBOOK_FILETYPE, INotebookService, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/browser/notebookService';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { DEFAULT_NB_LANGUAGE_MODE } from 'sql/workbench/common/constants'; import { NotebookLanguage } from 'sql/workbench/common/constants';
export const clusterEndpointsProperty = 'clusterEndpoints'; export const clusterEndpointsProperty = 'clusterEndpoints';
export const hadoopEndpointNameGateway = 'gateway'; export const hadoopEndpointNameGateway = 'gateway';
@@ -18,10 +18,10 @@ export function isStream(output: nb.ICellOutput): output is nb.IStreamResult {
return output.output_type === 'stream'; return output.output_type === 'stream';
} }
export function getProvidersForFileName(fileName: string, notebookService: INotebookService, languageMode?: string): string[] { export function getProvidersForFileName(fileName: string, notebookService: INotebookService, languageId?: string): string[] {
let fileExt = path.extname(fileName); let fileExt = path.extname(fileName);
if (!fileExt && languageMode && languageMode !== DEFAULT_NB_LANGUAGE_MODE) { if (!fileExt && languageId && languageId !== NotebookLanguage.Notebook) {
fileExt = `.${languageMode}`; fileExt = `.${languageId}`;
} }
let providers: string[]; let providers: string[];
// First try to get provider for actual file type // First try to get provider for actual file type

View File

@@ -47,10 +47,10 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IExistingUntitledTextEditorOptions, INewUntitledTextEditorWithAssociatedResourceOptions, IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; import { IExistingUntitledTextEditorOptions, INewUntitledTextEditorWithAssociatedResourceOptions, IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorPane } from 'vs/workbench/common/editor'; import { IEditorPane, IUntypedFileEditorInput } from 'vs/workbench/common/editor';
import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface'; import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface';
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol'; import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
import { DEFAULT_NB_LANGUAGE_MODE, INTERACTIVE_LANGUAGE_MODE, INTERACTIVE_PROVIDER_ID, NotebookLanguage } from 'sql/workbench/common/constants'; import { INTERACTIVE_PROVIDER_ID, NotebookLanguage } from 'sql/workbench/common/constants';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { SqlSerializationProvider } from 'sql/workbench/services/notebook/browser/sql/sqlSerializationProvider'; import { SqlSerializationProvider } from 'sql/workbench/services/notebook/browser/sql/sqlSerializationProvider';
import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -292,7 +292,7 @@ export class NotebookService extends Disposable implements INotebookService {
let isUntitled: boolean = uri.scheme === Schemas.untitled; let isUntitled: boolean = uri.scheme === Schemas.untitled;
let fileInput: EditorInput; let fileInput: EditorInput;
let languageMode = options.providerId === INTERACTIVE_PROVIDER_ID ? INTERACTIVE_LANGUAGE_MODE : DEFAULT_NB_LANGUAGE_MODE; let languageId = options.providerId === INTERACTIVE_PROVIDER_ID ? NotebookLanguage.Interactive : NotebookLanguage.Notebook;
let initialStringContents: string; let initialStringContents: string;
if (options.initialContent) { if (options.initialContent) {
if (typeof options.initialContent === 'string') { if (typeof options.initialContent === 'string') {
@@ -303,14 +303,24 @@ export class NotebookService extends Disposable implements INotebookService {
} }
} }
if (isUntitled && path.isAbsolute(uri.fsPath)) { if (isUntitled && path.isAbsolute(uri.fsPath)) {
const model = this._untitledEditorService.create(<INewUntitledTextEditorWithAssociatedResourceOptions>{ associatedResource: uri, languageId: languageMode, initialValue: initialStringContents }); const options: INewUntitledTextEditorWithAssociatedResourceOptions = {
associatedResource: uri,
languageId,
initialValue: initialStringContents
}
const model = this._untitledEditorService.create(options);
fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model); fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model);
} else { } else {
if (isUntitled) { if (isUntitled) {
const model = this._untitledEditorService.create(<IExistingUntitledTextEditorOptions>{ untitledResource: uri, languageId: languageMode, initialValue: initialStringContents }); const options: IExistingUntitledTextEditorOptions = {
untitledResource: uri,
languageId,
initialValue: initialStringContents
}
const model = this._untitledEditorService.create(options);
fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model); fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model);
} else { } else {
let input: any = { forceFile: true, resource: uri, languageId: languageMode }; let input: IUntypedFileEditorInput = { forceFile: true, resource: uri, languageId };
fileInput = await this._editorService.createEditorInput(input); fileInput = await this._editorService.createEditorInput(input);
} }
} }