Skip to content

Commit

Permalink
futhark repl: tweak tab completion.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Nov 7, 2024
1 parent 6ce365c commit 1ac13f0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Futhark/CLI/REPL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Monad.Except
import Control.Monad.Free.Church
import Control.Monad.State
import Data.Char
import Data.List (intersperse)
import Data.List (intersperse, isPrefixOf)
import Data.List.NonEmpty qualified as NE
import Data.Map qualified as M
import Data.Maybe
Expand Down Expand Up @@ -55,6 +55,10 @@ main = mainWithOptions () [] "options... [program.fut]" run

data StopReason = EOF | Stop | Exit | Load FilePath | Interrupt

replSettings :: Haskeline.Settings IO
replSettings =
Haskeline.setComplete replComplete Haskeline.defaultSettings

repl :: Maybe FilePath -> IO ()
repl maybe_prog = do
when fancyTerminal $ do
Expand Down Expand Up @@ -103,7 +107,7 @@ repl maybe_prog = do
pure s {futharkiLoaded = maybe_prog}
Right s ->
pure s
Haskeline.runInputT Haskeline.defaultSettings $ toploop s
Haskeline.runInputT replSettings $ toploop s

putStrLn "Leaving 'futhark repl'."

Expand Down Expand Up @@ -372,6 +376,15 @@ runInterpreterNoBreak m = runF m (pure . Right) intOp
locText w <> ": " <> "ignoring breakpoint when computating constant."
c

replComplete :: Haskeline.CompletionFunc IO
replComplete = loadComplete
where
loadComplete (prev, aft)
| ":load " `isPrefixOf` reverse prev =
Haskeline.completeFilename (prev, aft)
| otherwise =
Haskeline.noCompletion (prev, aft)

type Command = T.Text -> FutharkiM ()

loadCommand :: Command
Expand Down

0 comments on commit 1ac13f0

Please sign in to comment.