on master help sign in
Add IDESlave command for getting documentation

This is used by Emacs to get documentation for the symbol at point.

commit71b477b72f534a76ecdcb0ed211565bb3f57c31c authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateWed 19 Feb 2014, 09:43 (13 years ago) parentdbad038
2 files changed+15−6
src/Idris/IdeSlave.hs+2 src/Idris/REPL.hs+13−6
src/Idris/IdeSlave.hs+2
@@ -130,6 +130,7 @@ data IdeSlaveCommand = REPLCompletions String
130130 | MakeWithBlock Int String
131131 | ProofSearch Int String [String]
132132 | LoadFile String
133+ | DocsFor String
133134 deriving Show
134135
135136sexpToCommand :: SExp -> Maybe IdeSlaveCommand
@@ -147,6 +148,7 @@ sexpToCommand (SexpList [SymbolAtom "proof-search", IntegerAtom line, StringAtom
147148 where getHints = mapM (\h -> case h of
148149 StringAtom s -> Just s
149150 _ -> Nothing)
151+sexpToCommand (SexpList [SymbolAtom "docs-for", StringAtom name]) = Just (DocsFor name)
150152sexpToCommand _ = Nothing
151153
152154parseMessage :: String -> Either Err (SExp, Integer)
src/Idris/REPL.hs+13−6
@@ -251,12 +251,14 @@ ideslave orig mods
251251 Just x -> iPrintError $ "didn't load " ++ filename
252252 ideslave orig [filename]
253253 Just (IdeSlave.TypeOf name) ->
254− case reverse $ splitOn "." name of
255− [] -> iPrintError ("Didn't understand name '" ++ name ++ "'")
256− [n] -> process stdout "(ideslave)"
257− (Check (PRef (FC "(ideslave)" 0 0) (sUN n)))
258− (n:ns) -> process stdout "(ideslave)"
259− (Check (PRef (FC "(ideslave)" 0 0) (sNS (sUN n) ns)))
254+ case splitName name of
255+ Left err -> iPrintError err
256+ Right n -> process stdout "(ideslave)"
257+ (Check (PRef (FC "(ideslave)" 0 0) n))
258+ Just (IdeSlave.DocsFor name) ->
259+ case splitName name of
260+ Left err -> iPrintError err
261+ Right n -> process stdout "(ideslave)" (DocStr n)
260262 Just (IdeSlave.CaseSplit line name) ->
261263 process stdout fn (CaseSplitAt False line (sUN name))
262264 Just (IdeSlave.AddClause line name) ->
@@ -273,6 +275,11 @@ ideslave orig mods
273275 (\e -> do iPrintError $ show e))
274276 (\e -> do iPrintError $ show e)
275277 ideslave orig mods
278+ where splitName :: String -> Either String Name
279+ splitName s = case reverse $ splitOn "." s of
280+ [] -> Left ("Didn't understand name '" ++ s ++ "'")
281+ [n] -> Right $ sUN n
282+ (n:ns) -> Right $ sNS (sUN n) ns
276283
277284ideslaveProcess :: FilePath -> Command -> Idris ()
278285ideslaveProcess fn Help = process stdout fn Help