Skip to content

Remove editorOpenWith - #116856

Merged
Logan Ramos (lramos15) merged 23 commits into
microsoft:mainfrom
lramos15:editorServiceOpenWith
Feb 22, 2021
Merged

Logan Ramos (lramos15) merged 23 commits into
microsoft:mainfrom
lramos15:editorServiceOpenWith

Conversation

@lramos15

Copy link
Copy Markdown
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: (Benjamin Pasero (@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.

@bpasero Benjamin Pasero (bpasero) left a comment •

Copy link
Copy Markdown
Contributor

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 👍

Comment thread src/vs/platform/editor/common/editor.ts Resolved
Comment thread src/vs/workbench/common/editor.ts Resolved
Comment thread src/vs/workbench/common/editor.ts Resolved
- 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.

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Logan Ramos (@lramos15) fyi destructuring even undefined is fine

@bpasero

Copy link
Copy Markdown
Contributor

Logan Ramos (@lramos15) Matt Bierner (@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.

}

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

Copy link
Copy Markdown
Contributor

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?

@lramos15 Logan Ramos (lramos15) Feb 22, 2021 •

Copy link
Copy Markdown
Member Author

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 Matt Bierner (@mjbvz) knows

@bpasero

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

This looks a lot cleaner for me. Thank you to Benjamin Pasero (@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.

@mjbvz Matt Bierner (mjbvz) left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread src/vs/platform/editor/common/editor.ts Resolved

export const defaultCustomEditor = new CustomEditorInfo({
id: DEFAULT_EDITOR_ID,
id: 'default',

Copy link
Copy Markdown
Contributor

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?

@lramos15 Logan Ramos (lramos15) Feb 22, 2021 •

Copy link
Copy Markdown
Member Author

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

id: 'default',
displayName: nls.localize('promptOpenWith.defaultEditor.displayName', "Text Editor"),
providerDisplayName: builtinProviderDisplayName,
providerDisplayName: nls.localize('builtinProviderDisplayName', "Built-in"),

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Logan Ramos (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