Skip to content

Commit

Permalink
Adopt interface change.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Apr 2, 2024
1 parent d2ff36b commit 39df90b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type * as vscode from 'vscode';
import { LinkedList } from 'vs/base/common/linkedList';
import { ILogService } from 'vs/platform/log/common/log';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';

type Listener = [Function, any, IExtensionDescription];

Expand Down Expand Up @@ -165,7 +166,7 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
}

if (version === document.version) {
return this._mainThreadBulkEdits.$tryApplyWorkspaceEdit(dto);
return this._mainThreadBulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers(dto));
}

return Promise.reject(new Error('concurrent_edits'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebo
import { TextDocumentSaveReason, WorkspaceEdit as WorksapceEditConverter } from 'vs/workbench/api/common/extHostTypeConverters';
import { WorkspaceEdit } from 'vs/workbench/api/common/extHostTypes';
import { SaveReason } from 'vs/workbench/common/editor';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { NotebookDocumentWillSaveEvent } from 'vscode';

interface IExtensionListener<E> {
Expand Down Expand Up @@ -90,6 +91,6 @@ export class ExtHostNotebookDocumentSaveParticipant implements ExtHostNotebookDo
dto.edits = dto.edits.concat(edits);
}

return this._mainThreadBulkEdits.$tryApplyWorkspaceEdit(dto);
return this._mainThreadBulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers(dto));
}
}
5 changes: 3 additions & 2 deletions src/vs/workbench/api/test/browser/extHostBulkEdits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NullLogService } from 'vs/platform/log/common/log';
import { ExtHostBulkEdits } from 'vs/workbench/api/common/extHostBulkEdits';
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';

suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {

Expand All @@ -25,8 +26,8 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {

const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadBulkEdits, new class extends mock<MainThreadBulkEditsShape>() {
override $tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceEditDto): Promise<boolean> {
workspaceResourceEdits = _workspaceResourceEdits;
override $tryApplyWorkspaceEdit(_workspaceResourceEdits: SerializableObjectWithBuffers<IWorkspaceEditDto>): Promise<boolean> {
workspaceResourceEdits = _workspaceResourceEdits.value;
return Promise.resolve(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { mock } from 'vs/base/test/common/mock';
import { NullLogService } from 'vs/platform/log/common/log';
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';

function timeout(n: number) {
return new Promise(resolve => setTimeout(resolve, n));
Expand Down Expand Up @@ -257,8 +258,8 @@ suite('ExtHostDocumentSaveParticipant', () => {

let dto: IWorkspaceEditDto;
const participant = new ExtHostDocumentSaveParticipant(nullLogService, documents, new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyWorkspaceEdit(_edits: IWorkspaceEditDto) {
dto = _edits;
$tryApplyWorkspaceEdit(_edits: SerializableObjectWithBuffers<IWorkspaceEditDto>) {
dto = _edits.value;
return Promise.resolve(true);
}
});
Expand All @@ -281,8 +282,8 @@ suite('ExtHostDocumentSaveParticipant', () => {

let edits: IWorkspaceEditDto;
const participant = new ExtHostDocumentSaveParticipant(nullLogService, documents, new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyWorkspaceEdit(_edits: IWorkspaceEditDto) {
edits = _edits;
$tryApplyWorkspaceEdit(_edits: SerializableObjectWithBuffers<IWorkspaceEditDto>) {
edits = _edits.value;
return Promise.resolve(true);
}
});
Expand Down Expand Up @@ -318,9 +319,9 @@ suite('ExtHostDocumentSaveParticipant', () => {
test('event delivery, two listeners -> two document states', () => {

const participant = new ExtHostDocumentSaveParticipant(nullLogService, documents, new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyWorkspaceEdit(dto: IWorkspaceEditDto) {
$tryApplyWorkspaceEdit(dto: SerializableObjectWithBuffers<IWorkspaceEditDto>) {

for (const edit of dto.edits) {
for (const edit of dto.value.edits) {

const uri = URI.revive((<IWorkspaceTextEditDto>edit).resource);
const { text, range } = (<IWorkspaceTextEditDto>edit).textEdit;
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/api/test/browser/mainThreadEditors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { BulkEditService } from 'vs/workbench/contrib/bulkEdit/browser/bulkEditS
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { LabelService } from 'vs/workbench/services/label/common/labelService';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
Expand Down Expand Up @@ -204,7 +205,7 @@ suite('MainThreadEditors', () => {
// Act as if the user edited the model
model.applyEdits([EditOperation.insert(new Position(0, 0), 'something')]);

return bulkEdits.$tryApplyWorkspaceEdit({ edits: [workspaceResourceEdit] }).then((result) => {
return bulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers({ edits: [workspaceResourceEdit] })).then((result) => {
assert.strictEqual(result, false);
});
});
Expand All @@ -230,25 +231,25 @@ suite('MainThreadEditors', () => {
}
};

const p1 = bulkEdits.$tryApplyWorkspaceEdit({ edits: [workspaceResourceEdit1] }).then((result) => {
const p1 = bulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers({ edits: [workspaceResourceEdit1] })).then((result) => {
// first edit request succeeds
assert.strictEqual(result, true);
});
const p2 = bulkEdits.$tryApplyWorkspaceEdit({ edits: [workspaceResourceEdit2] }).then((result) => {
const p2 = bulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers({ edits: [workspaceResourceEdit2] })).then((result) => {
// second edit request fails
assert.strictEqual(result, false);
});
return Promise.all([p1, p2]);
});

test(`applyWorkspaceEdit with only resource edit`, () => {
return bulkEdits.$tryApplyWorkspaceEdit({
return bulkEdits.$tryApplyWorkspaceEdit(new SerializableObjectWithBuffers({
edits: [
{ oldResource: resource, newResource: resource, options: undefined },
{ oldResource: undefined, newResource: resource, options: undefined },
{ oldResource: resource, newResource: undefined, options: undefined }
]
}).then((result) => {
})).then((result) => {
assert.strictEqual(result, true);
assert.strictEqual(movedResources.get(resource), resource);
assert.strictEqual(createdResources.has(resource), true);
Expand Down

0 comments on commit 39df90b

Please sign in to comment.