| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
- import { URI } from '../../../base/common/uri.js';
- import { isObject } from '../../../base/common/types.js';
- export const IBulkEditService = createDecorator('IWorkspaceEditService');
- export class ResourceEdit {
- constructor(metadata) {
- this.metadata = metadata;
- }
- static convert(edit) {
- return edit.edits.map(edit => {
- if (ResourceTextEdit.is(edit)) {
- return ResourceTextEdit.lift(edit);
- }
- if (ResourceFileEdit.is(edit)) {
- return ResourceFileEdit.lift(edit);
- }
- throw new Error('Unsupported edit');
- });
- }
- }
- export class ResourceTextEdit extends ResourceEdit {
- constructor(resource, textEdit, versionId = undefined, metadata) {
- super(metadata);
- this.resource = resource;
- this.textEdit = textEdit;
- this.versionId = versionId;
- }
- static is(candidate) {
- if (candidate instanceof ResourceTextEdit) {
- return true;
- }
- return isObject(candidate)
- && URI.isUri(candidate.resource)
- && isObject(candidate.textEdit);
- }
- static lift(edit) {
- if (edit instanceof ResourceTextEdit) {
- return edit;
- }
- else {
- return new ResourceTextEdit(edit.resource, edit.textEdit, edit.versionId, edit.metadata);
- }
- }
- }
- export class ResourceFileEdit extends ResourceEdit {
- constructor(oldResource, newResource, options = {}, metadata) {
- super(metadata);
- this.oldResource = oldResource;
- this.newResource = newResource;
- this.options = options;
- }
- static is(candidate) {
- if (candidate instanceof ResourceFileEdit) {
- return true;
- }
- else {
- return isObject(candidate)
- && (Boolean(candidate.newResource) || Boolean(candidate.oldResource));
- }
- }
- static lift(edit) {
- if (edit instanceof ResourceFileEdit) {
- return edit;
- }
- else {
- return new ResourceFileEdit(edit.oldResource, edit.newResource, edit.options, edit.metadata);
- }
- }
- }
|