Make types for selection commands more precise#2304
Merged
robertbrignull merged 1 commit intomainfrom Apr 13, 2023
Merged
Conversation
charisk
approved these changes
Apr 13, 2023
Contributor
charisk
left a comment
There was a problem hiding this comment.
Thanks for thinking through this, testing the different cases and writing helpful comments!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to make our types for commands that operate on selections more precise and correct. It's possible for a lot of these commands to receive
undefineds that they weren't expecting, and the behaviour is different for different places where the commands are registered.I've done a lot of manual testing, logging the arguments of commands and triggering them in as many different ways as I could think of. It turns out that tree views behave differently from the file explorer, and title menus also behave differently from context menus. I've split the types in to the various cases and tried to summarise all my findings in the comments.
(btw, I know the type names are quite long. Any suggestions for better names are welcome.)
I then went and corrected types throughout the application. Thankfully we were actually handling undefined values everywhere, which just shows the types were incorrect and giving a false sense of security. The types now match the behaviour of the code and should avoid future problems.
Side-note, this sort of precise typing wouldn't be possible if we hadn't split our commands so they're only called from one place.
Checklist
ready-for-doc-reviewlabel there.