Commit adfa3af9 authored by Eyal Dechter's avatar Eyal Dechter

Merge branch 'notebook_completions' into directives

parents fc177677 26630501
......@@ -15,7 +15,7 @@ module IHaskell.Completion (makeCompletions) where
import Prelude
import Data.List
import IHaskell.Types
import GhcMonad(liftIO)
import GhcMonad(liftIO, GhcMonad)
import qualified GHC
import Outputable (showPpr)
import Data.Char
......@@ -26,6 +26,8 @@ import Data.Aeson
import IHaskell.Message.Writer
import qualified Data.ByteString.Lazy as L
makeCompletions
:: GHC.GhcMonad m => MessageHeader -> Message -> m Message
makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
ns <- GHC.getRdrNamesInScope
......@@ -34,8 +36,9 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
let candidate = getWordAt (toString line) pos
opts | Just cand <- candidate = filter (cand `isPrefixOf`) $ map (showPpr fs) ns
| otherwise = []
matched_text = fromString $ maybe "" id candidate
let reply = CompleteReply replyHeader (map fromString opts) line True
let reply = CompleteReply replyHeader (map fromString opts) matched_text line True
liftIO (L.putStrLn $ encode $ toJSON reply)
return reply
......
......@@ -56,8 +56,9 @@ instance ToJSON Message where
"execution_count" .= execCount,
"code" .= code
]
toJSON (CompleteReply _ m t s) = object [
toJSON (CompleteReply _ m mt t s) = object [
"matches" .= m,
"matched_text" .= mt,
"text" .= t,
"status" .= if s then "ok" :: String else "error"
]
......
......@@ -204,6 +204,7 @@ data Message
| CompleteReply {
header :: MessageHeader,
completionMatches :: [ByteString],
completionMatchedText :: ByteString,
completionText :: ByteString,
completionStatus :: Bool
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment