Skip to content

Conversation

shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Jul 31, 2025

Fixes #48

cmk-name-autocompletion.mp4

Fixes apache#48

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Copy link

@Copilot Copilot AI left a 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 {
Copy link
Preview

Copilot AI Aug 5, 2025

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.

Suggested change
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))
Copy link
Preview

Copilot AI Aug 5, 2025

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.

Suggested change
options = append(options, []rune(option))
options = append(options, []rune(option))
offset = 0

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@DaanHoogland DaanHoogland left a 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.

@shwstppr shwstppr added this to the 6.5.0 milestone Aug 6, 2025
@shwstppr shwstppr marked this pull request as ready for review August 8, 2025 09:28
@shwstppr shwstppr closed this Aug 8, 2025
@shwstppr shwstppr reopened this Aug 8, 2025
Copy link

github-actions bot commented Aug 8, 2025

✅ Build complete for PR #165.

🔗 Download the cmk binaries (expires on August 30, 2025)

@rohityadavcloud rohityadavcloud modified the milestones: 6.5.0, 6.6.0 Aug 11, 2025
Copy link

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

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

LGTM , Deploy 2 vms( vm1, vm2) , 2 networks (tier1, tier2)

Before fix autocompletion for the vmname was not working

(admin) 🐱 > list virtualmachines id=v

(admin) 🐱 > list networks id=t

After fix

bin/cmk
(admin) 🐱 > list virtualmachines id=v
0782866e-2c93-4c33-9434-05506e63ed0a (vm1)     80f8201f-794d-4d44-b934-6794df000388 (vm2)


(admin) 🐱 > list networks id=t
8e5d9efd-8bd2-452c-b004-77537f059590 (tier2)   d6b6622e-8ed4-4c5e-84c2-e038c14f2d9a (tier1)

@shwstppr
Copy link
Contributor Author

This is a good to have. If we are confident with testing we can include it in 6.5.0 milestone.
cc @DaanHoogland @rohityadavcloud @kiranchavala

@shwstppr shwstppr changed the title autocomplete: allow completion based on name/detail autocomplete: allow autocompletion based on name/detail of exisiting results for parameter Aug 25, 2025
@shwstppr shwstppr changed the title autocomplete: allow autocompletion based on name/detail of exisiting results for parameter autocomplete: allow completion based on name/detail of exisiting results for parameter Aug 25, 2025
Copy link

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

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

LGTM, Tested various List api calls

https://cloudstack.apache.org/api/apidocs-4.20/

The autocompletion works fine on the existing results of a parameter

Screenshot 2025-08-25 at 5 45 33 PM Screenshot 2025-08-25 at 5 44 16 PM Screenshot 2025-08-25 at 5 30 03 PM Screenshot 2025-08-25 at 5 29 11 PM Screenshot 2025-08-25 at 5 25 26 PM

@shwstppr shwstppr modified the milestones: 6.6.0, 6.5.0 Aug 25, 2025
@shwstppr shwstppr merged commit 03342d0 into apache:main Aug 25, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement better filtering for autocompletion
4 participants