@@ -14,6 +14,7 @@ import Idris.Parser
14import Idris.Error
14import Idris.Error
15import Idris.DataOpts
15import Idris.DataOpts
16import Idris.Completion
16import Idris.Completion
18import System.Console.Haskeline
19import System.Console.Haskeline
19import System.Console.Haskeline.History
20import System.Console.Haskeline.History
@@ -41,26 +42,31 @@ showProof lit n ps
41 break = "\n" ++ bird
42 break = "\n" ++ bird
43proverSettings :: ElabState [PDecl] -> Settings Idris
44proverSettings :: ElabState [PDecl] -> Settings Idris
44−proverSettings e = setComplete (proverCompletion assumptionNames) defaultSettings
45+proverSettings e = setComplete (proverCompletion (assumptionNames e)) defaultSettings
47+assumptionNames :: ElabState [PDecl] -> [String]
45− where assumptionNames = case envAtFocus (proof e) of
49+ = case envAtFocus (proof e) of
46− OK env -> names env
50+ OK env -> names env
47− names [] = []
51+ where names [] = []
48− names ((MN _ _, _) : bs) = names bs
52+ names ((MN _ _, _) : bs) = names bs
49− names ((n, _) : bs) = show n : names bs
53+ names ((n, _) : bs) = show n : names bs
51prove :: Context -> Bool -> Name -> Type -> Idris ()
55prove :: Context -> Bool -> Name -> Type -> Idris ()
52−prove ctxt lit n ty
56+prove ctxt lit n ty
53 = do let ps = initElaborator n ctxt ty
57 = do let ps = initElaborator n ctxt ty
58+ ideslavePutSExp "start-proof-mode" n
54 (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing) Nothing
59 (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing) Nothing
55 iLOG $ "Adding " ++ show tm
60 iLOG $ "Adding " ++ show tm
56 iputStrLn $ showProof lit n prf
61 iputStrLn $ showProof lit n prf
57 i <- getIState
62 i <- getIState
63+ ideslavePutSExp "end-proof-mode" n
58 let proofs = proof_list i
64 let proofs = proof_list i
59 putIState (i { proof_list = (n, prf) : proofs })
65 putIState (i { proof_list = (n, prf) : proofs })
60 let tree = simpleCase False True CompileTime (FC "proof" 0) [([], P Ref n ty, tm)]
66 let tree = simpleCase False True CompileTime (FC "proof" 0) [([], P Ref n ty, tm)]
61 logLvl 3 (show tree)
67 logLvl 3 (show tree)
62 (ptm, pty) <- recheckC (FC "proof" 0) [] tm
68 (ptm, pty) <- recheckC (FC "proof" 0) [] tm
63− logLvl 5 ("Proof type: " ++ show pty ++ "\n" ++
69+ logLvl 5 ("Proof type: " ++ show pty ++ "\n" ++
64 "Expected type:" ++ show ty)
70 "Expected type:" ++ show ty)
65 case converts ctxt [] ty pty of
71 case converts ctxt [] ty pty of
66 OK _ -> return ()
72 OK _ -> return ()
@@ -68,7 +74,7 @@ prove ctxt lit n ty
68 ptm' <- applyOpts ptm
74 ptm' <- applyOpts ptm
69 updateContext (addCasedef n True False True False
75 updateContext (addCasedef n True False True False
70 [Right (P Ref n ty, ptm)]
76 [Right (P Ref n ty, ptm)]
71− [([], P Ref n ty, ptm)]
77+ [([], P Ref n ty, ptm)]
72 [([], P Ref n ty, ptm')] ty)
78 [([], P Ref n ty, ptm')] ty)
73 solveDeferred n
79 solveDeferred n
74elabStep :: ElabState [PDecl] -> ElabD a -> Idris (a, ElabState [PDecl])
80elabStep :: ElabState [PDecl] -> ElabD a -> Idris (a, ElabState [PDecl])
@@ -77,13 +83,13 @@ elabStep st e = do case runStateT e st of
77 Error a -> do i <- getIState
83 Error a -> do i <- getIState
78 fail (pshow i a)
84 fail (pshow i a)
80−dumpState :: IState -> ProofState -> IO ()
86+dumpState :: IState -> ProofState -> Idris ()
81dumpState ist (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
87dumpState ist (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
82− putStrLn . render $ pretty nm <> colon <+> text "No more goals."
88+ iputGoal . render $ pretty nm <> colon <+> text "No more goals."
83dumpState ist ps@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ problems i _ _ ctxy _ _ _) = do
89dumpState ist ps@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ problems i _ _ ctxy _ _ _) = do
84 let OK ty = goalAtFocus ps
90 let OK ty = goalAtFocus ps
85 let OK env = envAtFocus ps
91 let OK env = envAtFocus ps
86− putStrLn . render $
92+ iputGoal . render $
87 prettyOtherGoals hs $$
93 prettyOtherGoals hs $$
88 prettyAssumptions env $$
94 prettyAssumptions env $$
89 prettyGoal ty
95 prettyGoal ty
@@ -124,46 +130,69 @@ lifte :: ElabState [PDecl] -> ElabD a -> Idris a
124lifte st e = do (v, _) <- elabStep st e
130lifte st e = do (v, _) <- elabStep st e
133+receiveInput :: ElabState [PDecl] -> Idris (Maybe String)
136+ l <- liftIO $ getLine
137+ let (sexp, id) = parseMessage l
138+ putIState $ i { idris_outputmode = (IdeSlave id) }
139+ case sexpToCommand sexp of
140+ Just (REPLCompletions prefix) ->
141+ do (unused, compls) <- proverCompletion (assumptionNames e) (reverse prefix, "")
142+ let good = SexpList [SymbolAtom "ok", toSExp (map replacement compls, reverse unused)]
143+ ideslavePutSExp "return" good
145+ Just (Interpret cmd) -> return (Just cmd)
146+ Nothing -> return Nothing
127ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Maybe History -> Idris (Term, [String])
148ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Maybe History -> Idris (Term, [String])
128ploop d prompt prf e h
149ploop d prompt prf e h
129 = do i <- getIState
150 = do i <- getIState
130− when d $ liftIO $ dumpState i (proof e)
151+ when d $ dumpState i (proof e)
153+ case idris_outputmode i of
131− (x, h') <- runInputT (proverSettings e) $
154+ RawOutput -> runInputT (proverSettings e) $
132− -- Manually track the history so that we can use the proof state
155+ -- Manually track the history so that we can use the proof state
133− do _ <- case h of
156+ do _ <- case h of
134− Just history -> putHistory history
157+ Just history -> putHistory history
135− Nothing -> return ()
158+ Nothing -> return ()
136− l <- getInputLine (prompt ++ "> ")
159+ l <- getInputLine (prompt ++ "> ")
137− h' <- getHistory
160+ h' <- getHistory
138− return (l, Just h')
161+ return (l, Just h')
163+ do isetPrompt prompt
139 (cmd, step) <- case x of
166 (cmd, step) <- case x of
140− Nothing -> fail "Abandoned"
167+ Nothing -> do iFail ""; fail "Abandoned"
141 Just input -> do return (parseTac i input, input)
168 Just input -> do return (parseTac i input, input)
142 case cmd of
169 case cmd of
143− Right Abandon -> fail "Abandoned"
170+ Right Abandon -> do iFail ""; fail "Abandoned"
144 _ -> return ()
171 _ -> return ()
145 (d, st, done, prf') <- idrisCatch
172 (d, st, done, prf') <- idrisCatch
146 (case cmd of
173 (case cmd of
147− Left err -> do iputStrLn (show err)
174+ Left err -> do iFail (show err)
148 return (False, e, False, prf)
175 return (False, e, False, prf)
150− do (_, st) <- elabStep e loadState
176+ Right Undo -> do (_, st) <- elabStep e loadState
151− return (True, st, False, init prf)
178+ return (True, st, False, init prf)
152− Right ProofState ->
179+ Right ProofState -> do iResult ""
153− return (True, e, False, prf)
180+ return (True, e, False, prf)
155− do tm <- lifte e get_term
181+ Right ProofTerm -> do tm <- lifte e get_term
156− iputStrLn $ "TT: " ++ show tm ++ "\n"
182+ iResult $ "TT: " ++ show tm ++ "\n"
157− return (False, e, False, prf)
183+ return (False, e, False, prf)
158 Right Qed -> do hs <- lifte e get_holes
184 Right Qed -> do hs <- lifte e get_holes
159 when (not (null hs)) $ fail "Incomplete proof"
185 when (not (null hs)) $ fail "Incomplete proof"
186+ iResult "Proof completed!"
160 return (False, e, True, prf)
187 return (False, e, True, prf)
161 Right tac -> do (_, e) <- elabStep e saveState
188 Right tac -> do (_, e) <- elabStep e saveState
162 (_, st) <- elabStep e (runTac True i tac)
189 (_, st) <- elabStep e (runTac True i tac)
163−-- trace (show (problems (proof st))) $
190+-- trace (show (problems (proof st))) $
164 return (True, st, False, prf ++ [step]))
192 return (True, st, False, prf ++ [step]))
165− (\err -> do iputStrLn (show err)
193+ (\err -> do iFail (show err)
166 return (False, e, False, prf))
194 return (False, e, False, prf))
195+ ideslavePutSExp "write-proof-state" (prf', length prf')
167 if done then do (tm, _) <- elabStep st get_term
196 if done then do (tm, _) <- elabStep st get_term
168 return (tm, prf')
197 return (tm, prf')
169 else ploop d prompt prf' st h'
198 else ploop d prompt prf' st h'