Skip to content

Remove determineSelection and simplify selection commands for the query history#2356

Merged
robertbrignull merged 3 commits intomainfrom
robertbrignull/query_history_selection
Apr 20, 2023
Merged

Remove determineSelection and simplify selection commands for the query history#2356
robertbrignull merged 3 commits intomainfrom
robertbrignull/query_history_selection

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

@robertbrignull robertbrignull commented Apr 19, 2023

This PR aims to simplify all our selection commands in the query history manager. The things we do are:

  • Remove the determineSelection method.
    • This method was needed for some commands that could be called from the title bar, because there might not be any items selected or even present. But with the merge of Remove query history title actions #2350 we've removed these actions.
    • I believe this wasn't strictly needed for the other commands, but we included it anyway for consistency and because nobody was quite sure what the rules and the real behaviour were.
    • singleItem should now always be defined, and there's some description on TreeViewContextMultiSelectionCommandFunction about when multiSelect is defined or not.
  • Make all method parameter types match TreeViewContextMultiSelectionCommandFunction
    • Some of the commands defined singleItem as possibly-undefined, but this isn't necessary.
  • Remove unnecessary checks that singleItem is not undefined
    • We should be able to trust our types, and therefore we don't need to test if singleItem is undefined or not. If our types are wrong we should change them, but I'm pretty convinced that they're correct.
  • Do multiSelect ||= [singleItem] in commands where we do operate on multiple items
    • This is working around multiSelect being undefined when only a single item is selected. Why VS Code gives us the arguments this way is a mystery to me, but that's what it does.
    • Making sure that multiSelect was always populated was something that determineSelection did, so now there's a couple of places where we need to do that ourselves. This will go away again with Introduce helpers for commands that operate on selections #2287.

If I'm correct, then this PR won't change any behaviour. I've done my best to manually test using the hover and right-click actions in every circumstance I could think of, and the rules follow what I wrote on TreeViewContextMultiSelectionCommandFunction.

This PR is another precursor to #2287 and it'll make that PR a lot simpler. In that PR we'll simplify method types again so they take exactly the arguments they need, and we can remove the need for the assertSingleQuery method.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

Copy link
Copy Markdown
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

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

Changes LGTM! Nice to see this getting tidied up. Thank you for writing a thorough PR description - it answered all my questions 😺

There were some tests around determineSelection which can now be 🔥

multiSelect,
);
if (!this.assertSingleQuery(finalMultiSelect) || !finalSingleItem) {
if (!this.assertSingleQuery(multiSelect)) {
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.

Not a problem with your PR but "assert" makes me think an error will be thrown if the expectation isn't met. Perhaps we should rename to isSingleQuery or something like that in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree it's confusingly named. I actually plan to delete it entirely in #2287

@robertbrignull
Copy link
Copy Markdown
Contributor Author

There were some tests around determineSelection which can now be 🔥

Ooh, I love the chance to delete even more code 🔥

These tests are now gone!

I guess this is another case of me not running npm run check-types, though I thought I'd got quite good at that 😞

@robertbrignull robertbrignull merged commit f0d41f6 into main Apr 20, 2023
@robertbrignull robertbrignull deleted the robertbrignull/query_history_selection branch April 20, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants