projects
/
lsp-test.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update hie version
[lsp-test.git]
/
src
/
Language
/
Haskell
/
LSP
/
Test
/
Decoding.hs
diff --git
a/src/Language/Haskell/LSP/Test/Decoding.hs
b/src/Language/Haskell/LSP/Test/Decoding.hs
index 2cbc41c07354f9c10f81ab902379085e52d5ed72..e635267fd7f9bf6200591b4d330ca8e2c3b3df99 100644
(file)
--- a/
src/Language/Haskell/LSP/Test/Decoding.hs
+++ b/
src/Language/Haskell/LSP/Test/Decoding.hs
@@
-3,6
+3,7
@@
module Language.Haskell.LSP.Test.Decoding where
import Prelude hiding ( id )
import Data.Aeson
import Prelude hiding ( id )
import Data.Aeson
+import Data.Foldable
import Control.Exception
import Control.Lens
import qualified Data.ByteString.Lazy.Char8 as B
import Control.Exception
import Control.Lens
import qualified Data.ByteString.Lazy.Char8 as B
@@
-32,7
+33,7
@@
getNextMessage :: Handle -> IO B.ByteString
getNextMessage h = do
headers <- getHeaders h
case read . init <$> lookup "Content-Length" headers of
getNextMessage h = do
headers <- getHeaders h
case read . init <$> lookup "Content-Length" headers of
- Nothing ->
error "Couldn't read Content-Length header"
+ Nothing ->
throw NoContentLengthHeader
Just size -> B.hGet h size
addHeader :: B.ByteString -> B.ByteString
Just size -> B.hGet h size
addHeader :: B.ByteString -> B.ByteString
@@
-123,7
+124,7
@@
matchResponseMsgType req = case req of
decodeFromServerMsg :: RequestMap -> B.ByteString -> FromServerMessage
decodeFromServerMsg reqMap bytes =
decodeFromServerMsg :: RequestMap -> B.ByteString -> FromServerMessage
decodeFromServerMsg reqMap bytes =
- case HM.lookup "method"
(fromJust $ decode bytes :: Object)
of
+ case HM.lookup "method"
obj
of
Just methodStr -> case fromJSON methodStr of
Success method -> case method of
-- We can work out the type of the message
Just methodStr -> case fromJSON methodStr of
Success method -> case method of
-- We can work out the type of the message
@@
-131,6
+132,9
@@
decodeFromServerMsg reqMap bytes =
WindowShowMessage -> NotShowMessage $ fromJust $ decode bytes
WindowLogMessage -> NotLogMessage $ fromJust $ decode bytes
CancelRequestServer -> NotCancelRequestFromServer $ fromJust $ decode bytes
WindowShowMessage -> NotShowMessage $ fromJust $ decode bytes
WindowLogMessage -> NotLogMessage $ fromJust $ decode bytes
CancelRequestServer -> NotCancelRequestFromServer $ fromJust $ decode bytes
+ Progress ->
+ fromJust $ asum [NotWorkDoneProgressBegin <$> decode bytes, NotWorkDoneProgressReport <$> decode bytes, NotWorkDoneProgressEnd <$> decode bytes]
+ WindowWorkDoneProgressCreate -> ReqWorkDoneProgressCreate $ fromJust $ decode bytes
TelemetryEvent -> NotTelemetry $ fromJust $ decode bytes
WindowShowMessageRequest -> ReqShowMessage $ fromJust $ decode bytes
ClientRegisterCapability -> ReqRegisterCapability $ fromJust $ decode bytes
TelemetryEvent -> NotTelemetry $ fromJust $ decode bytes
WindowShowMessageRequest -> ReqShowMessage $ fromJust $ decode bytes
ClientRegisterCapability -> ReqRegisterCapability $ fromJust $ decode bytes
@@
-138,6
+142,10
@@
decodeFromServerMsg reqMap bytes =
WorkspaceApplyEdit -> ReqApplyWorkspaceEdit $ fromJust $ decode bytes
WorkspaceWorkspaceFolders -> error "ReqWorkspaceFolders not supported yet"
WorkspaceConfiguration -> error "ReqWorkspaceConfiguration not supported yet"
WorkspaceApplyEdit -> ReqApplyWorkspaceEdit $ fromJust $ decode bytes
WorkspaceWorkspaceFolders -> error "ReqWorkspaceFolders not supported yet"
WorkspaceConfiguration -> error "ReqWorkspaceConfiguration not supported yet"
+ CustomServerMethod _
+ | "id" `HM.member` obj && "method" `HM.member` obj -> ReqCustomServer $ fromJust $ decode bytes
+ | "id" `HM.member` obj -> RspCustomServer $ fromJust $ decode bytes
+ | otherwise -> NotCustomServer $ fromJust $ decode bytes
Error e -> error e
Error e -> error e
@@
-146,3
+154,4
@@
decodeFromServerMsg reqMap bytes =
Just req -> matchResponseMsgType req bytes -- try to decode it to more specific type
Nothing -> error "Couldn't match up response with request"
Nothing -> error "Couldn't decode message"
Just req -> matchResponseMsgType req bytes -- try to decode it to more specific type
Nothing -> error "Couldn't match up response with request"
Nothing -> error "Couldn't decode message"
+ where obj = fromJust $ decode bytes :: Object