Repository navigation
feat(runtime): rank exact matches above higher priority suggestions - #511
Open
1ilsang (1ilsang) wants to merge 2 commits into
Open
1ilsang (1ilsang) wants to merge 2 commits into
1ilsang (1ilsang) wants to merge 2 commits into
Conversation
Author
|
@microsoft-github-policy-service agree |
cpendery (cpendery)
left a comment
Member
There was a problem hiding this comment.
overall looks good! left a few small tweaks / nits
| .map((s) => { | ||
| if (s.name == null) return; | ||
| if (s.name instanceof Array) { | ||
| const matchedName = s.name.find((n) => n.toLowerCase().startsWith(normalizedPartialCmd)); |
Member
There was a problem hiding this comment.
nit: if we are trying to prioritize exact matches, we should also change this condition and below to favor exact matches first, then prefix driven matches
| } | ||
| : undefined; | ||
| } | ||
| return s.name.toLowerCase().startsWith(normalizedPartialCmd) |
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { getArgDrivenRecommendation, getSubcommandDrivenRecommendation } from "../../runtime/suggestion.js"; |
Member
There was a problem hiding this comment.
maybe instead of adding this suggestion.test.ts, we can just add some cases to testData in runtime.test.ts to cover it?
| // (-l vs -L) and git refs differ by case. Tokens containing a path separator are treated as paths and | ||
| // reduced to their basename (partialCmd). File and folder suggestions are named by their basename, so | ||
| // they compare against it; every other suggestion (e.g. the git branch feat/foo) is named in full and | ||
| // compares against the full token, so typing feat/foo does not match an unrelated branch named foo. |
Member
There was a problem hiding this comment.
nit: trying to keep comments to a minimum in the repo, this function looks pretty self explanatory, no need to add it
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.
Summary
Typing a suggestion's full name did not always select it. Suggestions are sorted by priority first, so a higher priority partial match stayed on top of an exact match.
The git spec gives the current branch priority 100 and other branches priority 75. With the current branch
feat/foo-1234and another branchfeat/foo-:-land-Lare different.foo-), so the full token (feat/foo-) is compared too. Without this, branch names would never match exactly.