Skip to content

Commit 87c1cb6

Browse files
committed
[ repl ] better printing of holes
* Fixed printing in the IDEMode (& include highlighting) * Now also print the type of the holes
1 parent 2e98dd6 commit 87c1cb6

File tree

10 files changed

+44
-10
lines changed

10 files changed

+44
-10
lines changed

src/Idris/IDEMode/REPL.idr

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import Idris.Resugar
3030
import Idris.REPL
3131
import Idris.Syntax
3232
import Idris.Version
33-
import Idris.Pretty
3433
import Idris.Doc.String
3534

3635
import Idris.IDEMode.Commands
@@ -385,7 +384,17 @@ displayIDEResult outf i (REPL $ CheckedTotal xs)
385384
$ StringAtom $ showSep "\n"
386385
$ map (\ (fn, tot) => (show fn ++ " is " ++ show tot)) xs
387386
displayIDEResult outf i (REPL $ FoundHoles holes)
388-
= printIDEResult outf i $ SExpList $ map sexpHole holes
387+
= printIDEResultWithHighlight outf i =<< case holes of
388+
[] => pure (StringAtom "No holes", [])
389+
[x] => do let hole = pretty x.name <++> colon <++> prettyTerm x.type
390+
hlght <- renderWithDecorations syntaxToProperties
391+
$ "1 hole" <+> colon <++> hole
392+
pure $ mapFst StringAtom hlght
393+
xs => do let holes = xs <&> \ x => pretty x.name <++> colon <++> prettyTerm x.type
394+
let header = pretty (length xs) <++> pretty "holes" <+> colon
395+
hlght <- renderWithDecorations syntaxToProperties
396+
$ vcat (header :: map (indent 2) holes)
397+
pure $ mapFst StringAtom hlght
389398
displayIDEResult outf i (REPL $ LogLevelSet k)
390399
= printIDEResult outf i
391400
$ StringAtom $ "Set loglevel to " ++ show k

src/Idris/REPL.idr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,10 +1093,13 @@ mutual
10931093
displayResult (Missed cases) = printResult $ vsep (handleMissing <$> cases)
10941094
displayResult (CheckedTotal xs) = printResult (vsep (map (\(fn, tot) => pretty fn <++> pretty "is" <++> pretty tot) xs))
10951095
displayResult (FoundHoles []) = printResult (reflow "No holes")
1096-
displayResult (FoundHoles [x]) = printResult (reflow "1 hole" <+> colon <++> pretty x.name)
1096+
displayResult (FoundHoles [x]) = do
1097+
let hole = pretty x.name <++> colon <++> prettyTerm x.type
1098+
printResult (reflow "1 hole" <+> colon <++> hole)
10971099
displayResult (FoundHoles xs) = do
1098-
let holes = concatWith (surround (pretty ", ")) (pretty . name <$> xs)
1099-
printResult (pretty (length xs) <++> pretty "holes" <+> colon <++> holes)
1100+
let header = pretty (length xs) <++> pretty "holes" <+> colon
1101+
let holes = xs <&> \ x => pretty x.name <++> colon <++> prettyTerm x.type
1102+
printResult $ vcat (header :: map (indent 2) holes)
11001103
displayResult (LogLevelSet Nothing) = printResult (reflow "Logging turned off")
11011104
displayResult (LogLevelSet (Just k)) = printResult (reflow "Set log level to" <++> pretty k)
11021105
displayResult (ConsoleWidthSet (Just k)) = printResult (reflow "Set consolewidth to" <++> pretty k)

tests/Main.idr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ idrisTestsInteractive = MkTestPool "Interactive editing" [] Nothing
8686
"interactive021", "interactive022", "interactive023", "interactive024",
8787
"interactive025", "interactive026", "interactive027", "interactive028",
8888
"interactive029", "interactive030", "interactive031", "interactive032",
89-
"interactive033", "interactive034", "interactive035", "interactive036"]
89+
"interactive033", "interactive034", "interactive035", "interactive036",
90+
"interactive037"]
9091

9192
idrisTestsInterface : TestPool
9293
idrisTestsInterface = MkTestPool "Interface" [] Nothing

tests/idris2/basic049/expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ Fld:72:26--72:29
5555
Main> Main.myDog : OrdinaryDog
5656
Main> Main.mySuperDog : SuperDog
5757
Main> Main.other : Other String
58-
Main> 1 hole: Main.r2_shouldNotTypecheck1
58+
Main> 1 hole: Main.r2_shouldNotTypecheck1 : ?_ [no locals in scope]
5959
Main> Bye for now!

tests/idris2/import003/expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
1/2: Building A (A.idr)
22
2/2: Building B (B.idr)
3-
B> 1 hole: A.defA
3+
B> 1 hole: A.defA : Int -> Int
44
B> Bye for now!
55
2/2: Building C (C.idr)
6-
C> 1 hole: C.newHole
6+
C> 1 hole: C.newHole : Int -> Int
77
C> Bye for now!

tests/idris2/interactive037/Holes.idr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Holes
2+
3+
int : Int
4+
int = ?a
5+
6+
nat : Nat
7+
nat = ?b
8+
9+
equal : cast Holes.int === Holes.nat
10+
equal = ?c

tests/idris2/interactive037/expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1/1: Building Holes (Holes.idr)
2+
Holes> 3 holes:
3+
Holes.a : Int
4+
Holes.b : Nat
5+
Holes.c : integerToNat (prim__cast_IntInteger ?a) = ?b
6+
Holes> Bye for now!

tests/idris2/interactive037/input

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:m
2+
:q

tests/idris2/interactive037/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf build
2+
3+
$1 --no-color --console-width 0 --no-banner Holes.idr < input

tests/idris2/perror010/expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ TrailingLam:3:9--3:22
3535
3 | f k = f \n => k (S n)
3636
^^^^^^^^^^^^^
3737

38-
Main> 1 hole: Main.a
38+
Main> 1 hole: Main.a : Nat -> Nat
3939
Main>
4040
Bye for now!

0 commit comments

Comments
 (0)