From eab96ad6f11e0f76380d9cc600724f94c4523915 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 3 Sep 2018 18:15:25 +0100 Subject: [PATCH] Update to haskell-lsp-0.7 Update tests Turn off logging by default --- lsp-test.cabal | 6 +++--- src/Language/Haskell/LSP/Test.hs | 18 ++++++++++-------- src/Language/Haskell/LSP/Test/Exceptions.hs | 2 ++ src/Language/Haskell/LSP/Test/Replay.hs | 20 ++++++++++---------- src/Language/Haskell/LSP/Test/Session.hs | 2 +- test/Test.hs | 5 +++-- test/data/renamePass/session.log | 2 +- 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/lsp-test.cabal b/lsp-test.cabal index 85ade4c..0275aed 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.2.1.0 +version: 0.3.0.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against @@ -36,7 +36,7 @@ library , parser-combinators:Control.Applicative.Combinators default-language: Haskell2010 build-depends: base >= 4.7 && < 5 - , haskell-lsp >= 0.6 + , haskell-lsp >= 0.7 , aeson , aeson-pretty , ansi-terminal @@ -78,7 +78,7 @@ test-suite tests build-depends: base >= 4.7 && < 5 , hspec , lens - , haskell-lsp + , haskell-lsp >= 0.7 , lsp-test , data-default , aeson diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index ec290ff..b7a746e 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -23,7 +23,7 @@ module Language.Haskell.LSP.Test , runSessionWithConfig , SessionConfig(..) , defaultConfig - , module Language.Haskell.LSP.Types.Capabilities + , C.fullCaps -- ** Exceptions , module Language.Haskell.LSP.Test.Exceptions , withTimeout @@ -91,9 +91,10 @@ import Data.Default import qualified Data.HashMap.Strict as HashMap import qualified Data.Map as Map import Data.Maybe -import Language.Haskell.LSP.Types hiding (id, capabilities, message) +import Language.Haskell.LSP.Types hiding + (id, capabilities, message, executeCommand, applyEdit, rename) import qualified Language.Haskell.LSP.Types as LSP -import Language.Haskell.LSP.Types.Capabilities +import qualified Language.Haskell.LSP.Types.Capabilities as C import Language.Haskell.LSP.Messages import Language.Haskell.LSP.VFS import Language.Haskell.LSP.Test.Compat @@ -116,7 +117,7 @@ import qualified Yi.Rope as Rope -- > params = TextDocumentPositionParams doc -- > hover <- request TextDocumentHover params runSession :: String -- ^ The command to run the server. - -> ClientCapabilities -- ^ The capabilities that the client should declare. + -> C.ClientCapabilities -- ^ The capabilities that the client should declare. -> FilePath -- ^ The filepath to the root directory for the session. -> Session a -- ^ The session to run. -> IO a @@ -125,7 +126,7 @@ runSession = runSessionWithConfig def -- | Starts a new sesion with a custom configuration. runSessionWithConfig :: SessionConfig -- ^ Configuration options for the session. -> String -- ^ The command to run the server. - -> ClientCapabilities -- ^ The capabilities that the client should declare. + -> C.ClientCapabilities -- ^ The capabilities that the client should declare. -> FilePath -- ^ The filepath to the root directory for the session. -> Session a -- ^ The session to run. -> IO a @@ -139,6 +140,7 @@ runSessionWithConfig config serverExe caps rootDir session = do Nothing caps (Just TraceOff) + Nothing withServer serverExe (logStdErr config) $ \serverIn serverOut _ -> runSessionWithHandles serverIn serverOut listenServer config caps rootDir $ do @@ -441,9 +443,9 @@ applyEdit doc edit = do caps <- asks sessionCapabilities let supportsDocChanges = fromMaybe False $ do - let ClientCapabilities mWorkspace _ _ = caps - WorkspaceClientCapabilities _ mEdit _ _ _ _ _ _ <- mWorkspace - WorkspaceEditClientCapabilities mDocChanges <- mEdit + let C.ClientCapabilities mWorkspace _ _ = caps + C.WorkspaceClientCapabilities _ mEdit _ _ _ _ _ _ <- mWorkspace + C.WorkspaceEditClientCapabilities mDocChanges <- mEdit mDocChanges let wEdit = if supportsDocChanges diff --git a/src/Language/Haskell/LSP/Test/Exceptions.hs b/src/Language/Haskell/LSP/Test/Exceptions.hs index 5923d2d..e1e281f 100644 --- a/src/Language/Haskell/LSP/Test/Exceptions.hs +++ b/src/Language/Haskell/LSP/Test/Exceptions.hs @@ -3,6 +3,7 @@ module Language.Haskell.LSP.Test.Exceptions where import Control.Exception import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types +import Data.Aeson import Data.Aeson.Encode.Pretty import Data.Algorithm.Diff import Data.Algorithm.DiffOutput @@ -34,6 +35,7 @@ instance Show SessionException where in "Replay is out of order:\n" ++ -- Print json so its a bit easier to update the session logs "Received from server:\n" ++ B.unpack (encodePretty received) ++ "\n" ++ + "Raw from server:\n" ++ B.unpack (encode received) ++ "\n" ++ "Expected one of:\n" ++ unlines (map showExp expected') show UnexpectedDiagnostics = "Unexpectedly received diagnostics from the server." show (IncorrectApplyEditRequest msgStr) = "ApplyEditRequest didn't contain document, instead received:\n" diff --git a/src/Language/Haskell/LSP/Test/Replay.hs b/src/Language/Haskell/LSP/Test/Replay.hs index 6c049d0..76f9b68 100644 --- a/src/Language/Haskell/LSP/Test/Replay.hs +++ b/src/Language/Haskell/LSP/Test/Replay.hs @@ -20,6 +20,7 @@ import Data.Maybe import Control.Lens hiding (List) import Control.Monad import System.FilePath +import System.IO import Language.Haskell.LSP.Test import Language.Haskell.LSP.Test.Files import Language.Haskell.LSP.Test.Decoding @@ -27,7 +28,6 @@ import Language.Haskell.LSP.Test.Messages import Language.Haskell.LSP.Test.Server import Language.Haskell.LSP.Test.Session - -- | Replays a captured client output and -- makes sure it matches up with an expected response. -- The session directory should have a captured session file in it @@ -133,15 +133,15 @@ isNotification (NotShowMessage _) = True isNotification (NotCancelRequestFromServer _) = True isNotification _ = False --- listenServer :: [FromServerMessage] --- -> RequestMap --- -> MVar LspId --- -> MVar LspIdRsp --- -> MVar () --- -> ThreadId --- -> Handle --- -> SessionContext --- -> IO () +listenServer :: [FromServerMessage] + -> RequestMap + -> MVar LspId + -> MVar LspIdRsp + -> MVar () + -> ThreadId + -> Handle + -> SessionContext + -> IO () listenServer [] _ _ _ passSema _ _ _ = putMVar passSema () listenServer expectedMsgs reqMap reqSema rspSema passSema mainThreadId serverOut ctx = do diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index 8e4754f..175f570 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -78,7 +78,7 @@ data SessionConfig = SessionConfig -- | The configuration used in 'Language.Haskell.LSP.Test.runSession'. defaultConfig :: SessionConfig -defaultConfig = SessionConfig 60 False True True +defaultConfig = SessionConfig 60 False False True instance Default SessionConfig where def = defaultConfig diff --git a/test/Test.hs b/test/Test.hs index 88c6852..5e7e075 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -18,7 +18,8 @@ import GHC.Generics import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Test import Language.Haskell.LSP.Test.Replay -import Language.Haskell.LSP.Types as LSP hiding (capabilities, message) +import Language.Haskell.LSP.Types as LSP hiding (capabilities, message, rename, applyEdit) +import Language.Haskell.LSP.Types.Capabilities as LSP import System.Timeout {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-} @@ -206,7 +207,7 @@ main = hspec $ do liftIO $ do mainSymbol ^. name `shouldBe` "main" mainSymbol ^. kind `shouldBe` SkFunction - mainSymbol ^. range `shouldBe` Range (Position 3 0) (Position 3 4) + mainSymbol ^. range `shouldBe` Range (Position 3 0) (Position 5 30) describe "applyEdit" $ do it "increments the version" $ runSession "hie --lsp" docChangesCaps "test/data/renamePass" $ do diff --git a/test/data/renamePass/session.log b/test/data/renamePass/session.log index e03f29c..bd5537d 100644 --- a/test/data/renamePass/session.log +++ b/test/data/renamePass/session.log @@ -9,7 +9,7 @@ {"tag":"FromServer","contents":["2018-06-03T04:08:39.524239Z",{"tag":"NotPublishDiagnostics","contents":{"jsonrpc":"2.0","params":{"uri":"file:///Users/luke/Desktop/simple.hs","diagnostics":[]},"method":"textDocument/publishDiagnostics"}}]} {"tag":"FromServer","contents":["2018-06-03T04:08:39.714012Z",{"tag":"NotPublishDiagnostics","contents":{"jsonrpc":"2.0","params":{"uri":"file:///Users/luke/Desktop/simple.hs","diagnostics":[]},"method":"textDocument/publishDiagnostics"}}]} {"tag":"FromClient","contents":["2018-06-03T04:08:40.844374Z",{"tag":"ReqDocumentSymbols","contents":{"jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///Users/luke/Desktop/simple.hs"}},"method":"textDocument/documentSymbol","id":25}}]} -{"tag":"FromServer","contents":["2018-06-03T04:08:40.859268Z",{"tag":"RspDocumentSymbols","contents":{"result":[{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":3,"character":0},"end":{"line":3,"character":4}}},"kind":12,"name":"main"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":7,"character":5},"end":{"line":7,"character":9}}},"kind":5,"name":"Item"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":8,"character":5},"end":{"line":8,"character":10}}},"kind":5,"name":"Items"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":10,"character":5},"end":{"line":10,"character":12}}},"kind":5,"name":"Command"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":10,"character":15},"end":{"line":10,"character":19}}},"kind":9,"containerName":"Command","name":"Quit"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":11,"character":15},"end":{"line":11,"character":27}}},"kind":9,"containerName":"Command","name":"DisplayItems"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":12,"character":15},"end":{"line":12,"character":22}}},"kind":9,"containerName":"Command","name":"AddItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":13,"character":15},"end":{"line":13,"character":25}}},"kind":9,"containerName":"Command","name":"RemoveItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":14,"character":15},"end":{"line":14,"character":19}}},"kind":9,"containerName":"Command","name":"Help"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":16,"character":5},"end":{"line":16,"character":10}}},"kind":5,"name":"Error"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":19,"character":0},"end":{"line":19,"character":12}}},"kind":12,"name":"parseCommand"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":28,"character":0},"end":{"line":28,"character":7}}},"kind":12,"name":"addItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":31,"character":0},"end":{"line":31,"character":12}}},"kind":12,"name":"displayItems"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":34,"character":0},"end":{"line":34,"character":10}}},"kind":12,"name":"removeItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":37,"character":9},"end":{"line":37,"character":14}}},"kind":13,"containerName":"removeItem","name":"front"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":37,"character":16},"end":{"line":37,"character":20}}},"kind":13,"containerName":"removeItem","name":"back"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":38,"character":8},"end":{"line":38,"character":14}}},"kind":12,"containerName":"removeItem","name":"result"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":41,"character":0},"end":{"line":41,"character":16}}},"kind":12,"name":"interactWithUser"}],"jsonrpc":"2.0","id":25}}]} +{"tag":"FromServer","contents":["2018-06-03T04:08:40.859268Z",{"tag":"RspDocumentSymbols","contents":{"result":[{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":3,"character":0},"end":{"line":5,"character":30}}},"kind":12,"name":"main"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":7,"character":0},"end":{"line":7,"character":18}}},"kind":5,"name":"Item"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":8,"character":0},"end":{"line":8,"character":19}}},"kind":5,"name":"Items"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":10,"character":0},"end":{"line":14,"character":19}}},"kind":5,"name":"Command"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":10,"character":15},"end":{"line":10,"character":19}}},"kind":9,"containerName":"Command","name":"Quit"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":11,"character":15},"end":{"line":11,"character":27}}},"kind":9,"containerName":"Command","name":"DisplayItems"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":12,"character":15},"end":{"line":12,"character":29}}},"kind":9,"containerName":"Command","name":"AddItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":13,"character":15},"end":{"line":13,"character":29}}},"kind":9,"containerName":"Command","name":"RemoveItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":14,"character":15},"end":{"line":14,"character":19}}},"kind":9,"containerName":"Command","name":"Help"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":16,"character":0},"end":{"line":16,"character":19}}},"kind":5,"name":"Error"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":19,"character":0},"end":{"line":25,"character":29}}},"kind":12,"name":"parseCommand"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":28,"character":0},"end":{"line":28,"character":13}}},"kind":12,"name":"addItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":31,"character":0},"end":{"line":31,"character":38}}},"kind":12,"name":"displayItems"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":34,"character":0},"end":{"line":38,"character":35}}},"kind":12,"name":"removeItem"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":37,"character":8},"end":{"line":37,"character":45}}},"kind":13,"containerName":"removeItem","name":"front"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":37,"character":8},"end":{"line":37,"character":45}}},"kind":13,"containerName":"removeItem","name":"back"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":38,"character":8},"end":{"line":38,"character":35}}},"kind":12,"containerName":"removeItem","name":"result"},{"location":{"uri":"file:///Users/luke/Desktop/simple.hs","range":{"start":{"line":41,"character":0},"end":{"line":75,"character":28}}},"kind":12,"name":"interactWithUser"}],"jsonrpc":"2.0","id":25}}]} {"tag":"FromClient","contents":["2018-06-03T04:08:46.24927Z",{"tag":"ReqRename","contents":{"jsonrpc":"2.0","params":{"newName":"arseCommand","textDocument":{"uri":"file:///Users/luke/Desktop/simple.hs"},"position":{"line":19,"character":0}},"method":"textDocument/rename","id":32}}]} {"tag":"FromServer","contents":["2018-06-03T04:08:46.528715Z",{"tag":"RspRename","contents":{"result":{"changes":{"file:///Users/luke/Desktop/simple.hs":[{"range":{"start":{"line":43,"character":0},"end":{"line":43,"character":27}},"newText":" case arseCommand line of"},{"range":{"start":{"line":18,"character":0},"end":{"line":19,"character":38}},"newText":"arseCommand :: String -> Either Error Command\narseCommand line = case words line of"}]}},"jsonrpc":"2.0","id":32}}]} {"tag":"FromClient","contents":["2018-06-03T04:08:48.300837Z",{"tag":"NotDidChangeTextDocument","contents":{"jsonrpc":"2.0","params":{"contentChanges":[{"text":"module Main where\n\nmain :: IO ()\nmain = do\n let initialList = []\n interactWithUser initialList\n\ntype Item = String\ntype Items = [Item]\n\ndata Command = Quit\n | DisplayItems\n | AddItem String\n | RemoveItem Int\n | Help\n\ntype Error = String\n\narseCommand :: String -> Either Error Command\narseCommand line = case words line of\n [\"quit\"] -> Right Quit\n [\"items\"] -> Right DisplayItems\n \"add\" : item -> Right $ AddItem $ unwords item\n \"remove\" : i -> Right $ RemoveItem $ read $ unwords i\n [\"help\"] -> Right Help\n _ -> Left \"Unknown command\"\n\naddItem :: Item -> Items -> Items\naddItem = (:)\n\ndisplayItems :: Items -> String\ndisplayItems = unlines . map (\"- \" ++)\n\nremoveItem :: Int -> Items -> Either Error Items\nremoveItem i items\n | i < 0 || i >= length items = Left \"Out of range\"\n | otherwise = Right result\n where (front, back) = splitAt (i + 1) items\n result = init front ++ back\n\ninteractWithUser :: Items -> IO ()\ninteractWithUser items = do\n line <- getLine\n case arseCommand line of\n Right DisplayItems -> do\n putStrLn $ displayItems items\n interactWithUser items\n\n Right (AddItem item) -> do\n let newItems = addItem item items\n putStrLn \"Added\"\n interactWithUser newItems\n\n Right (RemoveItem i) ->\n case removeItem i items of\n Right newItems -> do\n putStrLn $ \"Removed \" ++ items !! i\n interactWithUser newItems\n Left err -> do\n putStrLn err\n interactWithUser items\n\n\n Right Quit -> return ()\n\n Right Help -> do\n putStrLn \"Commands:\"\n putStrLn \"help\"\n putStrLn \"items\"\n putStrLn \"add\"\n putStrLn \"quit\"\n interactWithUser items\n\n Left err -> do\n putStrLn $ \"Error: \" ++ err\n interactWithUser items\n"}],"textDocument":{"uri":"file:///Users/luke/Desktop/simple.hs","version":1}},"method":"textDocument/didChange"}}]} -- 2.30.2