mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
add WorkspaceEditMetadata and use it for applyEdit, (#160996)
* add `WorkspaceEditMetadata` and use it for `applyEdit`, https://github.com/microsoft/vscode/issues/112109 * fix compilo in tests * workspace edits from updating paths are marked as refactoring fyi @mjbvz
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
|
||||
"enabledApiProposals": [
|
||||
"resolvers",
|
||||
"workspaceTrust"
|
||||
"workspaceTrust",
|
||||
"workspaceEditIsRefactoring"
|
||||
],
|
||||
"capabilities": {
|
||||
"virtualWorkspaces": {
|
||||
|
||||
@@ -114,7 +114,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
|
||||
|
||||
if (edits.size) {
|
||||
if (await this.confirmActionWithUser(resourcesBeingRenamed)) {
|
||||
await vscode.workspace.applyEdit(edits);
|
||||
await vscode.workspace.applyEdit(edits, { isRefactoring: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"src/**/*",
|
||||
"../../src/vscode-dts/vscode.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.inlayHints.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.workspaceEditIsRefactoring.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.languageStatus.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.resolvers.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts",
|
||||
|
||||
@@ -865,8 +865,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
saveAll: (includeUntitled?) => {
|
||||
return extHostWorkspace.saveAll(includeUntitled);
|
||||
},
|
||||
applyEdit(edit: vscode.WorkspaceEdit, isRefactoring?: boolean): Thenable<boolean> {
|
||||
return extHostBulkEdits.applyWorkspaceEdit(edit, extension, isRefactoring);
|
||||
applyEdit(edit: vscode.WorkspaceEdit, metadata?: vscode.WorkspaceEditMetadata): Thenable<boolean> {
|
||||
return extHostBulkEdits.applyWorkspaceEdit(edit, extension, metadata);
|
||||
},
|
||||
createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
|
||||
return extHostFileSystemEvent.createFileSystemWatcher(extHostWorkspace, extension, pattern, ignoreCreate, ignoreChange, ignoreDelete);
|
||||
|
||||
@@ -28,13 +28,13 @@ export class ExtHostBulkEdits {
|
||||
};
|
||||
}
|
||||
|
||||
applyWorkspaceEdit(edit: vscode.WorkspaceEdit, extension: IExtensionDescription, isRefactoring?: boolean): Promise<boolean> {
|
||||
applyWorkspaceEdit(edit: vscode.WorkspaceEdit, extension: IExtensionDescription, metadata: vscode.WorkspaceEditMetadata | undefined): Promise<boolean> {
|
||||
const allowIsRefactoring = isProposedApiEnabled(extension, 'workspaceEditIsRefactoring');
|
||||
if (isRefactoring && !allowIsRefactoring) {
|
||||
if (metadata && !allowIsRefactoring) {
|
||||
console.warn(`Extension '${extension.identifier.value}' uses a proposed API 'workspaceEditIsRefactoring' which is NOT enabled for it`);
|
||||
isRefactoring = undefined;
|
||||
metadata = undefined;
|
||||
}
|
||||
const dto = WorkspaceEdit.from(edit, this._versionInformationProvider);
|
||||
return this._proxy.$tryApplyWorkspaceEdit(dto, undefined, isRefactoring);
|
||||
return this._proxy.$tryApplyWorkspaceEdit(dto, undefined, metadata?.isRefactoring ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
|
||||
test('uses version id if document available', async () => {
|
||||
const edit = new extHostTypes.WorkspaceEdit();
|
||||
edit.replace(resource, new extHostTypes.Range(0, 0, 0, 0), 'hello');
|
||||
await bulkEdits.applyWorkspaceEdit(edit, nullExtensionDescription);
|
||||
await bulkEdits.applyWorkspaceEdit(edit, nullExtensionDescription, undefined);
|
||||
assert.strictEqual(workspaceResourceEdits.edits.length, 1);
|
||||
const [first] = workspaceResourceEdits.edits;
|
||||
assert.strictEqual((<IWorkspaceTextEditDto>first).versionId, 1337);
|
||||
@@ -55,7 +55,7 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
|
||||
test('does not use version id if document is not available', async () => {
|
||||
const edit = new extHostTypes.WorkspaceEdit();
|
||||
edit.replace(URI.parse('foo:bar2'), new extHostTypes.Range(0, 0, 0, 0), 'hello');
|
||||
await bulkEdits.applyWorkspaceEdit(edit, nullExtensionDescription);
|
||||
await bulkEdits.applyWorkspaceEdit(edit, nullExtensionDescription, undefined);
|
||||
assert.strictEqual(workspaceResourceEdits.edits.length, 1);
|
||||
const [first] = workspaceResourceEdits.edits;
|
||||
assert.ok(typeof (<IWorkspaceTextEditDto>first).versionId === 'undefined');
|
||||
|
||||
@@ -7,12 +7,21 @@ declare module 'vscode' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/112109
|
||||
|
||||
/**
|
||||
* Additional data about a workspace edit.
|
||||
*/
|
||||
export interface WorkspaceEditMetadata {
|
||||
/**
|
||||
* Signal to the editor that this edit is a refactoring.
|
||||
*/
|
||||
isRefactoring?: boolean;
|
||||
}
|
||||
|
||||
export namespace workspace {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param isRefactoring Signal to the editor that this edit is a refactoring.
|
||||
* @param metadata Optional {@link WorkspaceEditMetadata metadata} for the edit.
|
||||
*/
|
||||
export function applyEdit(edit: WorkspaceEdit, isRefactoring?: boolean): Thenable<boolean>;
|
||||
export function applyEdit(edit: WorkspaceEdit, metadata?: WorkspaceEditMetadata): Thenable<boolean>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user