From 96cb99e1b5ad62cdf2c917757ccfa7235e6ba6d9 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Mar 2022 22:23:39 +0100 Subject: [PATCH] Improve --repository completion --- app/ghcup/GHCup/OptParse/Common.hs | 15 +++++++++------ app/ghcup/GHCup/OptParse/Compile.hs | 9 +++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/ghcup/GHCup/OptParse/Common.hs b/app/ghcup/GHCup/OptParse/Common.hs index e4f7ca9..cbe4cbc 100644 --- a/app/ghcup/GHCup/OptParse/Common.hs +++ b/app/ghcup/GHCup/OptParse/Common.hs @@ -302,14 +302,17 @@ gpgParser s' | t == T.pack "strict" = Right GPGStrict toolCompleter :: Completer toolCompleter = listCompleter ["ghc", "cabal", "hls", "stack"] -fileUri :: Completer -fileUri = mkCompleter fileUri' +gitFileUri :: [String] -> Completer +gitFileUri add = mkCompleter $ fileUri' (["git://"] <> add) -fileUri' :: String -> IO [String] -fileUri' = \case +fileUri :: Completer +fileUri = mkCompleter $ fileUri' [] + +fileUri' :: [String] -> String -> IO [String] +fileUri' add = \case "" -> do pwd <- getCurrentDirectory - pure ["https://", "http://", "file:///", "file://" <> pwd <> "/"] + pure $ ["https://", "http://", "file:///", "file://" <> pwd <> "/"] <> add xs | "file:///" `isPrefixOf` xs -> fmap ("file://" <>) <$> case stripPrefix "file://" xs of @@ -476,7 +479,7 @@ toolDlCompleter :: Tool -> Completer toolDlCompleter tool = mkCompleter $ \case "" -> pure (initUrl tool <> ["https://", "http://", "file:///"]) word - | "file://" `isPrefixOf` word -> fileUri' word + | "file://" `isPrefixOf` word -> fileUri' [] word -- downloads.haskell.org | "https://downloads.haskell.org/" `isPrefixOf` word -> fmap (completePrefix word) . prefixMatch (FP.takeFileName word) <$> fromHRef word diff --git a/app/ghcup/GHCup/OptParse/Compile.hs b/app/ghcup/GHCup/OptParse/Compile.hs index 4ee0f7c..67da670 100644 --- a/app/ghcup/GHCup/OptParse/Compile.hs +++ b/app/ghcup/GHCup/OptParse/Compile.hs @@ -173,7 +173,10 @@ ghcCompileOpts = (short 'g' <> long "git-ref" <> metavar "GIT_REFERENCE" <> help "The git commit/branch/ref to build from" ) <*> - optional (option str (short 'r' <> long "repository" <> metavar "GIT_REPOSITORY" <> help "The git repository to build from (defaults to GHC upstream)")) + optional (option str ( + short 'r' <> long "repository" <> metavar "GIT_REPOSITORY" <> help "The git repository to build from (defaults to GHC upstream)" + <> completer (gitFileUri ["https://gitlab.haskell.org/ghc/ghc.git"]) + )) ))) <*> option (eitherReader @@ -285,7 +288,9 @@ hlsCompileOpts = (short 'g' <> long "git-ref" <> metavar "GIT_REFERENCE" <> help "The git commit/branch/ref to build from" ) <*> - optional (option str (short 'r' <> long "repository" <> metavar "GIT_REPOSITORY" <> help "The git repository to build from (defaults to GHC upstream)")) + optional (option str (short 'r' <> long "repository" <> metavar "GIT_REPOSITORY" <> help "The git repository to build from (defaults to GHC upstream)" + <> completer (gitFileUri ["https://github.com/haskell/haskell-language-server.git"]) + )) ))) <*> optional (option