lsp-test 0.9.0.0 → 0.10.0.0
raw patch · 6 files changed
+47/−12 lines, 6 filesdep −rope-utf16-splaydep ~parser-combinatorsPVP ok
version bump matches the API change (PVP)
Dependencies removed: rope-utf16-splay
Dependency ranges changed: parser-combinators
API changes (from Hackage documentation)
+ Language.Haskell.LSP.Test: IllegalInitSequenceMessage :: FromServerMessage -> SessionException
Files
- ChangeLog.md +5/−0
- README.md +1/−1
- lsp-test.cabal +2/−3
- src/Language/Haskell/LSP/Test.hs +23/−3
- src/Language/Haskell/LSP/Test/Exceptions.hs +4/−0
- test/Test.hs +12/−5
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for lsp-test +## 0.10.0.0 -- 2019-12-29++* Account for messages received between the initialize request and response.+ (Though it will throw an exception if the message received is an illegal one)+ ## 0.9.0.0 -- 2019-12-1 * Add `ignoreLogNotifications` config option
README.md view
@@ -1,4 +1,4 @@-# lsp-test [](https://travis-ci.com/bubba/lsp-test) [](https://hackage.haskell.org/package/lsp-test-0.1.0.0)+# lsp-test [](https://github.com/bubba/lsp-test/actions) [](https://hackage.haskell.org/package/lsp-test-0.1.0.0) lsp-test is a functional testing framework for Language Server Protocol servers. ```haskell
lsp-test.cabal view
@@ -1,5 +1,5 @@ name: lsp-test-version: 0.9.0.0+version: 0.10.0.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against@@ -50,9 +50,8 @@ , filepath , lens , mtl- , parser-combinators+ , parser-combinators >= 1.2 , process >= 1.6- , rope-utf16-splay , text , transformers , unordered-containers
src/Language/Haskell/LSP/Test.hs view
@@ -114,7 +114,6 @@ import System.IO import System.Directory import System.FilePath-import qualified Data.Rope.UTF16 as Rope -- | Starts a new session. --@@ -154,8 +153,13 @@ withServer serverExe (logStdErr config) $ \serverIn serverOut serverProc -> runSessionWithHandles serverIn serverOut serverProc listenServer config caps rootDir exitServer $ do -- Wrap the session around initialize and shutdown calls- initRspMsg <- request Initialize initializeParams :: Session InitializeResponse+ -- initRspMsg <- sendRequest Initialize initializeParams :: Session InitializeResponse+ initReqId <- sendRequest Initialize initializeParams + -- Because messages can be sent in between the request and response,+ -- collect them and then...+ (inBetween, initRspMsg) <- manyTill_ anyMessage (responseForId initReqId)+ liftIO $ maybe (return ()) (putStrLn . ("Error while initializing: " ++) . show ) (initRspMsg ^. LSP.error) initRspVar <- initRsp <$> ask@@ -166,6 +170,12 @@ Just cfg -> sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams cfg) Nothing -> return () + -- ... relay them back to the user Session so they can match on them!+ -- As long as they are allowed.+ forM_ inBetween checkLegalBetweenMessage+ msgChan <- asks messageChan+ liftIO $ writeList2Chan msgChan (ServerMessage <$> inBetween)+ -- Run the actual test session where@@ -188,6 +198,16 @@ (RspShutdown _) -> return () _ -> listenServer serverOut context + -- | Is this message allowed to be sent by the server between the intialize+ -- request and response?+ -- https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#initialize+ checkLegalBetweenMessage :: FromServerMessage -> Session ()+ checkLegalBetweenMessage (NotShowMessage _) = pure ()+ checkLegalBetweenMessage (NotLogMessage _) = pure ()+ checkLegalBetweenMessage (NotTelemetry _) = pure ()+ checkLegalBetweenMessage (ReqShowMessage _) = pure ()+ checkLegalBetweenMessage msg = throw (IllegalInitSequenceMessage msg)+ -- | Check environment variables to override the config envOverrideConfig :: SessionConfig -> IO SessionConfig envOverrideConfig cfg = do@@ -204,7 +224,7 @@ documentContents doc = do vfs <- vfs <$> get let file = vfsMap vfs Map.! toNormalizedUri (doc ^. uri)- return $ Rope.toText $ Language.Haskell.LSP.VFS._text file+ return (virtualFileText file) -- | Parses an ApplyEditRequest, checks that it is for the passed document -- and returns the new content
src/Language/Haskell/LSP/Test/Exceptions.hs view
@@ -19,6 +19,7 @@ | IncorrectApplyEditRequest String | UnexpectedResponseError LspIdRsp ResponseError | UnexpectedServerTermination+ | IllegalInitSequenceMessage FromServerMessage deriving Eq instance Exception SessionException@@ -50,6 +51,9 @@ show (UnexpectedResponseError lid e) = "Received an exepected error in a response for id " ++ show lid ++ ":\n" ++ show e show UnexpectedServerTermination = "Language server unexpectedly terminated"+ show (IllegalInitSequenceMessage msg) =+ "Received an illegal message between the initialize request and response:\n"+ ++ B.unpack (encodePretty msg) -- | A predicate that matches on any 'SessionException' anySessionException :: SessionException -> Bool
test/Test.hs view
@@ -281,11 +281,18 @@ diag ^. severity `shouldBe` Just DsError diag ^. source `shouldBe` Just "bios" - describe "rename" $- it "works" $ runSession "hie" fullCaps "test/data" $ do- doc <- openDoc "Rename.hs" "haskell"- rename doc (Position 1 0) "bar"- documentContents doc >>= liftIO . shouldBe "main = bar\nbar = return 42\n"+ describe "rename" $ do+ it "works" $ pendingWith "HaRe not in hie-bios yet"+ it "works on javascript" $+ runSession "javascript-typescript-stdio" fullCaps "test/data/javascriptPass" $ do+ doc <- openDoc "test.js" "javascript"+ rename doc (Position 2 11) "bar"+ documentContents doc >>= liftIO . (`shouldContain` "function bar()") . T.unpack++ -- runSession "hie" fullCaps "test/data" $ do+ -- doc <- openDoc "Rename.hs" "haskell"+ -- rename doc (Position 1 0) "bar"+ -- documentContents doc >>= liftIO . shouldBe "main = bar\nbar = return 42\n" describe "getHover" $ it "works" $ runSession "hie" fullCaps "test/data/renamePass" $ do