Adding remainder of completion work

This commit is contained in:
Andrew Gibiansky 2015-03-06 12:48:19 -08:00
parent 2eca349123
commit 9cd9cfb1b8
5 changed files with 18 additions and 11 deletions

View File

@ -233,6 +233,9 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe
}
replyTo config _ _ req@CompleteRequest{} replyHeader = do
-- TODO: FIX
error "Unimplemented in IPython 3.0"
{-
let code = getCode req
line = getCodeLine req
col = getCursorPos req
@ -254,6 +257,7 @@ replyTo config _ _ req@CompleteRequest{} replyHeader = do
, completionText = cmplText
, completionStatus = True
}
-}
replyTo config _ _ ObjectInfoRequest { objectName = obj } replyHeader =
return $ case objectInfo config obj of

View File

@ -15,6 +15,8 @@ import Data.Text (Text)
import qualified Data.ByteString.Lazy as Lazy
import IHaskell.IPython.Types
import Debug.Trace (traceShow)
type LByteString = Lazy.ByteString
----- External interface -----
@ -118,7 +120,7 @@ executeRequestParser content =
requestParser parser content = parsed
where
Success parsed = parse parser decoded
Success parsed = traceShow decoded $ parse parser decoded
Just decoded = decode content
historyRequestParser :: LByteString -> Message
@ -137,7 +139,7 @@ historyRequestParser = requestParser $ \obj ->
completeRequestParser :: LByteString -> Message
completeRequestParser = requestParser $ \obj -> do
code <- obj .: "code" <|> return ""
code <- obj .: "code"
pos <- obj .: "cursor_pos"
return $ CompleteRequest noHeader code pos

View File

@ -60,11 +60,12 @@ instance ToJSON Message where
"execution_count" .= execCount,
"code" .= code
]
toJSON (CompleteReply _ m mt t s) = object [
"matches" .= m,
"matched_text" .= mt,
"text" .= t,
"status" .= if s then string "ok" else "error"
toJSON (CompleteReply _ matches start end metadata status) = object [
"matches" .= matches,
"cursor_start" .= start,
"cursor_end" .= end,
"metadata" .= metadata,
"status" .= if status then string "ok" else "error"
]
toJSON o@ObjectInfoReply{} = object [
"oname" .= objectName o,

View File

@ -16,9 +16,9 @@ import ClassyPrelude hiding (init, last, head, liftIO)
--import Prelude
import Control.Applicative ((<$>))
import Data.ByteString.UTF8 hiding (drop, take)
import Data.ByteString.UTF8 hiding (drop, take, lines, length)
import Data.Char
import Data.List (nub, init, last, head, elemIndex, find)
import Data.List (nub, init, last, head, elemIndex)
import Data.List.Split
import Data.List.Split.Internals
import Data.Maybe (fromJust)
@ -67,7 +67,7 @@ complete code posOffset = do
if offset <= length first
then (offset, first)
else findLine (offset - length first - 1) rest
findLine _ [] = error "Could not find line"
findLine _ [] = error $ "Could not find line: " ++ show (map length $ lines code, posOffset)
(pos, line) = findLine posOffset (lines code)

View File

@ -334,7 +334,7 @@ replyTo _ req@CompleteRequest{} replyHeader state = do
let start = pos - length matchedText
end = pos
reply = CompleteReply replyHeader (map pack completions) start end empty True
reply = CompleteReply replyHeader (map pack completions) start end Map.empty True
return (state, reply)
-- Reply to the object_info_request message. Given an object name, return