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 ...@@ -15,7 +15,7 @@ module IHaskell.Completion (makeCompletions) where
import Prelude import Prelude
import Data.List import Data.List
import IHaskell.Types import IHaskell.Types
import GhcMonad(liftIO) import GhcMonad(liftIO, GhcMonad)
import qualified GHC import qualified GHC
import Outputable (showPpr) import Outputable (showPpr)
import Data.Char import Data.Char
...@@ -26,6 +26,8 @@ import Data.Aeson ...@@ -26,6 +26,8 @@ import Data.Aeson
import IHaskell.Message.Writer import IHaskell.Message.Writer
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
makeCompletions
:: GHC.GhcMonad m => MessageHeader -> Message -> m Message
makeCompletions replyHeader (CompleteRequest hdr code line pos) = do makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
ns <- GHC.getRdrNamesInScope ns <- GHC.getRdrNamesInScope
...@@ -34,8 +36,9 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do ...@@ -34,8 +36,9 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
let candidate = getWordAt (toString line) pos let candidate = getWordAt (toString line) pos
opts | Just cand <- candidate = filter (cand `isPrefixOf`) $ map (showPpr fs) ns 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) liftIO (L.putStrLn $ encode $ toJSON reply)
return reply return reply
......
...@@ -56,8 +56,9 @@ instance ToJSON Message where ...@@ -56,8 +56,9 @@ instance ToJSON Message where
"execution_count" .= execCount, "execution_count" .= execCount,
"code" .= code "code" .= code
] ]
toJSON (CompleteReply _ m t s) = object [ toJSON (CompleteReply _ m mt t s) = object [
"matches" .= m, "matches" .= m,
"matched_text" .= mt,
"text" .= t, "text" .= t,
"status" .= if s then "ok" :: String else "error" "status" .= if s then "ok" :: String else "error"
] ]
......
...@@ -200,6 +200,7 @@ data Message ...@@ -200,6 +200,7 @@ data Message
| CompleteReply { | CompleteReply {
header :: MessageHeader, header :: MessageHeader,
completionMatches :: [ByteString], completionMatches :: [ByteString],
completionMatchedText :: ByteString,
completionText :: ByteString, completionText :: ByteString,
completionStatus :: Bool 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