提交 990cc855 编写于 作者: J Johannes Rieken

add CellUri-util but don't use it yet

上级 c1ec410c
......@@ -186,6 +186,34 @@ export function generateCellPath(cellKind: CellKind, cellHandle: number): string
return `/cell_${cellHandle}${cellKind === CellKind.Markdown ? '.md' : ''}`;
}
export namespace CellUri {
export const scheme = 'vscode-notebook';
export function generate(notebook: URI, handle: number): URI {
return notebook.with({
query: JSON.stringify({ cell: handle, notebook: notebook.toString() }),
scheme,
});
}
export function parse(cell: URI): { notebook: URI, handle: number } | undefined {
if (cell.scheme !== scheme) {
return undefined;
}
try {
const data = <{ cell: number, notebook: string }>JSON.parse(cell.query);
return {
handle: data.cell,
notebook: URI.parse(data.notebook)
};
} catch {
return undefined;
}
}
}
export function parseCellHandle(path: string): number | undefined {
const regex = new RegExp(/cell_(\d*)(\.)?/g);
let matches = regex.exec(path);
......
......@@ -4,8 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { NOTEBOOK_DISPLAY_ORDER, sortMimeTypes, CellKind, diff } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NOTEBOOK_DISPLAY_ORDER, sortMimeTypes, CellKind, diff, CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { TestCell } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { URI } from 'vs/base/common/uri';
suite('NotebookCommon', () => {
test('sortMimeTypes default orders', function () {
......@@ -322,3 +323,19 @@ suite('NotebookCommon', () => {
);
});
});
suite('CellUri', function () {
test('parse, generate', function () {
const nb = URI.parse('foo:///bar/følder/file.nb');
const id = 17;
const data = CellUri.generate(nb, id);
const actual = CellUri.parse(data);
assert.ok(Boolean(actual));
assert.equal(actual?.handle, id);
assert.equal(actual?.notebook.toString(), nb.toString());
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册