[commit: packages/haskeline] master: Add fallbackCompletion to support module completion in ghci :add (#91) (3281767)
git at git.haskell.org
git at git.haskell.org
Tue Nov 27 20:23:28 UTC 2018
Repository : ssh://git@git.haskell.org/haskeline
On branch : master
Link : http://git.haskell.org/packages/haskeline.git/commitdiff/328176735bf68e1e6523648dee04b6af73d2bee2
>---------------------------------------------------------------
commit 328176735bf68e1e6523648dee04b6af73d2bee2
Author: Ken Micklas <kmicklas at gmail.com>
Date: Sat Oct 20 12:23:08 2018 -0400
Add fallbackCompletion to support module completion in ghci :add (#91)
>---------------------------------------------------------------
328176735bf68e1e6523648dee04b6af73d2bee2
System/Console/Haskeline/Completion.hs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/System/Console/Haskeline/Completion.hs b/System/Console/Haskeline/Completion.hs
index b17bb0c..04b8e9a 100644
--- a/System/Console/Haskeline/Completion.hs
+++ b/System/Console/Haskeline/Completion.hs
@@ -3,6 +3,7 @@ module System.Console.Haskeline.Completion(
Completion(..),
noCompletion,
simpleCompletion,
+ fallbackCompletion,
-- * Word completion
completeWord,
completeWordWithPrev,
@@ -188,3 +189,12 @@ fixPath ('~':c:path) | isPathSeparator c = do
home <- getHomeDirectory
return (home </> path)
fixPath path = return path
+
+-- | If the first completer produces no suggestions, fallback to the second
+-- completer's output.
+fallbackCompletion :: Monad m => CompletionFunc m -> CompletionFunc m -> CompletionFunc m
+fallbackCompletion a b input = do
+ aCompletions <- a input
+ if null (snd aCompletions)
+ then b input
+ else return aCompletions
More information about the ghc-commits
mailing list