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

Fixed #5454, #5452: modified "replace-all" to save changes without opening editors #5600

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

fangnx
Copy link

@fangnx fangnx commented Jun 27, 2019

Fixed #5454
Fixed #5452.

  • In search-in-workspace widget, doing the "replace-all" used to open all the editor files in dirty state.
  • With this patch, "replace-all" will do all the text replacement, and simply save the changes in the editors without opening them.

vince-fugnitto
vince-fugnitto previously approved these changes Jun 27, 2019
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

Very nice work! 👍 BTW, it also fixes #5452

@vince-fugnitto vince-fugnitto added enhancement issues that are enhancements to current functionality - nice to haves search in workspace issues related to the search-in-workspace labels Jun 27, 2019
@vince-fugnitto
Copy link
Member

vince-fugnitto commented Jun 27, 2019

@lmcbout can you try the PR yourself as well?

@vince-fugnitto
Copy link
Member

@fangnx one thing however, if you were to perform a search + replace for a single node, clicking that node in the tree to replace only for him should open the file with the changes.

See the behavior below in vscode:

a (1)

@vince-fugnitto vince-fugnitto self-requested a review June 27, 2019 20:56
@vince-fugnitto vince-fugnitto dismissed their stale review June 27, 2019 20:57

updated testing.

@lmcbout
Copy link
Contributor

lmcbout commented Jun 28, 2019

When a file is opened, the replace all affects open and closed files and seems OK until the open file is in dirty state, then the replace all stops working. From that point on, you can add char in the file, but pressing "ctrl + s" to save the dirty file is not working anymore, replace all to return to its original data is not working anymore it is not detecting the new search.

ReplaceAllWhen Dirty
.

@fangnx
Copy link
Author

fangnx commented Jun 28, 2019

When a file is opened, the replace all affects open and closed files and seems OK until the open file is in dirty state, then the replace all stops working. From that point on, you can add char in the file, but pressing "ctrl + s" to save the dirty file is not working anymore, replace all to return to its original data is not working anymore it is not detecting the new search.

ReplaceAllWhen Dirty
.

I will look into this ;)

@fangnx fangnx changed the title Fixed #5454: modified "replace-all" to save changes without opening editors Fixed #5454, #5452: modified "replace-all" to save changes without opening editors Jun 28, 2019
@fangnx
Copy link
Author

fangnx commented Jun 28, 2019

When a file is opened, the replace all affects open and closed files and seems OK until the open file is in dirty state, then the replace all stops working. From that point on, you can add char in the file, but pressing "ctrl + s" to save the dirty file is not working anymore, replace all to return to its original data is not working anymore it is not detecting the new search.

ReplaceAllWhen Dirty
.

I updated the PR. With my new updates, I do not see the issue anymore.

@akosyakov akosyakov requested a review from jbicker July 1, 2019 08:46
@vince-fugnitto
Copy link
Member

@lmcbout do you mind re-testing the PR?

@lmcbout
Copy link
Contributor

lmcbout commented Jul 8, 2019

When there is a dirty file, {Add an empty line } before you look for a string to replace, you end-up with corrupted data. Corrupted data will be fix with the the following issue #5609 / pr #5651
Note: replacing data from a dirty file was there before this patch. This patch only prevent opening all files in a dirty state.

Copy link
Contributor

@lmcbout lmcbout left a comment

Choose a reason for hiding this comment

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

Nice improvement
One thing, I noticed that if a file is open and is not formatted, (JAVA, TS, CPP)
1- Focus on the file in editor view when replace all occurs: file save and reformatted
2- File in editor, but the focus is on a different file, replace all : file saved but not re-formatted
The "editor.formatOnSave" preference issue is tracked with issue #5740.

*/
protected async doGetWidget(node: SearchInWorkspaceResultLineNode): Promise<EditorWidget> {
const fileUri = new URI(node.fileUri);
const editorWidget = await this.editorManager.getOrCreateByUri(fileUri);
Copy link
Member

@akosyakov akosyakov Jul 18, 2019

Choose a reason for hiding this comment

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

if it creates a new widget, at what point of time is gets disposed and garbage collected?

Could you check that there are no memory leaks with this change please in the case if this code creates a new instance.

Copy link
Author

Choose a reason for hiding this comment

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

if it creates a new widget, at what point of time is gets disposed and garbage collected?

Could you check that there are no memory leaks with this change please in the case if this code creates a new instance.

I thought it would be handled as it extends widget. Could you please tell me how I can do memory leak check for Theia?

Copy link
Member

Choose a reason for hiding this comment

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

I added a bunch of code inside this function and displayed all the editors tracked by the editor manager, it happens that editors are leaking indeed. Good thing is that we only leak one of the same URI, since getOrCreate won't spawn duplicates.

I don't know how you should go about disposing them, I also find weird that we have to instantiate EditorWidget in order to change a file and save it?

@akosyakov ?

Copy link
Member

@akosyakov akosyakov Jul 21, 2019

Choose a reason for hiding this comment

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

I thought it would be handled as it extends widget. Could you please tell me how I can do memory leak check for Theia?

In dev tools, there is memory tab, you should force garbage collection first, then take a snapshot, and check whether there are no EditorWidget, except a constructor (you will see a special character next to such instance).

I don't know how you should go about disposing them, I also find weird that we have to instantiate EditorWidget in order to change a file and save it?

You should use ResourceProvider to get a Resource and then modify and dispose it if you want to modify content on the disk without editor or dirty model.

Copy link
Author

Choose a reason for hiding this comment

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

In the updated patch, I manually dispose the editor widget after it has been modified and saved, since editor widget has to be called in order to use the replaceText method. I tested with dev tools and could confirm that the editor widget could be disposed properly.

Copy link
Member

Choose a reason for hiding this comment

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

please ask someone to verify that:

  • it does not cause some glitches, like this editor also gets really opened in the meantime and then unexpectedly closed
  • there is no memory leak

If someone checks it and it is fine then it is fine to merge. Don't have time to do it now sorry

Copy link
Member

Choose a reason for hiding this comment

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

I looked and did not find a memleak, approving :)

…out opening editors

- In `search-in-workspace` widget, doing the "replace-all" used to open all the editor files in dirty state.
- With this patch, "replace-all" will do all the text replacement, and simply save the changes in the editors without opening them.

Signed-off-by: fangnx <naxin.fang@ericsson.com>
Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

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

No memory leak, LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement issues that are enhancements to current functionality - nice to haves search in workspace issues related to the search-in-workspace
Projects
None yet
5 participants