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

Fix URI Aware Command Handler Argument Duplication #8592

Merged

Conversation

colin-grant-work
Copy link
Contributor

@colin-grant-work colin-grant-work commented Oct 5, 2020

Signed-off-by: Colin Grant colin.grant@ericsson.com

What it does

Fixes #8585 by preventing duplication of arguments passed in. Also addresses the todo comment by creating separate classes for mono- and multi-select cases.

There are some remaining questions:

  • Given the potential confusion created by the generic and options, it may be desirable to deprecate the old UriAwareCommandHandler - except that it's likely to have been used quite widely.
  • Creating separate classes for the mono- and multi-select cases seems a bit heavy. Instead it would be possible to encourage users to instantiate the UriAwareCommandHandler class through the methods UriAwareCommandHandler.MultiSelect and UriAwareCommandHandler.MonoSelect (or better names :)), since then the typing only needs to be correct there.
  • This is potentially breaking in two cases:
    1. If anyone was working around it and expecting two copies of the URI.
    2. The old implementation would turn a single URI into [URI] in a multi-select context, but that seems like bad behavior. If the function expects URI[], then it seems like URI is a bad call, not something to be corrected. But if anyone was relying on that, they would now get an unexpected result.

How to test

  1. Run the tests.
  2. Copy the snippet from URIAwareCommand Handler Duplicates URI Arguments #8585 into packages/core/src/browser/common-frontend-contribution.ts in the registerCommands function, build, and run the 'Will Cause an Error' command. See that it doesn't cause an error anymore.

image

  1. Use some UriAwareCommandHandlers and see that they work (e.g. right click on a folder in the file explorer and try 'Find in Folder')

Review checklist

Reminder for reviewers

Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

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

Good changes and ideas!

My opinion about the points you brought up (clients depending on the URI clone bug, and the multi state typing bug) is that we should deprecate the old UriAwareCommandHandler while implementing the new ones which are free of bugs.

Deprecating doesn't mean removing, so mid-term it should be fine. Until we actually remove any deprecated API for good (on that note I did a test PR for this and I still need to take care of it at some point).

Now no matter how we handle the implementation for single vs multi uri selections, I agree that a simple API for clients is preferable. I feel like what you did with a namespace here is fine.

packages/core/src/common/uri-command-handler.ts Outdated Show resolved Hide resolved
packages/core/src/common/uri-command-handler.ts Outdated Show resolved Hide resolved
packages/core/src/common/uri-command-handler.ts Outdated Show resolved Hide resolved
@colin-grant-work colin-grant-work force-pushed the bugfix/duplicate-URI-args branch 2 times, most recently from c29ce67 to 42b7e2d Compare October 7, 2020 14:52
@colin-grant-work colin-grant-work force-pushed the bugfix/duplicate-URI-args branch 2 times, most recently from f3af630 to fc5dd5d Compare October 7, 2020 20:19
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
@colin-grant-work
Copy link
Contributor Author

@marechal-p, I've removed all calls (I think) to the UriAwareCommandHandler constructor in the repo. There are a couple of methods in different places that just duplicate the functionality of the new UriAwareCommandHandler.MonoSelect/MultiSelect, but I've left those in place, in case adopters refer to those methods in derived classes.

@paul-marechal paul-marechal merged commit 64bf4f5 into eclipse-theia:master Oct 14, 2020
@colin-grant-work colin-grant-work deleted the bugfix/duplicate-URI-args branch April 29, 2021 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URIAwareCommand Handler Duplicates URI Arguments
2 participants