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

Remove editorOpenWith #116856

Merged
merged 23 commits into from
Feb 22, 2021
Merged

Remove editorOpenWith #116856

merged 23 commits into from
Feb 22, 2021

Conversation

lramos15
Copy link
Member

This PR outlines part of the solution to #116272.

This removes the use of openWith and adds additional functionality to openEditor.

The next steps are to: (@bpasero feel free to correct me if I'm wrong 😄 )

  1. Make the editor service aware of editor associations
  2. Update custom editor inputs to no longer be async and add custom editor input functionality to createEditorInput
  3. Remove the editorGroups' understanding of what an override is and just expect the correct input to be passed in.
  4. Adopt this for other "custom editors" such as the search editor.

@lramos15 lramos15 self-assigned this Feb 17, 2021
@lramos15 lramos15 added the debt Code quality issues label Feb 17, 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 glanced over the changes and left some feedback. I think large chunks of code such as IEditorService#openEditorWith would simplify much once we have a way to return custom editor inputs from the createEditorInput flow. In my mind, the only logic editor service should have is to know which editor input to create based on overrides and picks. But that is a follow up step to consider as we have already discussed.

Besides, there are some types and interfaces I fail to find a good place for. I don't really understand the IConfigurationNode for custom editors, nor why schemas have to change. All of this stuff should really not be inside the editor service but in some registry outside. Same goes for constants defined in editor.ts.

I think my biggest issue in this area now is that I see code and concepts that I have not seen before (because I did not author them), making it hard for me the reason about them.

Ideally we can clean this up with existing patterns we have 👍

src/vs/workbench/contrib/files/browser/fileCommands.ts Outdated Show resolved Hide resolved
src/vs/workbench/contrib/files/browser/fileCommands.ts Outdated Show resolved Hide resolved
src/vs/workbench/contrib/files/browser/fileCommands.ts Outdated Show resolved Hide resolved
src/vs/platform/editor/common/editor.ts Outdated Show resolved Hide resolved
src/vs/workbench/common/editor.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
src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
@bpasero bpasero self-requested a review February 20, 2021 09:25
- OverrideOptions => EditorOverride
- It is safe to destructure (...) undefined
- Ensure when destructuring, override is always winning
- Not a big fan of shared builtinProviderDisplayName import
This moves the relevant code out of the editor service.
@@ -570,7 +570,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
}

const fileEditorInput = this.createEditorInput({ resource, forceFile: true });
const textOptions: IEditorOptions | ITextEditorOptions = options ? { ...options, override: OverrideOptions.DISABLED } : { override: OverrideOptions.DISABLED };
const textOptions: IEditorOptions | ITextEditorOptions = { ...options, override: EditorOverride.DISABLED };
Copy link
Member

Choose a reason for hiding this comment

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

@lramos15 fyi destructuring even undefined is fine

@bpasero
Copy link
Member

bpasero commented Feb 21, 2021

@lramos15 @mjbvz ok, I went over all the code and pushed changes to align with existing patterns. Please do a thorough review and testing of the following changes:

  • 293664b moves all of the previous IEditorService#registerCustomEditorViewTypesHandler into a static IEditorAssociationsRegistry. I did not fully understand why the editor service would be responsible for managing and updating the workbench.editorAssociations configuration, imho that is a very static concept that should behave like registering an editor to a registry. I also removed the notion of viewType from there. What is a viewType in the context of an editor? I renamed to editorType
  • f7b7f94 rewrites entirely the resolution of an editor override if one has to be picked. It clearly distinguishes between picking an override and finding one from a string that was passed in. There was additional complexity due to the fact that the provided group and options can change depending on how the user interacts with the picker
  • 8da2cec makes sure that the editor delegate still works, even with overrides

I will file follow up debt issues for related things I noticed that are beyond the scope of this PR.

@bpasero bpasero self-requested a review February 21, 2021 10:51
}

// Collect all overrides for resource
const allEditorOverrides = this.getEditorOverrides(resource, undefined, undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Should this call forward the options and group from the openEditor call or why is undefined explicitly passed in?

Copy link
Member Author

@lramos15 lramos15 Feb 22, 2021

Choose a reason for hiding this comment

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

I haven no idea, it didn't seem to change anything for me. Maybe @mjbvz knows

@bpasero
Copy link
Member

bpasero commented Feb 22, 2021

Commenting on your proposed next steps:

Make the editor service aware of editor associations

Yeah possibly. However in #117207 I noticed that actually only custom editors seem to use workbench.editorAssociations so I think we should have a dedicated discussion where this ends up being moved to. Maybe we end up moving workbench.editorAssociations out to custom editors only and leave a very simply solution in the editor service that converts a resource to an editor input.

Update custom editor inputs to no longer be async and add custom editor input functionality to createEditorInput

I reported #117208 to look into that. If we have the concept of letting the user pick a custom editor as part of the open editor flow, we probably have to make createEditorInput async, at least for those cases. As such, maybe createEditorInput could be sync in most cases but async in some, based on editor options passed in.

Remove the editorGroups' understanding of what an override is and just expect the correct input to be passed in.

Yes, 💯 , and that is #100281

Adopt this for other "custom editors" such as the search editor.

Yes, maybe also settings editor.

@lramos15
Copy link
Member Author

This looks a lot cleaner for me. Thank you to @bpasero for putting the pieces together that I couldn't quite figure out. I will utilize debt week to improve on this more based on the above comments.

Copy link
Collaborator

@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.

Looks good overall to me. Nice work!

src/vs/platform/editor/common/editor.ts Outdated Show resolved Hide resolved
export const defaultCustomEditor = new CustomEditorInfo({
id: DEFAULT_EDITOR_ID,
id: 'default',
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Why does this constant need to be inlined?

Copy link
Member Author

@lramos15 lramos15 Feb 22, 2021

Choose a reason for hiding this comment

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

It breaks layering, as everywhere else this is used is in browser

src/vs/workbench/services/editor/browser/editorService.ts Outdated Show resolved Hide resolved
displayName: nls.localize('promptOpenWith.defaultEditor.displayName', "Text Editor"),
providerDisplayName: builtinProviderDisplayName,
providerDisplayName: nls.localize('builtinProviderDisplayName', "Built-in"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Try extracting this string since it it used in two places

Copy link
Member

Choose a reason for hiding this comment

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

That is probably on me, I wasn't sure about the benefit of sharing NLS strings here. If we have a concept of built-in custom editors, shouldn't we rather have a flag to indicate as such and then maybe put the label in one central place?

@lramos15 lramos15 merged commit 413963c into microsoft:main Feb 22, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants