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

Allow renaming/creating/deleting files in a workspaced edit #41552

Merged
merged 10 commits into from
Jan 24, 2018

Conversation

mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented Jan 12, 2018

Fixes #10659

Allows workspace edits to also change files in the workspace

@mjbvz mjbvz self-assigned this Jan 12, 2018
@mjbvz mjbvz requested a review from jrieken January 12, 2018 22:04
@mjbvz mjbvz changed the title Add rename/create/delete file to workspaced edit Allow renaming/creating/deleting files in a workspaced edit Jan 12, 2018
Fixes #10659

Allows workspace edits to also change files in the workspace

export interface IResourceCreate {
readonly uri: URI;
readonly contents: string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is contents field really necessary? WorkspaceEdit also has edits that can be applied to 0,0 location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, tempting... We could then just have one type, a rename is from: Uri, to: Uri, a create would be from: null, to: Uri, and a delete would be from: Uri, to: null... Similar to how we map inserted, deleted, and changed text

import { IResourceRename, IResourceCreate } from 'vs/editor/common/modes';

export interface IResourceFileEdit {
readonly renamedResources: { from: URI, to }[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:URI


export interface IResourceCreate {
readonly uri: URI;
readonly contents: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, tempting... We could then just have one type, a rename is from: Uri, to: Uri, a create would be from: null, to: Uri, and a delete would be from: Uri, to: null... Similar to how we map inserted, deleted, and changed text

@jrieken
Copy link
Member

jrieken commented Jan 16, 2018

@gorkem Just wondering in what order JDT is generating edit when renaming a class? Is it first a file rename and then an edit in the new file or the other way around, text edit the old and then rename? Or would expect to have both supported (which our proposal doesn't)

@gorkem
Copy link

gorkem commented Jan 17, 2018

@jrieken At the framework level any mixed order is supported. Everything is seen as a Change whether it is a TextChange or a ResourceChange so it applies them on the given order and trusts that the entity that created the changes knows the best order for it. This is a bit complex to do on WorkspaceEdit at the moment as TextEdits and Resource changes are treated separately.

@jrieken
Copy link
Member

jrieken commented Jan 19, 2018

Makes sense @gorkem. I will give it a shot and see what I can do there... Today (without resources changes) we group all changes by file and performs per file... I'll try to preserve that but with interleaving resource changes...

@jrieken
Copy link
Member

jrieken commented Jan 19, 2018

@mjbvz I have pushed quite a monster commit to support more interleaving between text and file changes. I say 'more' because some are extra tricky because of how the API is designed, the workspace edit automatically groups text edits by resource. That means the following

  1. text change in a
  2. rename a to b
  3. another text change in a
  4. text change in b

will be executed in this order: 1, 3, 2, 4. I think that's a fair compromise tho (and I'll document that properly). I have removed most checks and I rely on the subcomponents fail, e.g. when making a textual change to a deleted/non-existing file you'll get an error.

Copy link
Collaborator Author

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I scanned over the changes but am not familiar enough with the editor logic to give change around bulkEdit a proper review.

The compromise around edit ordering you suggest sounds reasonable, although I'm not so sure if is something we should support. How much complexity does supporting out of order edits add to the implementation? Could the first iteration of this API have extra checks that prevent constructing an out of order workspaceEdit and then we could relax this in the future if the restriction is causing problems for ext developers?

* is represented as `[from, to]`, a delete-operation as `[from, null]`,
* and a create-operation as `[null, to]`;
*/
resourceEdits(): [Uri, Uri][];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we already use tuples in this API but they can be pretty annoying to work with. Can we use interfaces / object literal types instead? This would also better document what each component represents

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjbvz agree.

private _index = new Map<string, number>();
private _clock: number = 0;

private _resourceEdits: [number/*time*/, URI, URI][] = [];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about avoid tuples in our internals as well. They are weird type system wise (typeof([1, 2]) !== type [number, number]) and it easy to confuse tuple fields when writing or refactoring code

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjbvz agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, can make that change internally.. For the API I'd go for consistency even tho I share the concern. Having said that, I don't expect heavy usage of those reading APIs

@jrieken jrieken merged commit 57a072f into master Jan 24, 2018
@jrieken jrieken deleted the rename-workspaceedit-proto branch January 24, 2018 08:28
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WorkspaceEdit should support creating, deleting, and renaming of files
3 participants