Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Mar 19, 2021
1 parent 8bccb05 commit 9a5a488
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
15 changes: 3 additions & 12 deletions src/client/datascience/notebookStorage/nativeEditorStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as path from 'path';
import * as uuid from 'uuid/v4';
import { CancellationToken, Memento, Uri } from 'vscode';
import { createCodeCell } from '../../../datascience-ui/common/cellFactory';
import { IPythonExtensionChecker } from '../../api/types';
import { traceError } from '../../common/logger';
import { isFileNotFoundError } from '../../common/platform/errors';
import { IFileSystem } from '../../common/platform/types';
Expand All @@ -18,7 +17,6 @@ import { InvalidNotebookFileError } from '../jupyter/invalidNotebookFileError';
import { INotebookModelFactory } from '../notebookStorage/types';
import {
CellState,
IJupyterExecution,
IModelLoadOptions,
INotebookModel,
INotebookStorage,
Expand Down Expand Up @@ -57,15 +55,13 @@ export class NativeEditorStorage implements INotebookStorage {
private backupRequested: { model: INotebookModel; cancellation: CancellationToken } | undefined;

constructor(
@inject(IJupyterExecution) private jupyterExecution: IJupyterExecution,
@inject(IFileSystem) private fs: IFileSystem,
@inject(ICryptoUtils) private crypto: ICryptoUtils,
@inject(IExtensionContext) private context: IExtensionContext,
@inject(IMemento) @named(GLOBAL_MEMENTO) private globalStorage: Memento,
@inject(IMemento) @named(WORKSPACE_MEMENTO) private localStorage: Memento,
@inject(ITrustService) private trustService: ITrustService,
@inject(INotebookModelFactory) private readonly factory: INotebookModelFactory,
@inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker
@inject(INotebookModelFactory) private readonly factory: INotebookModelFactory
) {}
private static isUntitledFile(file: Uri) {
return isUntitledFile(file);
Expand Down Expand Up @@ -208,7 +204,7 @@ export class NativeEditorStorage implements INotebookStorage {
traceError(`Error writing storage for ${filePath}: `, exc);
}
}
private async extractPythonMainVersion(notebookData: Partial<nbformat.INotebookContent>): Promise<number> {
private extractPythonMainVersion(notebookData: Partial<nbformat.INotebookContent>): number {
if (
notebookData &&
notebookData.metadata &&
Expand All @@ -220,11 +216,6 @@ export class NativeEditorStorage implements INotebookStorage {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (notebookData.metadata.language_info.codemirror_mode as any).version;
}
// Use the active interpreter if allowed
if (this.extensionChecker.isPythonExtensionActive) {
const usableInterpreter = await this.jupyterExecution.getUsableJupyterPython();
return usableInterpreter && usableInterpreter.version ? usableInterpreter.version.major : 3;
}

return 3;
}
Expand Down Expand Up @@ -368,7 +359,7 @@ export class NativeEditorStorage implements INotebookStorage {
remapped.splice(0, 0, this.createEmptyCell(uuid()));
}
}
const pythonNumber = json ? await this.extractPythonMainVersion(json) : 3;
const pythonNumber = json ? this.extractPythonMainVersion(json) : 3;

const model = this.factory.createModel(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,13 @@ suite('DataScience - Native Editor Storage', () => {
const cellLanguageService = mock<NotebookCellLanguageService>();
when(cellLanguageService.getPreferredLanguage(anything())).thenReturn(PYTHON_LANGUAGE);
const notebookStorage = new NativeEditorStorage(
instance(executionProvider),
fileSystem.object, // Use typemoq so can save values in returns
instance(crypto),
context.object,
globalMemento,
localMemento,
instance(trustService),
new NotebookModelFactory(false, instance(mockVSC), instance(cellLanguageService)),
instance(extensionChecker)
new NotebookModelFactory(false, instance(mockVSC), instance(cellLanguageService))
);
const container = mock<IServiceContainer>();
when(container.tryGet(anything())).thenReturn(undefined);
Expand Down

0 comments on commit 9a5a488

Please sign in to comment.