-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
There was a problem hiding this 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
@lmcbout can you try the PR yourself as well? |
@fangnx one thing however, if you were to perform a search + replace for a single node, clicking that node in the tree to See the behavior below in vscode: |
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. |
I will look into this ;) |
I updated the PR. With my new updates, I do not see the issue anymore. |
packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx
Show resolved
Hide resolved
@lmcbout do you mind re-testing the PR? |
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 |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
There was a problem hiding this 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!
Fixed #5454
Fixed #5452.
search-in-workspace
widget, doing the "replace-all" used to open all the editor files in dirty state.