Fiddle with handleCompareWith to make it cleaner#2358
Merged
robertbrignull merged 6 commits intomainfrom Apr 25, 2023
Merged
Conversation
uick 6363a6a Remove the determineSelection method
charisk
approved these changes
Apr 25, 2023
Contributor
charisk
left a comment
There was a problem hiding this comment.
Thanks for tidying this up, the changes LGTM. I only have some minor suggestions that you can ignore.
I've not tested this locally but it looks like there's some code coverage around it.
extensions/ql-vscode/src/query-history/query-history-manager.ts
Outdated
Show resolved
Hide resolved
| const otherItem = | ||
| fromItem === allItemsSelected[0] | ||
| ? allItemsSelected[1] | ||
| : allItemsSelected[0]; |
Contributor
There was a problem hiding this comment.
The previous code had a comment explaining a bit why we're doing this. That meaning is lost a little bit here. Is there something we can do to make it clear again?
🤔 We could wrap this condition in a method like you've done in other places. Something like firstUnselectedItem()?
Contributor
Author
There was a problem hiding this comment.
I've updated the comments to be a bit clearer. Does that make it better?
extensions/ql-vscode/src/query-history/query-history-manager.ts
Outdated
Show resolved
Hide resolved
extensions/ql-vscode/src/query-history/query-history-manager.ts
Outdated
Show resolved
Hide resolved
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.
The aim of this PR is to make the code for
handleCompareWithcleaner and clearer.I've been reading the query history commands a lot recently, and
handleCompareWithkeeps catching my eye. It's unusual because it's the only command we have that actually uses bothsingleItemandmultiSelect, because it wants to know which of the selected items you actually clicked on so it can use that one as the "from" part of the comparison. Unfortunately the method is also rather confusingly written with lots of redundant checks and generally confusing logic.This PR should theoretically be completely behaviour preserving. I'm not aiming to change any behaviour, but then the
this.compareWithItemfield in particular is new to me so I might have misunderstood something in its operation.I haven't split up the commits into separate tiny changes because they're all on top of each other and I wasn't thinking about it as I wrote this. I recommend just reading the final code and seeing what you think of it. I could go back and split it up, but I hope a descriptive list will be just as good. Let me know what you think. The general list of things that are a little wrong in the original code and are changed by this PR are:
determineSelectionis unnecessary.LocalQueryItemand then aCompletedLocalQueryItemin multiple places.singleItemat the start ofhandleCompareWith, but then we check it again infindOtherQueryToCompare, and we only checkmultiSelectinfindOtherQueryToCompare.singleItemandmultiSelectonce at the start ofhandleCompareWithand provide a consistent error message.this.compareWithItemwithout checking that it is one of the selected queries.treeView.onDidChangeSelectionshould have fired and updatedthis.compareWithItem. But maybe it's possible that didn't fire or they happen in the wrong order.this.compareWithItemis one of the elements frommultiSelect.this.compareWithItembecause I expect most people won't have encountered it before, so I'll try to summarise how I think it works.isSuccessfulCompletedLocalQueryInfoand use that at the start to safely cast everything to aCompletedLocalQueryInfo. We can then remove a lot of casts and unnecessary error checks.isSuccessfulCompletedLocalQueryInfoinfindOtherQueryToComparewhen we're searching the list of all history items for possible comparisons.findOtherQueryToCompareand just show the notification without telemetry.Checklist
ready-for-doc-reviewlabel there.