From 96cb99e1b5ad62cdf2c917757ccfa7235e6ba6d9 Mon Sep 17 00:00:00 2001
From: Julian Ospald <hasufell@posteo.de>
Date: Mon, 7 Mar 2022 22:23:39 +0100
Subject: [PATCH] Improve --repository completion

---
 app/ghcup/GHCup/OptParse/Common.hs  | 13 ++++++++-----
 app/ghcup/GHCup/OptParse/Compile.hs |  9 +++++++--
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/app/ghcup/GHCup/OptParse/Common.hs b/app/ghcup/GHCup/OptParse/Common.hs
index e4f7ca96..cbe4cbc0 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"]
 
+gitFileUri :: [String] -> Completer
+gitFileUri add = mkCompleter $ fileUri' (["git://"] <> add)
+
 fileUri :: Completer
-fileUri = mkCompleter fileUri'
+fileUri = mkCompleter $ fileUri' []
 
-fileUri' :: String -> IO [String]
-fileUri' = \case
+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 4ee0f7cf..67da6708 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
-- 
GitLab