Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code #10125

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions src/notebooks/controllers/kernelSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
// Licensed under the MIT License.

import { IVSCodeNotebook, ICommandManager } from '../../platform/common/application/types';
import { JVSC_EXTENSION_ID } from '../../platform/common/constants';
import { traceError } from '../../platform/logging';
import { Resource } from '../../platform/common/types';
import { getActiveInteractiveWindow } from '../../interactive-window/helpers';
import { IKernel, KernelConnectionMetadata } from '../../kernels/types';
import { IKernel } from '../../kernels/types';
import { IInteractiveWindowProvider } from '../../interactive-window/types';
import { getResourceType } from '../../platform/common/utils';
import { workspace } from 'vscode';
import { getComparisonKey } from '../../platform/vscode-path/resources';

// TODO: This should probably move to a 'notebook' subsection

/**
* Return `true` if a new kernel has been selected.
*/
Expand All @@ -33,23 +30,6 @@ export async function selectKernel(
return false;
}

export async function switchKernel(
resource: Resource,
notebooks: IVSCodeNotebook,
interactiveWindowProvider: IInteractiveWindowProvider | undefined,
commandManager: ICommandManager,
kernelMetadata: KernelConnectionMetadata
) {
const notebookEditor = findNotebookEditor(resource, notebooks, interactiveWindowProvider);
if (notebookEditor) {
return commandManager.executeCommand('notebook.selectKernel', {
id: kernelMetadata.id,
extension: JVSC_EXTENSION_ID
});
}
traceError(`Unable to select kernel as the Notebook document for ${resource} could not be identified`);
}

export function findNotebookEditor(
resource: Resource,
notebooks: IVSCodeNotebook,
Expand Down
86 changes: 1 addition & 85 deletions src/notebooks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
NotebookDocument,
NotebookCellKind,
NotebookCellExecutionState,
NotebookCellExecutionSummary,
WorkspaceEdit,
Uri,
workspace,
Expand All @@ -27,9 +26,8 @@ import fastDeepEqual = require('fast-deep-equal');
import * as path from '../platform/vscode-path/path';
import * as uriPath from '../platform/vscode-path/resources';
import { IVSCodeNotebook, IDocumentManager } from '../platform/common/application/types';
import { PYTHON_LANGUAGE, MARKDOWN_LANGUAGE } from '../platform/common/constants';
import { PYTHON_LANGUAGE } from '../platform/common/constants';
import { traceInfoIfCI, traceError, traceWarning } from '../platform/logging';
import { Resource } from '../platform/common/types';
import { getInterpreterHash } from '../platform/pythonEnvironments/info/interpreter';
import { sendTelemetryEvent } from '../telemetry';
import { splitMultilineString, concatMultilineString } from '../webviews/webview-side/common';
Expand Down Expand Up @@ -61,12 +59,6 @@ export function isJupyterNotebook(option: NotebookDocument | string) {
}
}

export function isResourceNativeNotebook(resource: Resource, notebooks: IVSCodeNotebook) {
if (!resource) {
return false;
}
return notebooks.notebookDocuments.some((item) => uriPath.isEqual(item.uri, resource));
}
export function getNotebookMetadata(document: NotebookDocument | NotebookData): nbformat.INotebookMetadata | undefined {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const notebookContent: undefined | Partial<nbformat.INotebookContent> = document.metadata?.custom as any;
Expand Down Expand Up @@ -114,27 +106,6 @@ export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) {
// Valid notebooks will have a language information in the metadata.
return kernelSpec?.language === PYTHON_LANGUAGE || metadata?.language_info?.name === PYTHON_LANGUAGE;
}
/**
* Converts a NotebookModel into VSCode friendly format.
*/
export function notebookModelToVSCNotebookData(
notebookContentWithoutCells: Exclude<Partial<nbformat.INotebookContent>, 'cells'>,
nbCells: nbformat.IBaseCell[],
preferredLanguage: string,
originalJson: Partial<nbformat.INotebookContent>
): NotebookData {
const cells = nbCells
.map((cell) => createVSCNotebookCellDataFromCell(preferredLanguage, cell))
.filter((item) => !!item)
.map((item) => item!);

if (cells.length === 0 && Object.keys(originalJson).length === 0) {
cells.push(new NotebookCellData(NotebookCellKind.Code, '', preferredLanguage));
}
const notebookData = new NotebookData(cells);
notebookData.metadata = { custom: notebookContentWithoutCells };
return notebookData;
}

export function createJupyterCellFromVSCNotebookCell(
vscCell: NotebookCell | NotebookCellData
Expand Down Expand Up @@ -200,12 +171,6 @@ function createCodeCellFromNotebookCell(cell: NotebookCell | NotebookCellData):
return codeCell;
}

function createNotebookCellDataFromRawCell(cell: nbformat.IRawCell): NotebookCellData {
const cellData = new NotebookCellData(NotebookCellKind.Code, concatMultilineString(cell.source), 'raw');
cellData.outputs = [];
cellData.metadata = { custom: getNotebookCellMetadata(cell) };
return cellData;
}
function createMarkdownCellFromNotebookCell(cell: NotebookCell | NotebookCellData): nbformat.IMarkdownCell {
const cellMetadata = cell.metadata?.custom as CellMetadata | undefined;
const markdownCell: nbformat.IMarkdownCell = {
Expand All @@ -218,35 +183,6 @@ function createMarkdownCellFromNotebookCell(cell: NotebookCell | NotebookCellDat
}
return markdownCell;
}
function createNotebookCellDataFromMarkdownCell(cell: nbformat.IMarkdownCell): NotebookCellData {
const cellData = new NotebookCellData(
NotebookCellKind.Markup,
concatMultilineString(cell.source),
MARKDOWN_LANGUAGE
);
cellData.outputs = [];
cellData.metadata = { custom: getNotebookCellMetadata(cell) };
return cellData;
}
function createNotebookCellDataFromCodeCell(cell: nbformat.ICodeCell, cellLanguage: string): NotebookCellData {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cellOutputs: nbformat.IOutput[] = Array.isArray(cell.outputs) ? cell.outputs : [];
const outputs = createVSCCellOutputsFromOutputs(cellOutputs);
const hasExecutionCount = typeof cell.execution_count === 'number' && cell.execution_count > 0;

const source = concatMultilineString(cell.source);

const executionSummary: NotebookCellExecutionSummary = hasExecutionCount
? { executionOrder: cell.execution_count as number }
: {};

const cellData = new NotebookCellData(NotebookCellKind.Code, source, cellLanguage);

cellData.outputs = outputs;
cellData.metadata = { custom: getNotebookCellMetadata(cell) };
cellData.executionSummary = executionSummary;
return cellData;
}
const orderOfMimeTypes = [
'application/vnd.*',
'application/vdom.*',
Expand Down Expand Up @@ -319,26 +255,6 @@ export function traceCellMessage(cell: NotebookCell, message: string) {
);
}

export function createVSCNotebookCellDataFromCell(
cellLanguage: string,
cell: nbformat.IBaseCell
): NotebookCellData | undefined {
switch (cell.cell_type) {
case 'raw': {
return createNotebookCellDataFromRawCell(cell as nbformat.IRawCell);
}
case 'markdown': {
return createNotebookCellDataFromMarkdownCell(cell as nbformat.IMarkdownCell);
}
case 'code': {
return createNotebookCellDataFromCodeCell(cell as nbformat.ICodeCell, cellLanguage);
}
default: {
traceError(`Conversion of Cell into VS Code NotebookCell not supported ${cell.cell_type}`);
}
}
}

export function createVSCCellOutputsFromOutputs(outputs?: nbformat.IOutput[]): NotebookCellOutput[] {
const cellOutputs: nbformat.IOutput[] = Array.isArray(outputs) ? (outputs as []) : [];
return cellOutputs.map(cellOutputToVSCCellOutput);
Expand Down
2 changes: 1 addition & 1 deletion src/notebooks/outputs/plotSaveHandler.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PlotSaveHandler {
}
const output = getOutputItem(notebook, outputId, mimeType);
if (!output) {
return traceError(`Nolot to save ${getDisplayPath(notebook.uri)}, id: ${outputId} for ${mimeType}`);
return traceError(`No plot to save ${getDisplayPath(notebook.uri)}, id: ${outputId} for ${mimeType}`);
}
if (!(mimeType.toLowerCase() in imageExtensionForMimeType)) {
return traceError(`Unsupported MimeType ${getDisplayPath(notebook.uri)}, id: ${outputId} for ${mimeType}`);
Expand Down