Skip to content

Commit

Permalink
All languages in native notebooks, default Python (#13786)
Browse files Browse the repository at this point in the history
* All languages in native notebooks, default Python
* Fix tests
  • Loading branch information
DonJayamanne authored Sep 4, 2020
1 parent f41bef9 commit 49f160a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/client/datascience/notebook/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { JupyterNotebookView } from '../constants';
const vscodeNotebookEnums = require('vscode') as typeof import('vscode-proposed');
// tslint:disable-next-line: no-require-imports
import cloneDeep = require('lodash/cloneDeep');
import { isUntitledFile } from '../../../common/utils/misc';
import { KernelConnectionMetadata } from '../../jupyter/kernels/types';
import { updateNotebookMetadata } from '../../notebookStorage/baseModel';
import { VSCodeNotebookModel } from '../../notebookStorage/vscNotebookModel';
Expand Down Expand Up @@ -95,9 +96,18 @@ export function notebookModelToVSCNotebookData(model: VSCodeNotebookModel): Note
.map((item) => item!);

const defaultLanguage = getDefaultCodeLanguage(model);
if (cells.length === 0 && isUntitledFile(model.file)) {
cells.push({
cellKind: vscodeNotebookEnums.CellKind.Code,
language: defaultLanguage,
metadata: {},
outputs: [],
source: ''
});
}
return {
cells,
languages: [defaultLanguage],
languages: ['*'],
metadata: {
custom: model.notebookContentWithoutCells,
cellEditable: model.isTrusted,
Expand Down
4 changes: 2 additions & 2 deletions src/test/datascience/notebook/contentProvider.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ suite('DataScience - NativeNotebook ContentProvider', () => {
const notebook = await contentProvider.openNotebook(fileUri, {});

assert.isOk(notebook);
assert.deepEqual(notebook.languages, [PYTHON_LANGUAGE]);
assert.deepEqual(notebook.languages, ['*']);
// ignore metadata we add.
const cellsWithoutCustomMetadata = notebook.cells.map((cell) => {
const cellToCompareWith = cloneDeep(cell);
Expand Down Expand Up @@ -142,7 +142,7 @@ suite('DataScience - NativeNotebook ContentProvider', () => {
const notebook = await contentProvider.openNotebook(fileUri, {});

assert.isOk(notebook);
assert.deepEqual(notebook.languages, ['csharp']);
assert.deepEqual(notebook.languages, ['*']);

assert.equal(notebook.metadata.cellEditable, isNotebookTrusted);
assert.equal(notebook.metadata.cellRunnable, isNotebookTrusted);
Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/notebook/helpers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ suite('DataScience - NativeNotebook helpers', () => {
const notebook = notebookModelToVSCNotebookData(model as any);

assert.isOk(notebook);
assert.deepEqual(notebook.languages, [PYTHON_LANGUAGE]);
assert.deepEqual(notebook.languages, ['*']);
// ignore metadata we add.
const cellsWithoutCustomMetadata = notebook.cells.map((cell) => {
const cellToCompareWith = cloneDeep(cell);
Expand Down

0 comments on commit 49f160a

Please sign in to comment.