Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output vsbuffer transfer via workspace edit. #209358

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/vs/workbench/api/browser/mainThreadBulkEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
import { IWorkspaceEditDto, IWorkspaceFileEditDto, MainContext, MainThreadBulkEditsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';


@extHostNamedCustomer(MainContext.MainThreadBulkEdits)
Expand All @@ -26,8 +27,8 @@ export class MainThreadBulkEdits implements MainThreadBulkEditsShape {

dispose(): void { }

$tryApplyWorkspaceEdit(dto: IWorkspaceEditDto, undoRedoGroupId?: number, isRefactoring?: boolean): Promise<boolean> {
const edits = reviveWorkspaceEditDto(dto, this._uriIdentService);
$tryApplyWorkspaceEdit(dto: SerializableObjectWithBuffers<IWorkspaceEditDto>, undoRedoGroupId?: number, isRefactoring?: boolean): Promise<boolean> {
const edits = reviveWorkspaceEditDto(dto.value, this._uriIdentService);
return this._bulkEditService.apply(edits, { undoRedoGroupId, respectAutoSaveConfig: isRefactoring }).then((res) => res.isApplied, err => {
this._logService.warn(`IGNORING workspace edit: ${err}`);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export interface ITextDocumentShowOptions {
}

export interface MainThreadBulkEditsShape extends IDisposable {
$tryApplyWorkspaceEdit(workspaceEditDto: IWorkspaceEditDto, undoRedoGroupId?: number, respectAutoSaveConfig?: boolean): Promise<boolean>;
$tryApplyWorkspaceEdit(workspaceEditDto: SerializableObjectWithBuffers<IWorkspaceEditDto>, undoRedoGroupId?: number, respectAutoSaveConfig?: boolean): Promise<boolean>;
}

export interface MainThreadTextEditorsShape extends IDisposable {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/api/common/extHostBulkEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MainContext, MainThreadBulkEditsShape } from 'vs/workbench/api/common/e
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { WorkspaceEdit } from 'vs/workbench/api/common/extHostTypeConverters';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import type * as vscode from 'vscode';

export class ExtHostBulkEdits {
Expand All @@ -28,7 +29,7 @@ export class ExtHostBulkEdits {
}

applyWorkspaceEdit(edit: vscode.WorkspaceEdit, extension: IExtensionDescription, metadata: vscode.WorkspaceEditMetadata | undefined): Promise<boolean> {
const dto = WorkspaceEdit.from(edit, this._versionInformationProvider);
const dto = new SerializableObjectWithBuffers(WorkspaceEdit.from(edit, this._versionInformationProvider));
return this._proxy.$tryApplyWorkspaceEdit(dto, undefined, metadata?.isRefactoring ?? false);
}
}
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
Loading