Skip to content
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

fix: improve zsh completion suggestions #1933

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Valgard
Copy link

@Valgard Valgard commented Feb 10, 2025

improve zsh completion suggestions with flags, git refs, versions, etc.

@Valgard Valgard requested a review from a team as a code owner February 10, 2025 04:15
#compdef asdf
#description tool to manage versions of multiple runtimes

# Initialize local variables for ZSH completion context
local curcontext="$curcontext" state state_descr line subcmd
Copy link
Member

@Stratus3D Stratus3D Feb 10, 2025

Choose a reason for hiding this comment

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

I don't see curcontext used anywhere. Can it be removed?

Same comment about state_descr.

Copy link
Author

Choose a reason for hiding this comment

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

remove unused variables

Copy link
Member

@Stratus3D Stratus3D left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Valgard ! I'm going to test these changes out today and merge if they work as expected.

By the way, do you happen to know if there are any automated tools for validation completion code? Manual testing has been pretty time consuming for me.

Copy link
Member

@Stratus3D Stratus3D left a comment

Choose a reason for hiding this comment

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

I type asdf plugin list and hit tab and it converts the command to asdf plugin postgres. Unclear why this occurs.

@Valgard
Copy link
Author

Valgard commented Feb 11, 2025

By the way, do you happen to know if there are any automated tools for validation completion code? Manual testing has been pretty time consuming for me.

Hey, I'm not an expert, but as far as I know, there are only two test frameworks that support shell completion tests (both supports ZSH):

  • bats (https://github.com/bats-core/bats-core)
    #!/usr/bin/env bats
    
    # Lade die asdf ZSH Completion-Definitionen
    load '/usr/local/share/zsh/site-functions/_asdf'
    
    @test "asdf command completion includes 'plugin'" {
        words=(asdf '')
        CURRENT=2
        
        run _asdf
        
        [ "$status" -eq 0 ]
        [[ "${lines[@]}" =~ "plugin" ]]
    }
    
    @test "asdf plugin completion includes 'list'" {
        words=(asdf plugin '')
        CURRENT=3
        
        run _asdf
        
        [ "$status" -eq 0 ]
        [[ "${lines[@]}" =~ "list" ]]
    }
    
    @test "asdf plugin list has no further completions" {
        words=(asdf plugin list '')
        CURRENT=4
        
        run _asdf
        
        [ "$status" -eq 0 ]
        [ ${#lines[@]} -eq 0 ]  # Erwarte keine weiteren Completions
    }
    
  • shellspec (https://github.com/shellspec/shellspec)
    Describe 'asdf zsh completion'
      Include '/usr/local/share/zsh/site-functions/_asdf'
    
      Example 'completes plugin command'
        Set 'words' "asdf "
        Set 'CURRENT' 2
        When call _asdf
        The stdout should include 'plugin'
      End
    
      Example 'completes plugin subcommands'
        Set 'words' "asdf plugin "
        Set 'CURRENT' 3
        When call _asdf
        The stdout should include 'list'
      End
    
      Example 'plugin list has no further completions'
        Set 'words' "asdf plugin list "
        Set 'CURRENT' 4
        When call _asdf
        The stdout should equal ''  # Erwarte leere Ausgabe
      End
    
      # Optional: Test für teilweise eingegebene Befehle
      Example 'completes partial plugin command'
        Set 'words' "asdf plu"
        Set 'CURRENT' 2
        When call _asdf
        The stdout should include 'plugin'
      End
    End
    

@Valgard Valgard closed this Feb 11, 2025
@Valgard Valgard reopened this Feb 11, 2025
@Valgard Valgard force-pushed the master branch 2 times, most recently from 21f528a to cab4f7b Compare February 11, 2025 13:28
@Valgard
Copy link
Author

Valgard commented Feb 11, 2025

I type asdf plugin list and hit tab and it converts the command to asdf plugin postgres. Unclear why this occurs.

I'm really sorry, but I can't reproduce this behaviour.

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.

2 participants