mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 17:23:42 -05:00
Create untitled notebook names in core code rather than in the notebook extension (#21111)
This commit is contained in:
@@ -84,8 +84,6 @@ export const pythonWindowsInstallUrl = 'https://go.microsoft.com/fwlink/?linkid=
|
||||
export const pythonMacInstallUrl = 'https://go.microsoft.com/fwlink/?linkid=2163337';
|
||||
export const pythonLinuxInstallUrl = 'https://go.microsoft.com/fwlink/?linkid=2163336';
|
||||
|
||||
export const notebookLanguages = ['notebook', 'ipynb'];
|
||||
|
||||
export const KNOX_ENDPOINT_SERVER = 'host';
|
||||
export const KNOX_ENDPOINT_PORT = 'knoxport';
|
||||
export const KNOX_ENDPOINT_GATEWAY = 'gateway';
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as azdata from 'azdata';
|
||||
import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { getErrorMessage, isEditorTitleFree } from '../common/utils';
|
||||
import { getErrorMessage } from '../common/utils';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -20,21 +20,7 @@ export class NotebookUtils {
|
||||
constructor() { }
|
||||
|
||||
public async newNotebook(options?: azdata.nb.NotebookShowOptions): Promise<azdata.nb.NotebookEditor> {
|
||||
const title = this.findNextUntitledEditorName();
|
||||
const untitledUri = vscode.Uri.parse(`untitled:${title}`);
|
||||
return azdata.nb.showNotebookDocument(untitledUri, options);
|
||||
}
|
||||
|
||||
private findNextUntitledEditorName(): string {
|
||||
let nextVal = 0;
|
||||
// Note: this will go forever if it's coded wrong, or you have infinite Untitled notebooks!
|
||||
while (true) {
|
||||
let title = `Notebook-${nextVal}`;
|
||||
if (isEditorTitleFree(title)) {
|
||||
return title;
|
||||
}
|
||||
nextVal++;
|
||||
}
|
||||
return azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }), options);
|
||||
}
|
||||
|
||||
public async openNotebook(): Promise<void> {
|
||||
@@ -116,12 +102,7 @@ export class NotebookUtils {
|
||||
}
|
||||
|
||||
public async analyzeNotebook(oeContext?: azdata.ObjectExplorerContext): Promise<void> {
|
||||
// Ensure we get a unique ID for the notebook. For now we're using a different prefix to the built-in untitled files
|
||||
// to handle this. We should look into improving this in the future
|
||||
let title = this.findNextUntitledEditorName();
|
||||
let untitledUri = vscode.Uri.parse(`untitled:${title}`);
|
||||
|
||||
let editor = await azdata.nb.showNotebookDocument(untitledUri, {
|
||||
let editor = await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }), {
|
||||
connectionProfile: oeContext ? oeContext.connectionProfile : undefined,
|
||||
providerId: JUPYTER_NOTEBOOK_PROVIDER,
|
||||
preview: false,
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as nls from 'vscode-nls';
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as crypto from 'crypto';
|
||||
import { notebookLanguages, notebookConfigKey, pinnedBooksConfigKey, AUTHTYPE, INTEGRATED_AUTH, KNOX_ENDPOINT_PORT, KNOX_ENDPOINT_SERVER } from './constants';
|
||||
import { notebookConfigKey, pinnedBooksConfigKey, AUTHTYPE, INTEGRATED_AUTH, KNOX_ENDPOINT_PORT, KNOX_ENDPOINT_SERVER } from './constants';
|
||||
import { IPrompter, IQuestion, QuestionTypes } from '../prompts/question';
|
||||
import { BookTreeItemFormat } from '../book/bookTreeItem';
|
||||
import * as loc from './localizedConstants';
|
||||
@@ -268,13 +268,6 @@ export function isPackageSupported(pythonVersion: string, packageVersionConstrai
|
||||
return supportedVersionFound;
|
||||
}
|
||||
|
||||
export function isEditorTitleFree(title: string): boolean {
|
||||
|
||||
let hasTextDoc = vscode.workspace.textDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title && !notebookLanguages.find(lang => lang === doc.languageId)) > -1;
|
||||
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
|
||||
return !hasTextDoc && !hasNotebookDoc;
|
||||
}
|
||||
|
||||
export function getClusterEndpoints(serverInfo: azdata.ServerInfo): bdc.IEndpointModel[] {
|
||||
let endpoints: RawEndpoint[] = serverInfo.options['clusterEndpoints'];
|
||||
if (!endpoints || endpoints.length === 0) { return []; }
|
||||
|
||||
Reference in New Issue
Block a user