Commit c8ee3d8e authored by Andrew Gibiansky's avatar Andrew Gibiansky

Merge pull request #468 from sumitsahrawat/tooltip

Prevent kernel death on introspection.
parents 602939ad 1fb17401
...@@ -90,7 +90,7 @@ data KernelConfig m output result = ...@@ -90,7 +90,7 @@ data KernelConfig m output result =
, completion :: T.Text -> T.Text -> Int -> Maybe ([T.Text], T.Text, T.Text) , completion :: T.Text -> T.Text -> Int -> Maybe ([T.Text], T.Text, T.Text)
-- | Return the information or documentation for its argument. The returned tuple consists of the -- | Return the information or documentation for its argument. The returned tuple consists of the
-- name, the documentation, and the type, respectively. -- name, the documentation, and the type, respectively.
, objectInfo :: T.Text -> Maybe (T.Text, T.Text, T.Text) , inspectInfo :: T.Text -> Maybe (T.Text, T.Text, T.Text)
-- | Execute a cell. The arguments are the contents of the cell, an IO action that will clear the -- | Execute a cell. The arguments are the contents of the cell, an IO action that will clear the
-- current intermediate output, and an IO action that will add a new item to the intermediate -- current intermediate output, and an IO action that will add a new item to the intermediate
-- output. The result consists of the actual result, the status to be sent to IPython, and the -- output. The result consists of the actual result, the status to be sent to IPython, and the
...@@ -228,25 +228,10 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe ...@@ -228,25 +228,10 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe
replyTo config _ _ req@CompleteRequest{} replyHeader = replyTo config _ _ req@CompleteRequest{} replyHeader =
-- TODO: FIX -- TODO: FIX
error "Unimplemented in IPython 3.0" error "Completion: Unimplemented for IPython 3.0"
replyTo config _ _ ObjectInfoRequest { objectName = obj } replyHeader = replyTo _ _ _ InspectRequest{} _ = do
return $ error $ "Inspection: Unimplemented for IPython 3.0"
case objectInfo config obj of
Just (name, docs, ty) -> ObjectInfoReply
{ header = replyHeader
, objectName = obj
, objectFound = True
, objectTypeString = ty
, objectDocString = docs
}
Nothing -> ObjectInfoReply
{ header = replyHeader
, objectName = obj
, objectFound = False
, objectTypeString = ""
, objectDocString = ""
}
replyTo _ _ _ msg _ = do replyTo _ _ _ msg _ = do
liftIO $ putStrLn "Unknown message: " liftIO $ putStrLn "Unknown message: "
......
...@@ -74,7 +74,7 @@ parser :: MessageType -- ^ The message type being parsed. ...@@ -74,7 +74,7 @@ parser :: MessageType -- ^ The message type being parsed.
parser KernelInfoRequestMessage = kernelInfoRequestParser parser KernelInfoRequestMessage = kernelInfoRequestParser
parser ExecuteRequestMessage = executeRequestParser parser ExecuteRequestMessage = executeRequestParser
parser CompleteRequestMessage = completeRequestParser parser CompleteRequestMessage = completeRequestParser
parser ObjectInfoRequestMessage = objectInfoRequestParser parser InspectRequestMessage = inspectRequestParser
parser ShutdownRequestMessage = shutdownRequestParser parser ShutdownRequestMessage = shutdownRequestParser
parser InputReplyMessage = inputReplyParser parser InputReplyMessage = inputReplyParser
parser CommOpenMessage = commOpenParser parser CommOpenMessage = commOpenParser
...@@ -139,11 +139,12 @@ completeRequestParser = requestParser $ \obj -> do ...@@ -139,11 +139,12 @@ completeRequestParser = requestParser $ \obj -> do
pos <- obj .: "cursor_pos" pos <- obj .: "cursor_pos"
return $ CompleteRequest noHeader code pos return $ CompleteRequest noHeader code pos
objectInfoRequestParser :: LByteString -> Message inspectRequestParser :: LByteString -> Message
objectInfoRequestParser = requestParser $ \obj -> do inspectRequestParser = requestParser $ \obj -> do
oname <- obj .: "oname" code <- obj .: "code"
pos <- obj .: "cursor_pos"
dlevel <- obj .: "detail_level" dlevel <- obj .: "detail_level"
return $ ObjectInfoRequest noHeader oname dlevel return $ InspectRequest noHeader code pos dlevel
shutdownRequestParser :: LByteString -> Message shutdownRequestParser :: LByteString -> Message
shutdownRequestParser = requestParser $ \obj -> do shutdownRequestParser = requestParser $ \obj -> do
......
...@@ -65,15 +65,13 @@ instance ToJSON Message where ...@@ -65,15 +65,13 @@ instance ToJSON Message where
then string "ok" then string "ok"
else "error" else "error"
] ]
toJSON o@ObjectInfoReply{} = toJSON i@InspectReply{} =
object object
[ "oname" .= [ "status" .= if inspectStatus i
objectName o then string "ok"
, "found" .= objectFound o else "error"
, "ismagic" .= False , "data" .= object (map displayDataToJson . inspectData $ i)
, "isalias" .= False , "metadata" .= object []
, "type_name" .= objectTypeString o
, "docstring" .= objectDocString o
] ]
toJSON ShutdownReply { restartPending = restart } = toJSON ShutdownReply { restartPending = restart } =
......
...@@ -176,8 +176,8 @@ data MessageType = KernelInfoReplyMessage ...@@ -176,8 +176,8 @@ data MessageType = KernelInfoReplyMessage
| InputMessage | InputMessage
| CompleteRequestMessage | CompleteRequestMessage
| CompleteReplyMessage | CompleteReplyMessage
| ObjectInfoRequestMessage | InspectRequestMessage
| ObjectInfoReplyMessage | InspectReplyMessage
| ShutdownRequestMessage | ShutdownRequestMessage
| ShutdownReplyMessage | ShutdownReplyMessage
| ClearOutputMessage | ClearOutputMessage
...@@ -202,8 +202,8 @@ showMessageType OutputMessage = "pyout" ...@@ -202,8 +202,8 @@ showMessageType OutputMessage = "pyout"
showMessageType InputMessage = "pyin" showMessageType InputMessage = "pyin"
showMessageType CompleteRequestMessage = "complete_request" showMessageType CompleteRequestMessage = "complete_request"
showMessageType CompleteReplyMessage = "complete_reply" showMessageType CompleteReplyMessage = "complete_reply"
showMessageType ObjectInfoRequestMessage = "object_info_request" showMessageType InspectRequestMessage = "inspect_request"
showMessageType ObjectInfoReplyMessage = "object_info_reply" showMessageType InspectReplyMessage = "inspect_reply"
showMessageType ShutdownRequestMessage = "shutdown_request" showMessageType ShutdownRequestMessage = "shutdown_request"
showMessageType ShutdownReplyMessage = "shutdown_reply" showMessageType ShutdownReplyMessage = "shutdown_reply"
showMessageType ClearOutputMessage = "clear_output" showMessageType ClearOutputMessage = "clear_output"
...@@ -229,8 +229,8 @@ instance FromJSON MessageType where ...@@ -229,8 +229,8 @@ instance FromJSON MessageType where
"pyin" -> return InputMessage "pyin" -> return InputMessage
"complete_request" -> return CompleteRequestMessage "complete_request" -> return CompleteRequestMessage
"complete_reply" -> return CompleteReplyMessage "complete_reply" -> return CompleteReplyMessage
"object_info_request" -> return ObjectInfoRequestMessage "inspect_request" -> return InspectRequestMessage
"object_info_reply" -> return ObjectInfoReplyMessage "inspect_reply" -> return InspectReplyMessage
"shutdown_request" -> return ShutdownRequestMessage "shutdown_request" -> return ShutdownRequestMessage
"shutdown_reply" -> return ShutdownReplyMessage "shutdown_reply" -> return ShutdownReplyMessage
"clear_output" -> return ClearOutputMessage "clear_output" -> return ClearOutputMessage
...@@ -326,20 +326,22 @@ data Message = ...@@ -326,20 +326,22 @@ data Message =
, completionStatus :: Bool , completionStatus :: Bool
} }
| |
ObjectInfoRequest InspectRequest
{ header :: MessageHeader { header :: MessageHeader
-- | Name of object being searched for. -- | The code context in which introspection is requested
, objectName :: Text , inspectCode :: Text
-- | Position of the cursor in unicode characters. json field @cursor_pos@
, inspectCursorPos :: Int
-- | Level of detail desired (defaults to 0). 0 is equivalent to foo?, 1 is equivalent to foo??. -- | Level of detail desired (defaults to 0). 0 is equivalent to foo?, 1 is equivalent to foo??.
, detailLevel :: Int , detailLevel :: Int
} }
| |
ObjectInfoReply InspectReply
{ header :: MessageHeader { header :: MessageHeader
, objectName :: Text -- ^ Name of object which was searched for. -- | whether the request succeeded or failed
, objectFound :: Bool -- ^ Whether the object was found. , inspectStatus :: Bool
, objectTypeString :: Text -- ^ Object type. -- | @inspectData@ can be empty if nothing is found
, objectDocString :: Text , inspectData :: [DisplayData]
} }
| |
ShutdownRequest ShutdownRequest
...@@ -422,7 +424,7 @@ replyType :: MessageType -> Maybe MessageType ...@@ -422,7 +424,7 @@ replyType :: MessageType -> Maybe MessageType
replyType KernelInfoRequestMessage = Just KernelInfoReplyMessage replyType KernelInfoRequestMessage = Just KernelInfoReplyMessage
replyType ExecuteRequestMessage = Just ExecuteReplyMessage replyType ExecuteRequestMessage = Just ExecuteReplyMessage
replyType CompleteRequestMessage = Just CompleteReplyMessage replyType CompleteRequestMessage = Just CompleteReplyMessage
replyType ObjectInfoRequestMessage = Just ObjectInfoReplyMessage replyType InspectRequestMessage = Just InspectReplyMessage
replyType ShutdownRequestMessage = Just ShutdownReplyMessage replyType ShutdownRequestMessage = Just ShutdownReplyMessage
replyType HistoryRequestMessage = Just HistoryReplyMessage replyType HistoryRequestMessage = Just HistoryReplyMessage
replyType _ = Nothing replyType _ = Nothing
......
{-# LANGUAGE NoImplicitPrelude, QuasiQuotes, ViewPatterns #-} {-# LANGUAGE FlexibleContexts, NoImplicitPrelude, QuasiQuotes, ViewPatterns #-}
module IHaskell.Eval.Lint (lint) where module IHaskell.Eval.Lint (lint) where
......
...@@ -19,6 +19,7 @@ import Text.Printf ...@@ -19,6 +19,7 @@ import Text.Printf
import System.Posix.Signals import System.Posix.Signals
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.String.Here (hereFile) import Data.String.Here (hereFile)
import qualified Data.Text as T
-- IHaskell imports. -- IHaskell imports.
import IHaskell.Convert (convert) import IHaskell.Convert (convert)
...@@ -334,17 +335,10 @@ replyTo _ req@CompleteRequest{} replyHeader state = do ...@@ -334,17 +335,10 @@ replyTo _ req@CompleteRequest{} replyHeader state = do
reply = CompleteReply replyHeader (map pack completions) start end Map.empty True reply = CompleteReply replyHeader (map pack completions) start end Map.empty True
return (state, reply) return (state, reply)
-- Reply to the object_info_request message. Given an object name, return the associated type -- TODO: Implement inspect_reply
-- calculated by GHC. replyTo _ InspectRequest{} replyHeader state = do
replyTo _ ObjectInfoRequest { objectName = oname } replyHeader state = do -- FIXME
docs <- pack <$> info (unpack oname) let reply = InspectReply { header = replyHeader, inspectStatus = False, inspectData = [] }
let reply = ObjectInfoReply
{ header = replyHeader
, objectName = oname
, objectFound = strip docs /= ""
, objectTypeString = docs
, objectDocString = docs
}
return (state, reply) return (state, reply)
-- TODO: Implement history_reply. -- TODO: Implement history_reply.
......
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