Skip to content

Commit

Permalink
Add fallbackCompletion to support module completion in ghci :add (has…
Browse files Browse the repository at this point in the history
  • Loading branch information
kmicklas authored and judah committed Oct 20, 2018
1 parent f61f592 commit 3281767
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions System/Console/Haskeline/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module System.Console.Haskeline.Completion(
Completion(..),
noCompletion,
simpleCompletion,
fallbackCompletion,
-- * Word completion
completeWord,
completeWordWithPrev,
Expand Down Expand Up @@ -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

0 comments on commit 3281767

Please # to comment.