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

Open Editor refactors #119274

Merged
merged 19 commits into from
Mar 29, 2021
Merged

Open Editor refactors #119274

merged 19 commits into from
Mar 29, 2021

Conversation

lramos15
Copy link
Member

@lramos15 lramos15 commented Mar 18, 2021

This PR is part of the work for #100281

The main work of this PR includes:

  1. Renaming IEditorInputFactory -> IEditorInputSerializer as it doesn't actually create an editor input at all
  2. Move the override logic into the editor service and away from the editorGroupView. This involved removing the onEditorWillOpen event as it wasn't really necessary. An improvement here might be to have the overrides return editor inputs to prevent circular openEditor calling
  3. Create an onWillMoveEditor event so things like notebooks can properly handle moving between groups

@lramos15 lramos15 requested a review from bpasero March 18, 2021 19:00
@lramos15 lramos15 self-assigned this Mar 18, 2021
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

I really like these changes, good job. I focused mainly on the editor related changes and for notebook + custom defer to your expertise because I am not comfortable reviewing changes in those areas.

Here is some general feedback:

  • there is a ton of places now where we have the IEditorInputSerializer but the surrounding context often still refers to it as a "factory". I think for consistency and avoiding confusion in the future I would also rename everything around it to refer to "serializers" and not "factories" anymore. does that sounds reasonable? this probably means to go over the change again step by step and doing a bit more renames but I think that would be worth it especially since we may want to introduce editor input factory in the future which then collides with the serializer concept
  • I see some commented out tests in editorGroupsService.test.ts and think that they need to be converted in a way that we can test the new concepts you introduced (e.g. onWillMoveEditor)

src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
src/vs/workbench/common/editor.ts Outdated Show resolved Hide resolved
src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
@lramos15 lramos15 requested a review from bpasero March 19, 2021 20:10
@lramos15
Copy link
Member Author

@bpasero This is ready for review again. The one issue @rebornix and I ran into is that on editor startup / restore there is no way for something to know about all the groups that exist on startup. I changed the editor part restore to fire the onAddGroup event for all the restored groups so any subscribers would be aware of them but I want to get your input as this causes active editor tests to fail so I'm not sure if they should be updated or what the best solution is.

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

@lramos15 I did a review and pushed some 💄 changes on top that I had in mind from my first review, I hope that is fine.

There is slight inconsistency with this change that we may want to tackle later:

  • override is still a member of EditorOptions but is actually ignored unless you go through the IEditorService, so maybe we should actually remove it from the options and explicitly add it as parameter to the IEditorOpenService#openEditor method alone?
  • the moveEditor method does not really support all the editor options passed unless the editor moves to another group but I think that is fine, I removed the move/copy options bag and replaced it with the editor options interface we already have

there is no way for something to know about all the groups that exist on startup

I signed off on all changes, except for the one that is causing test failures and maybe can we push a more isolated fix only for notebooks? It is funny that you ran into this issue because I have #119059 (comment) where I face a similar problem where my editor observer is only starting to track editor groups after editors have restored but this causes all kinds of issues. In April I want to push a change to have a way to track editor groups even before editors restore. In other words: the editor part should signal editors have been restored before the actual editors have been loaded. This should actually enable us to track groups and editor s right on startup. But I am a bit afraid to push this right before endgame.

Where do notebooks need the groups right on startup?

@lramos15
Copy link
Member Author

Thanks for the review. The 💄 looks good too, sorry about forgetting to rename the areas around IEditorInputSerializer. I talked to Kai a bit and he said we should probably hold off on merging this until next iteration just due to how little testing time we would have with these changes. This should give us time to come up with a good solution for your issue that also unblocks notebooks. I don't want to merge this yet as notebooks not knowing about all groups causes the re-rendering issue we were trying to avoid with onWillMoveEditor.

Here you can see that notebooks binds event listeners to all groups, but due to not knowing about groups on startup / restore reloading the window is enough to cause all existing listeners to be lost and not rebound.

const onNewGroup = (group: IEditorGroup) => {
const { id } = group;
const listeners: IDisposable[] = [];
listeners.push(group.onDidGroupChange(e => {
const widgets = this._borrowableEditors.get(group.id);
if (!widgets || e.kind !== GroupChangeKind.EDITOR_CLOSE || !(e.editor instanceof NotebookEditorInput)) {
return;
}
const value = widgets.get(e.editor.resource);
if (!value) {
return;
}
value.token = undefined;
this._disposeWidget(value.widget);
widgets.delete(e.editor.resource);
}));
listeners.push(group.onWillMoveEditor(e => {
if (e.editor instanceof NotebookEditorInput) {
this._freeWidget(e.editor, e.source, e.target);
}
}));
groupListener.set(id, listeners);
};
this._disposables.add(editorGroupService.onDidAddGroup(onNewGroup));
editorGroupService.groups.forEach(onNewGroup);

@bpasero bpasero added this to the April 2021 milestone Mar 21, 2021
@bpasero bpasero self-requested a review March 21, 2021 10:53
@bpasero
Copy link
Member

bpasero commented Mar 21, 2021

@lramos15 I don't really understand why notebooks cannot do this:

editorGroupService.whenRestored.then(() => editorGroupService.groups.forEach(onNewGroup)); 

There should always be a way to track editor groups, in the end that is what EditorsObserver does, which is a core thing crucial for many features we built on top:

private registerListeners(): void {
this._register(this.storageService.onWillSaveState(() => this.saveState()));
this._register(this.editorGroupsService.onDidAddGroup(group => this.onGroupAdded(group)));
this._register(this.editorGroupsService.onDidChangeEditorPartOptions(e => this.onDidChangeEditorPartOptions(e)));
this.editorGroupsService.whenRestored.then(() => this.loadState());
}

@lramos15
Copy link
Member Author

@bpasero I have fixed the tests and adjusted the notebook's way of listening for groups to the way you suggested and that seems to work.

I noticed you renamed the notebook and custom editor input factory files to input serializer files. I'm not sure what we could call those as they have both an IEditorInputSerializer and a ICustomEditorInputFactory

@bpasero
Copy link
Member

bpasero commented Mar 22, 2021

@lramos15 very cool! yeah feel free to revert my rename, I didn't see they include the actual custom factories too 👍

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

Ok for me to merge in April 👍

@lramos15 lramos15 enabled auto-merge (squash) March 26, 2021 19:59
@lramos15 lramos15 disabled auto-merge March 26, 2021 20:13
@lramos15 lramos15 enabled auto-merge (squash) March 29, 2021 14:49
@lramos15 lramos15 merged commit 7164efa into main Mar 29, 2021
@lramos15 lramos15 deleted the editorInputRefactor branch March 29, 2021 14:56
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2021
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.

2 participants