-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Revisit lifecycle of editor inputs in VSCode #99770
Comments
@mjbvz curious to hear your thoughts on this since you are a big customer of editor inputs as well. Do you share inputs of same resources (for webviews, custom editors?). How about the lifecycle there? |
@bpasero I believe we avoid this for webviews and custom editors because we create a unique editor input for each copy of the editor that is open (even if they are for the same resource):
We do this because |
@mjbvz so are you implementing the I am really thinking we should have an explicit |
@rebornix @mjbvz via a18110a there is now a new method on editor inputs: close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
if (!openedInOtherGroups) {
this.dispose();
}
} For now it preserves exactly the behaviour we had. In the future this should possibly be an abstract method as I think only an implementor of an editor input knows if the input can be disposed or not. @rebornix does that help in removing the editor close listener you have to setup? |
This is a list of all our editor inputs in VSCode where we should check for adoption: Maybe @mjbvz you could make a statement about custom editors and webview related ones. |
So, |
@bpasero Speaking of If we are going to share updateI added proposals and deleted it three times after playing around |
Yeah - I have ref counted notebook models follow the re-use editor input approach but it's impossible for to get the "share widget" logic to work. The challange is that is all cases |
Yes, but the logic for moving a tab will always first open it in the second group and then close it in the first group. So you will end up getting a It is fine if you decide to NOT share editor inputs, this is not a requirement of the editor model at all. Just files decided to do this. I hope the new |
Yeah, I came to the same conclusion and I'll drop my current (branched) changes. One challenge is that the workbench defaults to reuse and that notebooks and custom editors fight against that. So, could we have workbench support here, e.g when splitting an editor check for |
Is that only for splitting or are there more places where you see that? I think it is fine to add more methods to |
Oh, yeah I like that |
So after looking into this again going through all editors, I see that this is not so trivial. I still think a However, the logic that we have today that we only close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
if (!openedInOtherGroups) {
this.dispose();
}
} Here is why:
[1] Open same editor across groups
Bottom line: a call between custom editor and notebook owners would be good to collect requirements and then go from there. I will hold to push anymore changes on this matter until we decided what is needed. |
Actually how would we enforce this, e.g. someone could easily write the following code: const input = new MyInput();
editorService.openEditor(input, groupA);
editorService.openEditor(input, groupB); I feel that we need to make sure that editor inputs really remain lightweight and do not carry anything heavy around. They should only be used to instruct the editor part to open something imho. |
Some quick high level note on expected behavior for webviews and custom editors. Webviews
Custom Editors that set supportsMultipleEditorsPerDocument:false
Normal Custom editors (that set supportsMultipleEditorsPerDocument: true)
|
The editor part changed its strategy for calling
As such, inputs should now be more aggressively disposed if they decide to not share the same instance across groups. As such, this special code for custom editors was removed: 063ea11 |
Stumbled upon this code (after chat with @jrieken):
vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts
Lines 216 to 230 in 19dcc79
The editor part should already take care of disposal. You can see it here:
vscode/src/vs/workbench/browser/parts/editor/editorGroupView.ts
Lines 535 to 537 in 19dcc79
We call
EditorInput.dispose()
when the last kind of that editor is closed across all groups. This is in the end determined by theEditorInput.matches()
method and goes like this:editor.matches(editorThatClosed)
I see that this may result in editor inputs not getting disposed in the following case:
foo
foo
is openedEditorInput.matches()
)This is unfortunate and should be fixed by always ensuring the same editor input is used for the same underlying resource (something we do for files always). The editor part cannot really enforce this, so I wonder if a better idea would be to introduce a method such as
EditorInput#close()
that we always call when an editor is being closed and then each input has to decide how to deal with it.The text was updated successfully, but these errors were encountered: