Commit a061e229 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Update to newest kernel_info_reply protocol

parent 45011f5a
*.hi
Untitled*.ipynb
main/Main
.stack-work
notebooks/Test.ipynb
......
name: ipython-kernel
version: 0.6.1.3
version: 0.7
synopsis: A library for creating kernels for IPython frontends
description: ipython-kernel is a library for communicating with frontends for the interactive IPython framework. It is used extensively in IHaskell, the interactive Haskell environment.
......
......@@ -70,11 +70,8 @@ import System.IO (openFile, IOMode(ReadMode))
data KernelConfig m output result =
KernelConfig
{
-- | The name of the language. This field is used to calculate the name of the profile,
-- so it should contain characters that are reasonable to have in file names.
languageName :: String
-- | The version of the language
, languageVersion :: [Int]
-- | Info on the language of the kernel.
kernelLanguageInfo :: LanguageInfo
-- | Determine the source of a profile to install using 'installProfile'. The source should be a
-- tarball whose contents will be unpacked directly into the profile directory. For example, the
-- file whose name is @ipython_config.py@ in the tar file for a language named @lang@ will end up in
......@@ -122,7 +119,7 @@ installProfile config = do
where
profDir = do
home <- liftIO getHomeDirectory
return $ home </> ".ipython" </> ("profile_" ++ languageName config)
return $ home </> ".ipython" </> ("profile_" ++ languageName (kernelLanguageInfo config))
isInstalled = do
prof <- profDir
dirThere <- liftIO $ doesDirectoryExist prof
......@@ -185,8 +182,9 @@ replyTo config _ _ KernelInfoRequest{} replyHeader =
return
KernelInfoReply
{ header = replyHeader
, language = languageName config
, versionList = languageVersion config
, languageInfo = kernelLanguageInfo config
, implementation = "ipython-kernel.EasyKernel"
, implementationVersion = "0.0"
}
replyTo config _ interface ShutdownRequest { restartPending = pending } replyHeader = do
liftIO $ writeChan (shellReplyChannel interface) $ ShutdownReply replyHeader pending
......@@ -206,10 +204,10 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe
sendOutput x =
send $ PublishDisplayData
outputHeader
(languageName config)
(languageName $ kernelLanguageInfo config)
(displayOutput config x)
in run config code clearOutput sendOutput
liftIO . send $ PublishDisplayData outputHeader (languageName config) (displayResult config res)
liftIO . send $ PublishDisplayData outputHeader (languageName $ kernelLanguageInfo config) (displayResult config res)
idleHeader <- dupHeader replyHeader StatusMessage
......@@ -230,8 +228,8 @@ replyTo config _ _ req@CompleteRequest{} replyHeader =
-- TODO: FIX
error "Completion: Unimplemented for IPython 3.0"
replyTo _ _ _ InspectRequest{} _ = do
error $ "Inspection: Unimplemented for IPython 3.0"
replyTo _ _ _ InspectRequest{} _ =
error "Inspection: Unimplemented for IPython 3.0"
replyTo _ _ _ msg _ = do
liftIO $ putStrLn "Unknown message: "
......
......@@ -16,11 +16,23 @@ import Data.Text.Encoding
import IHaskell.IPython.Types
instance ToJSON LanguageInfo where
toJSON info = object
[ "name" .= languageName info
, "version" .= languageVersion info
, "file_extension" .= languageFileExtension info
, "codemirror_mode" .= languageCodeMirrorMode info
]
-- Convert message bodies into JSON.
instance ToJSON Message where
toJSON KernelInfoReply { versionList = vers, language = language } =
object ["protocol_version" .= string "5.0" -- current protocol version, major and minor
, "language_version" .= vers, "language" .= language]
toJSON rep@KernelInfoReply{} =
object
[ "protocol_version" .= string "5.0" -- current protocol version, major and minor
, "implementation" .= implementation rep
, "implementation_version" .= implementationVersion rep
, "language_info" .= languageInfo rep
]
toJSON ExecuteReply { status = status, executionCounter = counter, pagerOutput = pager } =
object
......
......@@ -24,6 +24,7 @@ module IHaskell.IPython.Types (
ExecuteReplyStatus(..),
HistoryAccessType(..),
HistoryReplyElement(..),
LanguageInfo(..),
replyType,
showMessageType,
......@@ -246,6 +247,15 @@ instance FromJSON MessageType where
_ -> fail ("Unknown message type: " ++ show s)
parseJSON _ = fail "Must be a string."
data LanguageInfo =
LanguageInfo
{ languageName :: String -- ^ The language name, e.g. "haskell"
, languageVersion :: String -- ^ GHC 7.6.3
, languageFileExtension :: String -- ^ .hs
, languageCodeMirrorMode :: String -- ^ 'ihaskell'. can be 'null'
}
deriving (Show, Eq)
-- | A message used to communicate with the IPython frontend.
data Message =
-- | A request from a frontend for information about the kernel.
......@@ -254,9 +264,9 @@ data Message =
-- | A response to a KernelInfoRequest.
KernelInfoReply
{ header :: MessageHeader
, versionList :: [Int] -- ^ The version of the language, e.g. [7, 6, 3] for GHC
-- 7.6.3
, language :: String -- ^ The language name, e.g. "haskell"
, implementation :: String -- ^ e.g. IHaskell
, implementationVersion :: String -- ^ The version of the implementation
, languageInfo :: LanguageInfo
}
|
-- | A request from a frontend to execute some code.
......
......@@ -229,8 +229,14 @@ replyTo _ KernelInfoRequest{} replyHeader state =
return
(state, KernelInfoReply
{ header = replyHeader
, language = "haskell"
, versionList = ghcVersionInts
, implementation = "IHaskell"
, implementationVersion = VERSION_ipython_kernel
, languageInfo = LanguageInfo
{ languageName = "haskell"
, languageVersion = VERSION_ghc
, languageFileExtension = ".hs"
, languageCodeMirrorMode = "ihaskell"
}
})
-- Reply to a shutdown request by exiting the main thread. Before shutdown, reply to the request to
......
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