From: Luke Lau Date: Tue, 31 Jul 2018 16:10:04 +0000 (+0100) Subject: Merge branch 'master' into travis-investigation X-Git-Url: http://git.lukelau.me/?a=commitdiff_plain;h=6dd470a7b927038c40daecd0b040ba3b83ba7e57;hp=38a29ee38abd42afffc380f4911c9ebf99108ffb;p=lsp-test.git Merge branch 'master' into travis-investigation --- diff --git a/README.md b/README.md index dd71506..4a8762b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,42 @@ # haskell-lsp-test [![Build Status](https://travis-ci.com/Bubba/haskell-lsp-test.svg?branch=master)](https://travis-ci.com/Bubba/haskell-lsp-test) -This is the functional testing framework for [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine), and potentially any other Language Server Protocol server. +haskell-lsp-test is a functional testing framework for Language Server Protocol servers. ```haskell -runSession "session/root/dir" $ do - doc <- openDoc "foo.hs" "haskell" +import Language.Haskell.LSP.Test +runSession "hie" fullCaps "proj/dir" $ do + doc <- openDoc "Foo.hs" "haskell" + skipMany anyNotification + symbols <- getDocumentSymbols doc +``` - skipMany notification +## Examples - symbols <- getDocumentSymbols doc +### Unit tests with HSpec +```haskell +describe "diagnostics" $ + it "report errors" $ runSession "hie" fullCaps "test/data" $ do + openDoc "Error.hs" "haskell" + [diag] <- waitForDiagnosticsSource "ghcmod" + liftIO $ do + diag ^. severity `shouldBe` Just DsError + diag ^. source `shouldBe` Just "ghcmod" ``` +### Replaying captured session +```haskell +replaySession "hie --lsp" "test/data/renamePass" +``` + +### Parsing with combinators +```haskell +skipManyTill loggingNotification publishDiagnosticsNotification +count 4 (message :: Session ApplyWorkspaceEditRequest) +anyRequest <|> anyResponse +``` + +For more examples check the [Wiki](https://github.com/Bubba/haskell-lsp-test/wiki/Introduction) + ## Developing -To test make sure you have [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine) installed. +To test make sure you have the following language servers installed: +- [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine) +- [javascript-typescript-langserver](https://github.com/sourcegraph/javascript-typescript-langserver) diff --git a/haskell-lsp-test.cabal b/haskell-lsp-test.cabal index ec769ac..e3bb526 100644 --- a/haskell-lsp-test.cabal +++ b/haskell-lsp-test.cabal @@ -18,6 +18,7 @@ extra-source-files: README.md library hs-source-dirs: src exposed-modules: Language.Haskell.LSP.Test + , Language.Haskell.LSP.Test.Capabilities , Language.Haskell.LSP.Test.Replay reexported-modules: haskell-lsp:Language.Haskell.LSP.Types , haskell-lsp:Language.Haskell.LSP.Types.Capabilities @@ -48,8 +49,7 @@ library build-depends: Win32 else build-depends: unix - other-modules: Language.Haskell.LSP.Test.Capabilities - Language.Haskell.LSP.Test.Compat + other-modules: Language.Haskell.LSP.Test.Compat Language.Haskell.LSP.Test.Decoding Language.Haskell.LSP.Test.Exceptions Language.Haskell.LSP.Test.Files diff --git a/src/Language/Haskell/LSP/Test/Capabilities.hs b/src/Language/Haskell/LSP/Test/Capabilities.hs index f1237e3..9947906 100644 --- a/src/Language/Haskell/LSP/Test/Capabilities.hs +++ b/src/Language/Haskell/LSP/Test/Capabilities.hs @@ -1,11 +1,20 @@ +-- TODO: Move this into haskell-lsp module Language.Haskell.LSP.Test.Capabilities where import Language.Haskell.LSP.Types import Language.Haskell.LSP.Types.Capabilities --- | Capabilities for full conformance to the LSP specification. +-- | Capabilities for full conformance to the current (v3.10) LSP specification. -- The whole shebang. fullCaps :: ClientCapabilities -fullCaps = ClientCapabilities (Just w) (Just td) Nothing +fullCaps = capsForVersion (LSPVersion maxBound maxBound) + +-- | A specific version of the LSP specification. +data LSPVersion = LSPVersion Int -- ^ Major + Int -- ^ Minor + +-- | Capabilities for full conformance to the LSP specification up until a version. +capsForVersion :: LSPVersion -> ClientCapabilities +capsForVersion (LSPVersion maj min) = ClientCapabilities (Just w) (Just td) Nothing where w = WorkspaceClientCapabilities (Just True) @@ -39,7 +48,10 @@ fullCaps = ClientCapabilities (Just w) (Just td) Nothing (Just True) codeAction = CodeActionClientCapabilities (Just True) - (Just (CodeActionLiteralSupport kinds)) + codeActionLiterals + codeActionLiterals + | maj >= 3 && min >= 8 = Just (CodeActionLiteralSupport kinds) + | otherwise = Nothing kinds = CodeActionKindValueSet (List [ CodeActionQuickFix , CodeActionRefactor diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index 39a3ed2..86030df 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -302,14 +302,6 @@ withTimeout duration f = do } return res --- logClientMsg :: (MonadIO m, HasReader SessionContext m) --- => FromClientMessage -> m () --- logClientMsg = logMsg True - --- logServerMsg :: (MonadIO m, HasReader SessionContext m) --- => FromServerMessage -> m () --- logServerMsg = logMsg False - data LogMsgType = LogServer | LogClient deriving Eq @@ -331,6 +323,4 @@ logMsg t msg = do | t == LogServer = Magenta | otherwise = Cyan - -showPretty :: ToJSON a => a -> String showPretty = B.unpack . encodePretty