Commit 26630501 authored by Eyal Dechter's avatar Eyal Dechter

Fix up complete_reply messages (#8).

The reason that aavogt's complete_reply messages were not showing up is because the "Messagin in IPython" documentation is missing a field for the complete_reply messages. There needs to be a "matched_text" field which contains the part of the line on which completions were computed. I have added that field and it seems to work now.

FYI, I figured this out because tab completion on the notebook was raising javascript errors in the browser. For future reference, this could be a useful thing to check if something in the notebook is not working.
parent 26c22a77
......@@ -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
......@@ -33,9 +35,10 @@ 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 = []
| 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"
]
......
......@@ -200,6 +200,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