Skip to content
Snippets Groups Projects

Add command line completions for installed and available versions.

Merged Huw Campbell requested to merge HuwCampbell/ghcup-hs:topic/version-completions into master
2 unresolved threads

When running ghcup set ghc and pressing tab, it's great to be able to autocomplete the currently installed GHCs we have available.

I've added a basic optparse applicative completer for install, rm, and set commands which shows tags and versions. For installation, all are shown, while for remove and set, only those installed are.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
808 808 % _head
809 809 )
810 810 dls
811
812
813 -- Gathering monoidal values
814 traverseFold :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b
815 traverseFold f = foldl (\mb a -> (<>) <$> mb <*> f a) (pure mempty)
816
817 -- | Gathering monoidal values
818 forFold :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b
819 forFold = flip traverseFold
  • traverseFold only inlines if given one parameter. While forFold always inlines it will expand to flip traverseFold, not flip foldl (\mb a -> (<>) <$> mb <*> f a) (pure mempty), making further optimizations/fusion harder (because we don't pass an argument to traverseFold).

    To make sure forFold properly inlines, we can do:

    forFold = \t -> \f -> traverseFold f t
  • Please register or sign in to reply
  • Julian Ospald changed milestone to %0.1.13

    changed milestone to %0.1.13

  • Author Contributor

    I have also been considering disallowing the completion from making internet calls and just using the cache.

    It's a simple change of exposing readFromCache and using it instead of getDownloadsF. It feels like it makes things snappier; but maybe I should only do it for "set" and not "install".

  • I have also been considering disallowing the completion from making internet calls and just using the cache.

    Hmm, I'm not sure how ppl generally think about this. I personally have no strong opinion, but it could be considered annoying/intrusive.


    Thinking about it... I think readFromCache is the right way to go, but we also have to account for this to fail (e.g. on very first use, when nothing has been downloaded yet).

    Edited by Julian Ospald
  • Huw Campbell added 1 commit

    added 1 commit

    • d42e718f - Just use the cache for commands which refer to locally stored objects.

    Compare with previous version

  • Author Contributor

    Sounds like a reasonable plan.

    I've kept install using the network by default.

  • Huw Campbell added 1 commit

    added 1 commit

    • e1b1832f - Just use the cache for commands which refer to locally stored objects.

    Compare with previous version

  • Huw Campbell added 3 commits

    added 3 commits

    • 1a5f0259 - Just use the cache for commands which refer to locally stored objects.
    • 94bfaa1b - Respect the user's configuration settings
    • 02f3387c - Only lookup user configuration before doing a search; implement version...

    Compare with previous version

  • Huw Campbell added 1 commit

    added 1 commit

    • 453a29fd - Respect the user's configuration settings

    Compare with previous version

  • 769 toolVersionArgument =
    770 argument (eitherReader toolVersionEither) (metavar "VERSION|TAG")
    771
    768 toolVersionArgument :: Bool -> Maybe ListCriteria -> Maybe Tool -> Parser ToolVersion
    769 toolVersionArgument networkSensitive criteria tool =
    770 argument (eitherReader toolVersionEither) (metavar "VERSION|TAG" <> completer tagCompleter <> foldMap (completer . versionCompleter networkSensitive criteria) tool)
    771
    772
    773 versionArgument :: Bool -> Maybe ListCriteria -> Maybe Tool -> Parser GHCTargetVersion
    774 versionArgument networkSensitive criteria tool = argument (eitherReader tVersionEither) (metavar "VERSION" <> foldMap (completer . versionCompleter networkSensitive criteria) tool)
    775
    776
    777 tagCompleter :: Completer
    778 tagCompleter =
    779 listCompleter [
    780 "recommended", "latest"
    • We could get the list of tags from the cached file as well (and default to this list if there is no cached file). Because we have other interesting tags, such as the base version. The old tag would have to be filtered.

    • Please register or sign in to reply
  • merged

  • Please register or sign in to reply
    Loading