-
Notifications
You must be signed in to change notification settings - Fork 70
autocomplete: allow completion based on name/detail #165
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
base: main
Are you sure you want to change the base?
Conversation
Fixes apache#48 Signed-off-by: Abhishek Kumar <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the autocomplete functionality to support completion based on both the value and detail fields of completion items, addressing issue #48. The changes allow users to trigger autocompletion by typing either the main value or the detail portion of completion options.
- Modified filtering logic to include items where the detail field matches the input prefix
- Updated option display logic to show full option when matching on detail field
- Changed condition for showing details from requiring multiple options to showing when any detail exists
@@ -421,12 +421,14 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) | |||
} | |||
for _, item := range filteredOptions { | |||
option := item.Value + " " | |||
if len(filteredOptions) > 1 && len(item.Detail) > 0 { | |||
if len(filteredOptions) > 0 && len(item.Detail) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The condition change from > 1
to > 0
means details will now always be shown when they exist, even for single options. This could clutter the display unnecessarily. Consider if this change aligns with the intended UX behavior.
if len(filteredOptions) > 0 && len(item.Detail) > 0 { | |
if len(filteredOptions) > 1 && len(item.Detail) > 0 { |
Copilot uses AI. Check for mistakes.
option += fmt.Sprintf("(%v)", item.Detail) | ||
} | ||
if strings.HasPrefix(option, argInput) { | ||
options = append(options, []rune(option[len(argInput):])) | ||
offset = len(argInput) | ||
} else if len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput) { | ||
options = append(options, []rune(option)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When matching on detail, the full option string is returned without adjusting the offset. This means the completion will include the entire option text, potentially overwriting the user's input. The offset should be set to 0 when returning the full option.
options = append(options, []rune(option)) | |
options = append(options, []rune(option)) | |
offset = 0 |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clgtm and tested but only marginally.
✅ Build complete for PR #165. 🔗 Download the cmk binaries (expires on August 18, 2025) |
Fixes #48
Note: This needs exhaustive testing as it can break autocompletion
cmk-name-autocompletion.mp4