mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 01:32:34 -05:00
Merge from vscode ad407028575a77ea387eb7cc219b323dc017b686
This commit is contained in:
committed by
Anthony Dresser
parent
404260b8a0
commit
4ad73d381c
@@ -35,7 +35,7 @@ suite('ExtHostDocumentData', () => {
|
||||
'and this is line number two', //27
|
||||
'it is followed by #3', //20
|
||||
'and finished with the fourth.', //29
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
});
|
||||
|
||||
test('readonly-ness', () => {
|
||||
@@ -55,7 +55,7 @@ suite('ExtHostDocumentData', () => {
|
||||
saved = uri;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}, URI.parse('foo:bar'), [], '\n', 'text', 1, true);
|
||||
}, URI.parse('foo:bar'), [], '\n', 1, 'text', true);
|
||||
|
||||
return data.document.save().then(() => {
|
||||
assert.equal(saved.toString(), 'foo:bar');
|
||||
@@ -242,7 +242,7 @@ suite('ExtHostDocumentData', () => {
|
||||
test('getWordRangeAtPosition', () => {
|
||||
data = new ExtHostDocumentData(undefined!, URI.file(''), [
|
||||
'aaaa bbbb+cccc abc'
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
|
||||
let range = data.document.getWordRangeAtPosition(new Position(0, 2))!;
|
||||
assert.equal(range.start.line, 0);
|
||||
@@ -276,7 +276,7 @@ suite('ExtHostDocumentData', () => {
|
||||
'function() {',
|
||||
' "far boo"',
|
||||
'}'
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
|
||||
let range = data.document.getWordRangeAtPosition(new Position(0, 0), /\/\*.+\*\//);
|
||||
assert.equal(range, undefined);
|
||||
@@ -304,7 +304,7 @@ suite('ExtHostDocumentData', () => {
|
||||
|
||||
data = new ExtHostDocumentData(undefined!, URI.file(''), [
|
||||
perfData._$_$_expensive
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
|
||||
let range = data.document.getWordRangeAtPosition(new Position(0, 1_177_170), regex)!;
|
||||
assert.equal(range, undefined);
|
||||
@@ -323,7 +323,7 @@ suite('ExtHostDocumentData', () => {
|
||||
|
||||
data = new ExtHostDocumentData(undefined!, URI.file(''), [
|
||||
line
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
|
||||
let range = data.document.getWordRangeAtPosition(new Position(0, 27), regex)!;
|
||||
assert.equal(range.start.line, 0);
|
||||
@@ -387,7 +387,7 @@ suite('ExtHostDocumentData updates line mapping', () => {
|
||||
}
|
||||
|
||||
function testLineMappingDirectionAfterEvents(lines: string[], eol: string, direction: AssertDocumentLineMappingDirection, e: IModelChangedEvent): void {
|
||||
let myDocument = new ExtHostDocumentData(undefined!, URI.file(''), lines.slice(0), eol, 'text', 1, false);
|
||||
let myDocument = new ExtHostDocumentData(undefined!, URI.file(''), lines.slice(0), eol, 1, 'text', false);
|
||||
assertDocumentLineMapping(myDocument, direction);
|
||||
|
||||
myDocument.onEvents(e);
|
||||
|
||||
@@ -4,148 +4,248 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
|
||||
import { TestRPCProtocol } from 'vs/workbench/test/browser/api/testRPCProtocol';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostNotebookDocument, ExtHostCell } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { IModelAddedData, MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostNotebookDocument, ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { CellKind, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { isEqual } from 'vs/base/common/resources';
|
||||
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
|
||||
suite('NotebookCell#Document', function () {
|
||||
|
||||
suite('NotebookCell', function () {
|
||||
|
||||
let rpcProtocol: TestRPCProtocol;
|
||||
let notebook: ExtHostNotebookDocument;
|
||||
let extHostDocumentsAndEditors: ExtHostDocumentsAndEditors;
|
||||
|
||||
let extHostDocuments: ExtHostDocuments;
|
||||
let extHostNotebooks: ExtHostNotebookController;
|
||||
const notebookUri = URI.parse('test:///notebook.file');
|
||||
const disposables = new DisposableStore();
|
||||
const fakeNotebookProxy = new class extends mock<MainThreadNotebookShape>() { };
|
||||
const fakeNotebook = new class extends mock<ExtHostNotebookDocument>() { };
|
||||
|
||||
setup(async function () {
|
||||
disposables.clear();
|
||||
|
||||
rpcProtocol = new TestRPCProtocol();
|
||||
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
|
||||
$registerCommand() { }
|
||||
});
|
||||
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
|
||||
async $registerNotebookProvider() { }
|
||||
async $unregisterNotebookProvider() { }
|
||||
});
|
||||
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
|
||||
});
|
||||
|
||||
test('Document is real', function () {
|
||||
|
||||
const dto = {
|
||||
cellKind: CellKind.Code,
|
||||
eol: '\n',
|
||||
source: ['aaaa', 'bbbb', 'cccc'],
|
||||
handle: 0,
|
||||
language: 'fooLang',
|
||||
outputs: [],
|
||||
uri: URI.parse('test:/path')
|
||||
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
|
||||
workspaceValue() {
|
||||
return URI.from({ scheme: 'test', path: generateUuid() });
|
||||
}
|
||||
};
|
||||
const cell = new ExtHostCell(fakeNotebookProxy, fakeNotebook, extHostDocumentsAndEditors, dto);
|
||||
|
||||
assert.ok(cell.document);
|
||||
assert.strictEqual(cell.document.version, 0);
|
||||
assert.strictEqual(cell.document.languageId, dto.language);
|
||||
assert.strictEqual(cell.document.uri.toString(), dto.uri.toString());
|
||||
assert.strictEqual(cell.uri.toString(), dto.uri.toString());
|
||||
});
|
||||
|
||||
|
||||
test('Document is uses actual document when possible', function () {
|
||||
|
||||
const dto = {
|
||||
cellKind: CellKind.Code,
|
||||
eol: '\n',
|
||||
source: ['aaaa', 'bbbb', 'cccc'],
|
||||
handle: 0,
|
||||
language: 'fooLang',
|
||||
outputs: [],
|
||||
uri: URI.parse('test:/path')
|
||||
};
|
||||
const cell = new ExtHostCell(fakeNotebookProxy, fakeNotebook, extHostDocumentsAndEditors, dto);
|
||||
|
||||
// this is the "default document" which is used when the real
|
||||
// document isn't open
|
||||
const documentNow = cell.document;
|
||||
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
|
||||
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
|
||||
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
|
||||
// async openNotebook() { }
|
||||
});
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
isDirty: false,
|
||||
versionId: 12,
|
||||
modeId: dto.language,
|
||||
uri: dto.uri,
|
||||
lines: dto.source,
|
||||
EOL: dto.eol
|
||||
handle: 0,
|
||||
uri: notebookUri,
|
||||
viewType: 'test',
|
||||
versionId: 0,
|
||||
cells: [{
|
||||
handle: 0,
|
||||
uri: CellUri.generate(notebookUri, 0),
|
||||
source: ['### Heading'],
|
||||
eol: '\n',
|
||||
language: 'markdown',
|
||||
cellKind: CellKind.Markdown,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebookUri, 1),
|
||||
source: ['console.log("aaa")', 'console.log("bbb")'],
|
||||
eol: '\n',
|
||||
language: 'javascript',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}],
|
||||
}],
|
||||
addedEditors: [{
|
||||
documentUri: notebookUri,
|
||||
id: '_notebook_editor_0',
|
||||
selections: [0]
|
||||
}]
|
||||
});
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
|
||||
|
||||
// the real document
|
||||
assert.ok(documentNow !== cell.document);
|
||||
assert.strictEqual(cell.document.languageId, dto.language);
|
||||
assert.strictEqual(cell.document.uri.toString(), dto.uri.toString());
|
||||
assert.strictEqual(cell.uri.toString(), dto.uri.toString());
|
||||
notebook = extHostNotebooks.notebookDocuments[0]!;
|
||||
|
||||
// back to "default document"
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: [dto.uri] });
|
||||
assert.ok(documentNow === cell.document);
|
||||
});
|
||||
|
||||
test('Document can change language (1/2)', function () {
|
||||
|
||||
const dto = {
|
||||
cellKind: CellKind.Code,
|
||||
eol: '\n',
|
||||
source: ['aaaa', 'bbbb', 'cccc'],
|
||||
handle: 0,
|
||||
language: 'fooLang',
|
||||
outputs: [],
|
||||
uri: URI.parse('test:/path')
|
||||
};
|
||||
const cell = new ExtHostCell(fakeNotebookProxy, fakeNotebook, extHostDocumentsAndEditors, dto);
|
||||
|
||||
assert.strictEqual(cell.document.languageId, dto.language);
|
||||
cell.defaultDocument._acceptLanguageId('barLang');
|
||||
assert.strictEqual(cell.document.languageId, 'barLang');
|
||||
disposables.add(reg);
|
||||
disposables.add(notebook);
|
||||
disposables.add(extHostDocuments);
|
||||
});
|
||||
|
||||
|
||||
test('Document can change language (1/2)', function () {
|
||||
test('cell document is vscode.TextDocument', async function () {
|
||||
|
||||
assert.strictEqual(notebook.cells.length, 2);
|
||||
|
||||
const dto = {
|
||||
cellKind: CellKind.Code,
|
||||
eol: '\n',
|
||||
source: ['aaaa', 'bbbb', 'cccc'],
|
||||
handle: 0,
|
||||
language: 'fooLang',
|
||||
outputs: [],
|
||||
uri: URI.parse('test:/path')
|
||||
};
|
||||
const [c1, c2] = notebook.cells;
|
||||
const d1 = extHostDocuments.getDocument(c1.uri);
|
||||
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
isDirty: false,
|
||||
versionId: 12,
|
||||
modeId: dto.language,
|
||||
uri: dto.uri,
|
||||
lines: dto.source,
|
||||
EOL: dto.eol
|
||||
}]
|
||||
assert.ok(d1);
|
||||
assert.equal(d1.languageId, c1.language);
|
||||
assert.equal(d1.version, 1);
|
||||
assert.ok(d1.notebook === notebook);
|
||||
|
||||
const d2 = extHostDocuments.getDocument(c2.uri);
|
||||
assert.ok(d2);
|
||||
assert.equal(d2.languageId, c2.language);
|
||||
assert.equal(d2.version, 1);
|
||||
assert.ok(d2.notebook === notebook);
|
||||
});
|
||||
|
||||
test('cell document goes when notebook closes', async function () {
|
||||
const cellUris: string[] = [];
|
||||
for (let cell of notebook.cells) {
|
||||
assert.ok(extHostDocuments.getDocument(cell.uri));
|
||||
cellUris.push(cell.uri.toString());
|
||||
}
|
||||
|
||||
const removedCellUris: string[] = [];
|
||||
const reg = extHostDocuments.onDidRemoveDocument(doc => {
|
||||
removedCellUris.push(doc.uri.toString());
|
||||
});
|
||||
|
||||
const extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
|
||||
reg.dispose();
|
||||
|
||||
const cell = new ExtHostCell(fakeNotebookProxy, fakeNotebook, extHostDocumentsAndEditors, dto);
|
||||
|
||||
// a real document already exists and therefore
|
||||
// the "default document" doesn't count
|
||||
|
||||
assert.strictEqual(cell.document.languageId, dto.language);
|
||||
cell.defaultDocument._acceptLanguageId('barLang');
|
||||
assert.strictEqual(cell.document.languageId, dto.language);
|
||||
|
||||
extHostDocuments.$acceptModelModeChanged(dto.uri, dto.language, 'barLang');
|
||||
assert.strictEqual(cell.document.languageId, 'barLang');
|
||||
assert.strictEqual(removedCellUris.length, 2);
|
||||
assert.deepStrictEqual(removedCellUris.sort(), cellUris.sort());
|
||||
});
|
||||
|
||||
test('cell document is vscode.TextDocument after changing it', async function () {
|
||||
|
||||
const p = new Promise((resolve, reject) => {
|
||||
extHostNotebooks.onDidChangeNotebookCells(e => {
|
||||
try {
|
||||
assert.strictEqual(e.changes.length, 1);
|
||||
assert.strictEqual(e.changes[0].items.length, 2);
|
||||
|
||||
const [first, second] = e.changes[0].items;
|
||||
|
||||
const doc1 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, first.uri));
|
||||
assert.ok(doc1);
|
||||
assert.strictEqual(doc1?.document === first.document, true);
|
||||
|
||||
const doc2 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, second.uri));
|
||||
assert.ok(doc2);
|
||||
assert.strictEqual(doc2?.document === second.document, true);
|
||||
|
||||
resolve();
|
||||
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
kind: NotebookCellsChangeType.ModelChange,
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebookUri, 2),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
eol: '\n',
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 3,
|
||||
uri: CellUri.generate(notebookUri, 3),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
eol: '\n',
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
await p;
|
||||
|
||||
});
|
||||
|
||||
test('cell document stays open when notebook is still open', async function () {
|
||||
|
||||
const docs: vscode.TextDocument[] = [];
|
||||
const addData: IModelAddedData[] = [];
|
||||
for (let cell of notebook.cells) {
|
||||
const doc = extHostDocuments.getDocument(cell.uri);
|
||||
assert.ok(doc);
|
||||
assert.equal(extHostDocuments.getDocument(cell.uri).isClosed, false);
|
||||
docs.push(doc);
|
||||
addData.push({
|
||||
EOL: '\n',
|
||||
isDirty: doc.isDirty,
|
||||
lines: doc.getText().split('\n'),
|
||||
modeId: doc.languageId,
|
||||
uri: doc.uri,
|
||||
versionId: doc.version
|
||||
});
|
||||
}
|
||||
|
||||
// this call happens when opening a document on the main side
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ addedDocuments: addData });
|
||||
|
||||
// this call happens when closing a document from the main side
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: docs.map(d => d.uri) });
|
||||
|
||||
// notebook is still open -> cell documents stay open
|
||||
for (let cell of notebook.cells) {
|
||||
assert.ok(extHostDocuments.getDocument(cell.uri));
|
||||
assert.equal(extHostDocuments.getDocument(cell.uri).isClosed, false);
|
||||
}
|
||||
|
||||
// close notebook -> docs are closed
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
|
||||
for (let cell of notebook.cells) {
|
||||
assert.throws(() => extHostDocuments.getDocument(cell.uri));
|
||||
}
|
||||
for (let doc of docs) {
|
||||
assert.equal(doc.isClosed, true);
|
||||
}
|
||||
});
|
||||
|
||||
test('cell document goes when cell is removed', async function () {
|
||||
|
||||
assert.equal(notebook.cells.length, 2);
|
||||
const [cell1, cell2] = notebook.cells;
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebook.uri, {
|
||||
kind: NotebookCellsChangeType.ModelChange,
|
||||
versionId: 2,
|
||||
changes: [[0, 1, []]]
|
||||
});
|
||||
|
||||
assert.equal(notebook.cells.length, 1);
|
||||
assert.equal(cell1.document.isClosed, true); // ref still alive!
|
||||
assert.equal(cell2.document.isClosed, false);
|
||||
|
||||
assert.throws(() => extHostDocuments.getDocument(cell1.uri));
|
||||
});
|
||||
|
||||
test('cell document knows notebook', function () {
|
||||
for (let cells of notebook.cells) {
|
||||
assert.equal(cells.document.notebook === notebook, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,8 @@ import * as vscode from 'vscode';
|
||||
import { mock } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
|
||||
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
|
||||
suite('NotebookConcatDocument', function () {
|
||||
|
||||
@@ -44,11 +45,16 @@ suite('NotebookConcatDocument', function () {
|
||||
});
|
||||
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
|
||||
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' });
|
||||
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
|
||||
workspaceValue() {
|
||||
return URI.from({ scheme: 'test', path: generateUuid() });
|
||||
}
|
||||
};
|
||||
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
|
||||
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
|
||||
// async openNotebook() { }
|
||||
});
|
||||
await extHostNotebooks.$acceptDocumentAndEditorsDelta({
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
handle: 0,
|
||||
uri: notebookUri,
|
||||
@@ -72,7 +78,7 @@ suite('NotebookConcatDocument', function () {
|
||||
}
|
||||
]
|
||||
});
|
||||
await extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
|
||||
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
|
||||
|
||||
notebook = extHostNotebooks.notebookDocuments[0]!;
|
||||
|
||||
@@ -292,17 +298,6 @@ suite('NotebookConcatDocument', function () {
|
||||
let cell1End = doc.offsetAt(new Position(2, 12));
|
||||
assert.equal(doc.positionAt(cell1End).isEqual(new Position(2, 12)), true);
|
||||
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
uri: notebook.cells[0].uri,
|
||||
versionId: 1,
|
||||
lines: ['Hello', 'World', 'Hello World!'],
|
||||
EOL: '\n',
|
||||
modeId: '',
|
||||
isDirty: false
|
||||
}]
|
||||
});
|
||||
|
||||
extHostDocuments.$acceptModelChanged(notebook.cells[0].uri, {
|
||||
versionId: 0,
|
||||
eol: '\n',
|
||||
|
||||
@@ -17,7 +17,7 @@ suite('ExtHostTextEditor', () => {
|
||||
let editor: ExtHostTextEditor;
|
||||
let doc = new ExtHostDocumentData(undefined!, URI.file(''), [
|
||||
'aaaa bbbb+cccc abc'
|
||||
], '\n', 'text', 1, false);
|
||||
], '\n', 1, 'text', false);
|
||||
|
||||
setup(() => {
|
||||
editor = new ExtHostTextEditor('fake', null!, new NullLogService(), doc, [], { cursorStyle: 0, insertSpaces: true, lineNumbers: 1, tabSize: 4, indentSize: 4 }, [], 1);
|
||||
|
||||
@@ -203,7 +203,8 @@ suite('ExtHostTreeView', function () {
|
||||
assert.deepEqual(actuals, ['1/a', '1/b']);
|
||||
return testObject.$getChildren('testNodeWithIdTreeProvider', '1/a')
|
||||
.then(() => testObject.$getChildren('testNodeWithIdTreeProvider', '1/b'))
|
||||
.then(() => { assert.fail('Should fail with duplicate id'); done(); }, () => done());
|
||||
.then(() => assert.fail('Should fail with duplicate id'))
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
onDidChangeTreeNode.fire(undefined);
|
||||
|
||||
@@ -45,7 +45,7 @@ suite('ExtHostTypeConverter', function () {
|
||||
data = MarkdownString.from('hello@foo.bar');
|
||||
assert.equal(data.value, 'hello@foo.bar');
|
||||
assert.equal(size(data.uris!), 1);
|
||||
assert.ok(!!data.uris!['mailto:hello@foo.bar']);
|
||||
// assert.ok(!!data.uris!['mailto:hello@foo.bar']);
|
||||
|
||||
data = MarkdownString.from('*hello* [click](command:me)');
|
||||
assert.equal(data.value, '*hello* [click](command:me)');
|
||||
|
||||
@@ -3,33 +3,28 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as vscode from 'vscode';
|
||||
import * as assert from 'assert';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { MainThreadWebviews } from 'vs/workbench/api/browser/mainThreadWebview';
|
||||
import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview';
|
||||
import { EditorViewColumn } from 'vs/workbench/api/common/shared/editor';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { SingleProxyRPCProtocol } from './testRPCProtocol';
|
||||
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { NullApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview';
|
||||
import { ExtHostWebviewSerializer } from 'vs/workbench/api/common/extHostWebviewSerializer';
|
||||
import { EditorViewColumn } from 'vs/workbench/api/common/shared/editor';
|
||||
import type * as vscode from 'vscode';
|
||||
import { SingleProxyRPCProtocol } from './testRPCProtocol';
|
||||
|
||||
suite('ExtHostWebview', () => {
|
||||
|
||||
let rpcProtocol: (IExtHostRpcService & IExtHostContext) | undefined;
|
||||
let extHostDocuments: ExtHostDocuments | undefined;
|
||||
|
||||
setup(() => {
|
||||
const shape = createNoopMainThreadWebviews();
|
||||
rpcProtocol = SingleProxyRPCProtocol(shape);
|
||||
|
||||
const extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
|
||||
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
});
|
||||
|
||||
test('Cannot register multiple serializers for the same view type', async () => {
|
||||
@@ -39,7 +34,9 @@ suite('ExtHostWebview', () => {
|
||||
webviewCspSource: '',
|
||||
webviewResourceRoot: '',
|
||||
isExtensionDevelopmentDebug: false,
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService, extHostDocuments!);
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService);
|
||||
|
||||
const extHostWebviewSerializer = new ExtHostWebviewSerializer(rpcProtocol!, extHostWebviews);
|
||||
|
||||
let lastInvokedDeserializer: vscode.WebviewPanelSerializer | undefined = undefined;
|
||||
|
||||
@@ -54,20 +51,20 @@ suite('ExtHostWebview', () => {
|
||||
const serializerA = new NoopSerializer();
|
||||
const serializerB = new NoopSerializer();
|
||||
|
||||
const serializerARegistration = extHostWebviews.registerWebviewPanelSerializer(extension, viewType, serializerA);
|
||||
const serializerARegistration = extHostWebviewSerializer.registerWebviewPanelSerializer(extension, viewType, serializerA);
|
||||
|
||||
await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorViewColumn, {});
|
||||
await extHostWebviewSerializer.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorViewColumn, {});
|
||||
assert.strictEqual(lastInvokedDeserializer, serializerA);
|
||||
|
||||
assert.throws(
|
||||
() => extHostWebviews.registerWebviewPanelSerializer(extension, viewType, serializerB),
|
||||
() => extHostWebviewSerializer.registerWebviewPanelSerializer(extension, viewType, serializerB),
|
||||
'Should throw when registering two serializers for the same view');
|
||||
|
||||
serializerARegistration.dispose();
|
||||
|
||||
extHostWebviews.registerWebviewPanelSerializer(extension, viewType, serializerB);
|
||||
extHostWebviewSerializer.registerWebviewPanelSerializer(extension, viewType, serializerB);
|
||||
|
||||
await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorViewColumn, {});
|
||||
await extHostWebviewSerializer.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorViewColumn, {});
|
||||
assert.strictEqual(lastInvokedDeserializer, serializerB);
|
||||
});
|
||||
|
||||
@@ -76,7 +73,7 @@ suite('ExtHostWebview', () => {
|
||||
webviewCspSource: '',
|
||||
webviewResourceRoot: 'vscode-resource://{{resource}}',
|
||||
isExtensionDevelopmentDebug: false,
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService, extHostDocuments!);
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService);
|
||||
const webview = extHostWebviews.createWebviewPanel({} as any, 'type', 'title', 1, {});
|
||||
|
||||
assert.strictEqual(
|
||||
@@ -115,7 +112,7 @@ suite('ExtHostWebview', () => {
|
||||
webviewCspSource: '',
|
||||
webviewResourceRoot: `https://{{uuid}}.webview.contoso.com/commit/{{resource}}`,
|
||||
isExtensionDevelopmentDebug: false,
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService, extHostDocuments!);
|
||||
}, undefined, new NullLogService(), NullApiDeprecationService);
|
||||
const webview = extHostWebviews.createWebviewPanel({} as any, 'type', 'title', 1, {});
|
||||
|
||||
function stripEndpointUuid(input: string) {
|
||||
|
||||
@@ -63,7 +63,7 @@ class MyPart2 extends SimplePart {
|
||||
const titleContainer = append(parent, $('div'));
|
||||
const titleLabel = append(titleContainer, $('span'));
|
||||
titleLabel.id = 'myPart.title';
|
||||
titleLabel.innerHTML = 'Title';
|
||||
titleLabel.innerText = 'Title';
|
||||
|
||||
return titleContainer;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class MyPart2 extends SimplePart {
|
||||
const contentContainer = append(parent, $('div'));
|
||||
const contentSpan = append(contentContainer, $('span'));
|
||||
contentSpan.id = 'myPart.content';
|
||||
contentSpan.innerHTML = 'Content';
|
||||
contentSpan.innerText = 'Content';
|
||||
|
||||
return contentContainer;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class MyPart3 extends SimplePart {
|
||||
const contentContainer = append(parent, $('div'));
|
||||
const contentSpan = append(contentContainer, $('span'));
|
||||
contentSpan.id = 'myPart.content';
|
||||
contentSpan.innerHTML = 'Content';
|
||||
contentSpan.innerText = 'Content';
|
||||
|
||||
return contentContainer;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,6 @@ export class TestElectronService implements IElectronService {
|
||||
async exit(code: number): Promise<void> { }
|
||||
async openDevTools(options?: Electron.OpenDevToolsOptions | undefined): Promise<void> { }
|
||||
async toggleDevTools(): Promise<void> { }
|
||||
async startCrashReporter(options: Electron.CrashReporterStartOptions): Promise<void> { }
|
||||
async resolveProxy(url: string): Promise<string | undefined> { return undefined; }
|
||||
async readClipboardText(type?: 'selection' | 'clipboard' | undefined): Promise<string> { return ''; }
|
||||
async writeClipboardText(text: string, type?: 'selection' | 'clipboard' | undefined): Promise<void> { }
|
||||
|
||||
Reference in New Issue
Block a user