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 ...@@ -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
...@@ -33,9 +35,10 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do ...@@ -33,9 +35,10 @@ 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"
] ]
......
...@@ -204,6 +204,7 @@ data Message ...@@ -204,6 +204,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