From 2a1a602d8f21a042e6db4dce211a23cb138b8398 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 15 Dec 2019 20:09:30 +0000 Subject: [PATCH 01/16] Bump to 0.9.0.0 --- ChangeLog.md | 5 ++++- lsp-test.cabal | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2d4f611..17c926a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,8 +1,11 @@ # Revision history for lsp-test -## 0.9.0.0 -- ??? +## 0.9.0.0 -- 2019-12-1 * Add `ignoreLogNotifications` config option +* Add ability to override `logStdErr` and `logMessages` config options with + the `LSP_TEST_LOG_STDERR` and `LOG_TEST_LOG_MESSAGES` environment variables +* Update for haskell-lsp-0.19.0.0 (@mpickering) ## 0.8.2.0 -- 2019-11-17 diff --git a/lsp-test.cabal b/lsp-test.cabal index b323deb..dcb6793 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.8.2.0 +version: 0.9.0.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against -- 2.30.2 From 5de316d1457c8abfac4c41c2a86892b74a1db07c Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 16 Dec 2019 11:54:52 +0000 Subject: [PATCH 02/16] Remove rope-utf16-splay dependency --- lsp-test.cabal | 1 - src/Language/Haskell/LSP/Test.hs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lsp-test.cabal b/lsp-test.cabal index dcb6793..0d43611 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -52,7 +52,6 @@ library , mtl , parser-combinators , process >= 1.6 - , rope-utf16-splay , text , transformers , unordered-containers diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index bca640f..3ad7b2f 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -114,7 +114,6 @@ import System.Environment import System.IO import System.Directory import System.FilePath -import qualified Data.Rope.UTF16 as Rope -- | Starts a new session. -- @@ -204,7 +203,7 @@ documentContents :: TextDocumentIdentifier -> Session T.Text 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 -- 2.30.2 From 6c549ae5869e8dd30e3fb8fa95b98e4130e38cd1 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 16 Dec 2019 11:55:10 +0000 Subject: [PATCH 03/16] Update stack.yaml --- stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index e9c1a6a..c3e341c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,3 @@ -resolver: nightly-2019-11-29 +resolver: nightly-2019-12-16 packages: - . -- 2.30.2 From 01da6135bd795edcf08c1462ce9925e9917df956 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 20 Dec 2019 02:05:48 +0000 Subject: [PATCH 04/16] Squashed commit of the following: commit 2ba261a93d4d1aebb3f749d65e7ad038fe1fb8ce Author: Luke Lau Date: Fri Dec 20 02:04:40 2019 +0000 Remove extraneous flag commit 358ddf1c3f5138c2ddf5f40d6ab543ab6ea75f27 Author: Luke Lau Date: Fri Dec 20 01:50:46 2019 +0000 Do some tidying up commit 4f1628681efec92fdb69dc2faf09c3c73e1d6d83 Author: Luke Lau Date: Fri Dec 20 00:57:46 2019 +0000 Replace rename test while HaRe is gone commit 60b309d19338bc584dae5388b2fa7486779fdaa6 Author: Luke Lau Date: Fri Dec 20 00:01:42 2019 +0000 Update hie commit 14966566f56badb30e257defe62463e484a2892a Merge: a61a867 6c549ae Author: Luke Lau Date: Fri Dec 20 00:01:01 2019 +0000 Merge branch 'master' into github-actions commit a61a867b278edc025489298b360340e7ddec05e7 Author: Luke Lau Date: Tue Nov 26 15:45:25 2019 +0000 Update hie version commit ef87eb25780e65706b1ec9437a0c1084b4940b9a Author: Luke Lau Date: Mon Nov 25 21:59:41 2019 +0000 Skip caching commit 803c622b2a390a310584d9f8170c9ec1c8ea67db Merge: d46bb3d 95ef237 Author: Luke Lau Date: Mon Nov 25 17:24:41 2019 +0000 Merge branch 'master' into github-actions commit d46bb3df79fd71344d0c8d7c6de5b67c99f65906 Author: Luke Lau Date: Wed Nov 13 15:33:41 2019 +0000 Add restore keys commit d88f852bc000c0d743f50c9328bf7f94c68a917a Author: Luke Lau Date: Wed Nov 13 15:27:26 2019 +0000 Cache ~/.cabal commit 51a500ceafa6d32b39e8c79bbb885fd1f0d559a4 Author: Luke Lau Date: Wed Nov 13 14:05:47 2019 +0000 Turn back on tests commit 4ecafadfae6e2f85bd92fd26ef5a79171a8114c9 Author: Luke Lau Date: Wed Nov 13 13:14:29 2019 +0000 Skip tests commit f1fca115d4447601b5547c75762fbb0bab0ebcff Author: Luke Lau Date: Wed Nov 13 13:14:03 2019 +0000 Add hie.yaml file commit ff565d6a883324c593d394ca43483ed5304ff7bb Author: Luke Lau Date: Tue Nov 12 23:11:32 2019 +0000 Use hie-bios commit 282975ed02c212a8a70b002adceefe9be17828ab Author: Luke Lau Date: Tue Nov 12 22:14:21 2019 +0000 Turn back on tests commit 9466153bd3fec0fb4f3a6a70659fbc2ded68ff07 Author: Luke Lau Date: Tue Nov 12 22:13:12 2019 +0000 Fix cache path commit d0957b1bb20206a72daf042b62d8d31acb58f6ec Author: Luke Lau Date: Tue Nov 12 22:10:11 2019 +0000 Install Cabal library commit 005f2a5b9a388355fac1978a0c191ace407703dc Author: Luke Lau Date: Wed Nov 6 01:21:53 2019 +0000 Try tests commit 1fece5cbea8a496f0ffd9bcdc66799a789d9bc6d Author: Luke Lau Date: Wed Nov 6 01:12:43 2019 +0000 Update readme badge commit 4d7d4a7889723fcac14b034b4af5bc007a78505f Author: Luke Lau Date: Wed Nov 6 01:00:42 2019 +0000 Cache dist-newstyle commit 81f355b80c168555f5af9a40bd3722e27e1b20a6 Author: Luke Lau Date: Tue Nov 5 23:28:14 2019 +0000 Skip tests so it passes and caches hie commit 5d347a640ed7f3967e0a48c8e039d263e585c90c Author: Luke Lau Date: Tue Nov 5 23:12:42 2019 +0000 Fix typo commit c153a088c325d7ca9ec2d385f1616216dba8231b Author: Luke Lau Date: Tue Nov 5 23:10:35 2019 +0000 Move into the right dir commit 322f51e3ab0bf60b1a791a7128c8954bb8c1dd08 Author: Luke Lau Date: Tue Nov 5 23:05:15 2019 +0000 Try and figure out where its being checked out to commit 344a84171b685571ea8a8b2c01e577db9bf2b225 Author: Luke Lau Date: Tue Nov 5 23:00:26 2019 +0000 Try moving hie checkout path commit d1933f6079eef0a92255f0d291c08b63ce258998 Author: Luke Lau Date: Tue Nov 5 22:56:55 2019 +0000 Don't use wrong condition for hie test commit d55147cdd6b333a1fa5125a4868842266cdbb1d8 Author: Luke Lau Date: Tue Nov 5 22:56:02 2019 +0000 Only cache cabal binaries commit badc948ab7affaa15f5c6a6a6e8af07a74e56dea Author: Luke Lau Date: Tue Nov 5 22:54:28 2019 +0000 Try caching hie commit a3cd5371e2fe29acd8b9653d0eacebf3087d9715 Author: Luke Lau Date: Tue Nov 5 22:33:04 2019 +0000 Start debugging these failing tests commit ebfabfaac2438f69625b72d9867a21bec489181d Author: Luke Lau Date: Sun Nov 3 21:11:54 2019 +0000 Go back to using hie master commit a262b90b6df2b3aff0fd23019390f83f16d7a75f Author: Luke Lau Date: Sat Oct 19 01:54:41 2019 +0100 Add npm bin directory to PATH commit 3d9f14e3d376b069169a13ffba59211e4838134e Author: Luke Lau Date: Sat Oct 19 00:49:44 2019 +0100 Use hie-bios commit ba2031ed9c5237c40dc6de1376bf74ec134f78bf Merge: 38bf0b7 c80fbbc Author: Luke Lau Date: Sat Oct 19 00:49:15 2019 +0100 Merge branch 'master' into github-actions commit 38bf0b76556e21891319a2e2af92efe8ff4bf5b7 Author: Luke Lau Date: Sun Oct 6 00:42:27 2019 +0100 Install JS language server commit 0980bdc3a13cc183ef4de6a00820d386c498d7f7 Author: Luke Lau Date: Sat Oct 5 21:29:08 2019 +0100 Tidy up workflow commit 83f521b928a6c952dba54061dde684869ca5c669 Author: Luke Lau Date: Wed Oct 2 19:50:10 2019 +0100 Update haskell.yml commit 588e085d12244b795441c0e17b71a561ac5db80b Author: Luke Lau Date: Wed Oct 2 15:09:13 2019 +0100 Debug PATH commit 89407b82feba0a4c025d118eb6bf03b3fa6bef39 Author: Luke Lau Date: Wed Oct 2 14:00:38 2019 +0100 Add cabal bin to PATH commit 0de9d38dfe3a9b0f9c029e9da72054261702e3f1 Author: Luke Lau Date: Wed Oct 2 12:12:17 2019 +0100 Update haskell.yml commit 9fa751f3d517dd071d9af47ae42988c6acd7334f Author: Luke Lau Date: Wed Oct 2 12:09:13 2019 +0100 Update haskell.yml commit d6bfa2476eae9b86896bdcf9116965feccb2ca7a Merge: 550d88c c066f37 Author: Luke Lau Date: Wed Oct 2 12:08:03 2019 +0100 Merge branch 'github-actions' of https://github.com/bubba/lsp-test into github-actions commit 550d88ca15b7909e2988d400f0fd0882304c1d1f Author: Luke Lau Date: Sat Aug 24 18:19:04 2019 -0400 Add secret commit 1d9d650e6391f03527db6bae6b0e8d6ac9c2231c Author: Luke Lau Date: Sat Aug 24 18:15:15 2019 -0400 Add hlinter commit 860ba10766f52281e31fe1a778e290b30ac37676 Author: Luke Lau Date: Sat Aug 24 18:11:27 2019 -0400 Try upgrading ghc and cabal commit c066f37e7955511a5f02acefb2d8c7360397d3df Author: Luke Lau Date: Sat Aug 24 18:19:04 2019 -0400 Add secret commit 80aeabcf9c63706c07c33f0933c2622aac7fc376 Author: Luke Lau Date: Sat Aug 24 18:15:15 2019 -0400 Add hlinter commit 2d99d48db3865ad7f5916fea82ad4ce8b6a695f4 Author: Luke Lau Date: Sat Aug 24 18:11:27 2019 -0400 Try upgrading ghc and cabal --- .github/workflows/haskell.yml | 49 ++++++++++++++++++++++++++++------- README.md | 2 +- test/Test.hs | 17 ++++++++---- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index e4cdf76..53827ca 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -1,32 +1,61 @@ name: Haskell CI on: [push] - jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + env: + hieref: cd0d1eb88334c359b8a220f2aebec703d66012ff + + strategy: + matrix: + ghc: ['8.6.5'] + os: [ubuntu-latest, macOS-latest] steps: - uses: actions/checkout@v1 - - uses: actions/setup-haskell@v1 + - uses: bubba/setup-haskell@macos-ghcup with: - ghc-version: '8.6.5' + ghc-version: ${{ matrix.ghc }} cabal-version: '3.0' - run: cabal update - - name: Install HIE + + - name: Clone HIE + uses: actions/checkout@v1 + with: + repository: mpickering/haskell-ide-engine + submodules: recursive + ref: ${{ env.hieref }} + path: haskell-ide-engine + + # - name: Cache Cabal + # uses: actions/cache@v1 + # with: + # path: ~/.cabal + # key: ${{ runner.OS }}-${{ matrix.ghc }}-cabal-${{ hashFiles('../**/*.cabal') }} + # restore-keys: | + # ${{ runner.OS }}-${{ matrix.ghc }}-cabal + + - name: Build HIE run: | - pushd $HOME - git clone https://github.com/haskell/haskell-ide-engine --recurse-submodules - cd haskell-ide-engine + # if [ -e $HOME/.cabal/bin/hie ]; then + # echo "hie is already built" + # exit 0 + # fi + pushd ../haskell-ide-engine cabal install hie cabal install hoogle - export PATH=$PATH:$HOME/.cabal/bin hoogle generate popd + - name: Install JS Language Server + run: npm install -g javascript-typescript-langserver - name: Build run: cabal build - name: Test run: | - export PATH=$PATH:$HOME/.cabal/bin + echo $PATH + echo $(npm bin) + export PATH=$PATH:$(npm bin) cabal test diff --git a/README.md b/README.md index ce452fe..9f0251b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lsp-test [![Build Status](https://travis-ci.com/bubba/lsp-test.svg?branch=master)](https://travis-ci.com/bubba/lsp-test) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test-0.1.0.0) +# lsp-test [![Actions Status](https://github.com/bubba/lsp-test/workflows/Haskell%20CI/badge.svg)](https://github.com/bubba/lsp-test/actions) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test-0.1.0.0) lsp-test is a functional testing framework for Language Server Protocol servers. ```haskell diff --git a/test/Test.hs b/test/Test.hs index dc770d9..eb0eef0 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -281,11 +281,18 @@ main = hspec $ do 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 -- 2.30.2 From 5852fb5aa22b2d9cada2451447909edca5ce5951 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 20 Dec 2019 02:08:49 +0000 Subject: [PATCH 05/16] Turn on Haskell workflow for PRs --- .github/workflows/haskell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 53827ca..70ee98a 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -1,6 +1,6 @@ name: Haskell CI -on: [push] +on: [push, pull_request] jobs: build: -- 2.30.2 From cc06e0d2125df0aeb7b5ac99233ea9c5cf6fdc48 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 20 Dec 2019 02:41:43 +0000 Subject: [PATCH 06/16] Don't install globally via npm --- .github/workflows/haskell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 70ee98a..67c9666 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -50,7 +50,7 @@ jobs: hoogle generate popd - name: Install JS Language Server - run: npm install -g javascript-typescript-langserver + run: npm install javascript-typescript-langserver - name: Build run: cabal build - name: Test -- 2.30.2 From df1dfeee3cb3947513634476332b29a740966d37 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 20 Dec 2019 21:12:37 +0000 Subject: [PATCH 07/16] Update hie used in CI --- .github/workflows/haskell.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 67c9666..837bcbf 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -7,11 +7,11 @@ jobs: runs-on: ${{ matrix.os }} env: - hieref: cd0d1eb88334c359b8a220f2aebec703d66012ff + hieref: 8582a960dc1ca389734707f821b273b00bae54ab strategy: matrix: - ghc: ['8.6.5'] + ghc: ['8.6.5', '8.4.4'] os: [ubuntu-latest, macOS-latest] steps: @@ -25,7 +25,7 @@ jobs: - name: Clone HIE uses: actions/checkout@v1 with: - repository: mpickering/haskell-ide-engine + repository: haskell/haskell-ide-engine submodules: recursive ref: ${{ env.hieref }} path: haskell-ide-engine -- 2.30.2 From 4c6cc8593438b195326ef99cc8d8d33030b1b4d6 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 20 Dec 2019 22:13:06 +0000 Subject: [PATCH 08/16] Disable CI on macOS 8.4.4 --- .github/workflows/haskell.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 837bcbf..4b593b9 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -13,6 +13,9 @@ jobs: matrix: ghc: ['8.6.5', '8.4.4'] os: [ubuntu-latest, macOS-latest] + exclude: + - os: macOS-latest + ghc: '8.4.4' # fails due to ghc panic steps: - uses: actions/checkout@v1 -- 2.30.2 From 80a27eb1c9cb59c25bdf8c80926b897bc48f3672 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 29 Dec 2019 00:44:24 +0000 Subject: [PATCH 09/16] Handle receiving messages in between the initialize sequence And check that they are legal --- lsp-test.cabal | 2 +- src/Language/Haskell/LSP/Test.hs | 23 ++++++++++++++++++++- src/Language/Haskell/LSP/Test/Exceptions.hs | 4 ++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lsp-test.cabal b/lsp-test.cabal index 0d43611..88c6f76 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -50,7 +50,7 @@ library , filepath , lens , mtl - , parser-combinators + , parser-combinators >= 1.2 , process >= 1.6 , text , transformers diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 3ad7b2f..b3f535f 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -153,7 +153,12 @@ runSessionWithConfig config' serverExe caps rootDir session = do 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) @@ -165,6 +170,12 @@ runSessionWithConfig config' serverExe caps rootDir session = do 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 @@ -187,6 +198,16 @@ runSessionWithConfig config' serverExe caps rootDir session = do (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 diff --git a/src/Language/Haskell/LSP/Test/Exceptions.hs b/src/Language/Haskell/LSP/Test/Exceptions.hs index 713b25f..afb48df 100644 --- a/src/Language/Haskell/LSP/Test/Exceptions.hs +++ b/src/Language/Haskell/LSP/Test/Exceptions.hs @@ -19,6 +19,7 @@ data SessionException = Timeout (Maybe FromServerMessage) | IncorrectApplyEditRequest String | UnexpectedResponseError LspIdRsp ResponseError | UnexpectedServerTermination + | IllegalInitSequenceMessage FromServerMessage deriving Eq instance Exception SessionException @@ -50,6 +51,9 @@ instance Show SessionException where 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 -- 2.30.2 From edd69eeb0b5b055ccbb0e4e1a6035f6cd9aaa551 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 29 Dec 2019 01:53:05 +0000 Subject: [PATCH 10/16] Bump to 0.10.0.0 --- ChangeLog.md | 5 +++++ lsp-test.cabal | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 17c926a..2ad3ba8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/lsp-test.cabal b/lsp-test.cabal index 88c6f76..8df7405 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -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 -- 2.30.2 From 33e01cbb9cddcd84cbb1a25d25d2e63a1c0e1146 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 3 Jan 2020 13:09:27 +0000 Subject: [PATCH 11/16] Tidy up README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f0251b..a263847 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ lsp-test is a functional testing framework for Language Server Protocol servers. ```haskell import Language.Haskell.LSP.Test -runSession "hie" fullCaps "proj/dir" $ do +main = runSession "hie" fullCaps "proj/dir" $ do doc <- openDoc "Foo.hs" "haskell" skipMany anyNotification symbols <- getDocumentSymbols doc @@ -34,7 +34,7 @@ count 4 (message :: Session ApplyWorkspaceEditRequest) anyRequest <|> anyResponse ``` -Try out the example tests in the `example` directory with `cabal new-test`. +Try out the example tests in the `example` directory with `cabal test`. For more examples check the [Wiki](https://github.com/bubba/lsp-test/wiki/Introduction) ## Developing @@ -45,7 +45,7 @@ The tests are integration tests, so make sure you have the following language se ### [javascript-typescript-langserver](https://github.com/sourcegraph/javascript-typescript-langserver) `npm i -g javascript-typescript-langserver` -Then run the tests with `stack test` or `cabal new-test`. +Then run the tests with `cabal test` or `stack test`. ## Troubleshooting Seeing funny stuff when running lsp-test via stack? If your server is built upon Haskell tooling, [keep in mind that stack sets some environment variables related to GHC, and you may want to unset them.](https://github.com/alanz/haskell-ide-engine/blob/bfb16324d396da71000ef81d51acbebbdaa854ab/test/utils/TestUtils.hs#L290-L298) -- 2.30.2 From 109cc7395312c9f8c7d973701200ff0a9efa4363 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Tue, 21 Jan 2020 10:40:46 +0000 Subject: [PATCH 12/16] Squashed commit of the following: commit e182b6f35a5f729dddfefcc0dab79d2ee6fafa22 Author: Luke Lau Date: Tue Jan 21 10:20:29 2020 +0000 Remove hie binary check (main slowdown was Hoogle) commit 78e3a657fd66255c93e845adf4b1da48f6313d37 Author: Luke Lau Date: Tue Jan 21 10:16:48 2020 +0000 Cache hoogle db commit 89eeebae8dc7730cbac4bb56320e307c6aab9f18 Author: Luke Lau Date: Tue Jan 21 10:11:08 2020 +0000 Check for hie already existing commit 9c14e02fa30ce94a9635854d032294692578e02e Author: Luke Lau Date: Sun Jan 19 22:12:11 2020 +0000 Hash based on hieref commit 0e0f5c819ca9514567bfbb7897bc40f7c0a9a3b3 Author: Luke Lau Date: Mon Jan 6 19:56:36 2020 +0000 Try caching now that v1.1 is out --- .github/workflows/haskell.yml | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 4b593b9..0608616 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -33,32 +33,38 @@ jobs: ref: ${{ env.hieref }} path: haskell-ide-engine - # - name: Cache Cabal - # uses: actions/cache@v1 - # with: - # path: ~/.cabal - # key: ${{ runner.OS }}-${{ matrix.ghc }}-cabal-${{ hashFiles('../**/*.cabal') }} - # restore-keys: | - # ${{ runner.OS }}-${{ matrix.ghc }}-cabal + - name: Cache Cabal + uses: actions/cache@v1.1.0 + with: + path: ~/.cabal + key: ${{ runner.OS }}-${{ matrix.ghc }}-cabal-${{ env.hieref }} + restore-keys: | + ${{ runner.OS }}-${{ matrix.ghc }}-cabal + + - name: Cache Hoogle + uses: actions/cache@v1.1.0 + with: + path: ~/.hoogle + key: ${{ runner.OS }}-${{ matrix.ghc }}-hoogle-${{ env.hieref }} - name: Build HIE run: | - # if [ -e $HOME/.cabal/bin/hie ]; then - # echo "hie is already built" - # exit 0 - # fi pushd ../haskell-ide-engine cabal install hie cabal install hoogle - hoogle generate popd + - name: Generate hoogle database + run: | + if [ -d $HOME/.hoogle ]; then + echo "hoogle database already built" + exit 0 + fi + hoogle generate - name: Install JS Language Server run: npm install javascript-typescript-langserver - name: Build run: cabal build - name: Test run: | - echo $PATH - echo $(npm bin) export PATH=$PATH:$(npm bin) cabal test -- 2.30.2 From bcc33d41eb5f2130c358095528f993bfd7863d8d Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Tue, 4 Feb 2020 23:33:38 +0000 Subject: [PATCH 13/16] Bump constraints for new haskell-lsp --- ChangeLog.md | 4 ++++ lsp-test.cabal | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2ad3ba8..3361a12 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Revision history for lsp-test +## 0.10.1.0 -- 2019-02-04 + +* Bump constraints for new haskell-lsp + ## 0.10.0.0 -- 2019-12-29 * Account for messages received between the initialize request and response. diff --git a/lsp-test.cabal b/lsp-test.cabal index 8df7405..8485192 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.10.0.0 +version: 0.10.1.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against @@ -35,7 +35,7 @@ library , parser-combinators:Control.Applicative.Combinators default-language: Haskell2010 build-depends: base >= 4.10 && < 5 - , haskell-lsp == 0.19.* + , haskell-lsp >= 0.19 && < 0.21 , aeson , aeson-pretty , ansi-terminal @@ -77,7 +77,7 @@ test-suite tests build-depends: base >= 4.10 && < 5 , hspec , lens - , haskell-lsp == 0.19.* + , haskell-lsp >= 0.19 && < 0.21 , lsp-test , data-default , aeson -- 2.30.2 From e8a6e5b9442b2cde0d861a169f5b219b64de380e Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sat, 21 Mar 2020 16:22:56 +0000 Subject: [PATCH 14/16] Bump verison of haskell-lsp --- ChangeLog.md | 6 +++++- lsp-test.cabal | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 3361a12..c83131f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,10 @@ # Revision history for lsp-test -## 0.10.1.0 -- 2019-02-04 +## 0.10.1.0 -- 2020-03-21 + +* Bump constraints for new haskell-lsp + +## 0.10.1.0 -- 2020-02-04 * Bump constraints for new haskell-lsp diff --git a/lsp-test.cabal b/lsp-test.cabal index 8485192..4142b2b 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.10.1.0 +version: 0.10.2.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against @@ -35,7 +35,7 @@ library , parser-combinators:Control.Applicative.Combinators default-language: Haskell2010 build-depends: base >= 4.10 && < 5 - , haskell-lsp >= 0.19 && < 0.21 + , haskell-lsp >= 0.19 && < 0.22 , aeson , aeson-pretty , ansi-terminal @@ -77,7 +77,7 @@ test-suite tests build-depends: base >= 4.10 && < 5 , hspec , lens - , haskell-lsp >= 0.19 && < 0.21 + , haskell-lsp >= 0.19 && < 0.22 , lsp-test , data-default , aeson -- 2.30.2 From 1dcc5d9ce4ade0accceafc52c73d66533d343685 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sat, 21 Mar 2020 16:57:46 +0000 Subject: [PATCH 15/16] Bump hie ci version --- .github/workflows/haskell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 0608616..0e23fd4 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} env: - hieref: 8582a960dc1ca389734707f821b273b00bae54ab + hieref: 35f62cffb6bae6c3f86113cb0c55f52b7192689d strategy: matrix: -- 2.30.2 From ddf9bc17ce8a548a927c201c6b0edb8cf1c9fcad Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 4 May 2020 19:16:24 +0100 Subject: [PATCH 16/16] Support haskell-lsp-0.22 --- ChangeLog.md | 6 +++- lsp-test.cabal | 8 ++--- src/Language/Haskell/LSP/Test.hs | 36 +++++++++++------------ src/Language/Haskell/LSP/Test/Decoding.hs | 1 - src/Language/Haskell/LSP/Test/Files.hs | 16 ++++------ src/Language/Haskell/LSP/Test/Replay.hs | 8 ++--- src/Language/Haskell/LSP/Test/Session.hs | 2 +- test/Test.hs | 3 +- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c83131f..ab65edd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,10 @@ # Revision history for lsp-test -## 0.10.1.0 -- 2020-03-21 +## 0.10.3.0 -- 2020-05-04 + +* Build with new haskell-lsp-0.22 + +## 0.10.2.0 -- 2020-03-21 * Bump constraints for new haskell-lsp diff --git a/lsp-test.cabal b/lsp-test.cabal index 4142b2b..c6d543c 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.10.2.0 +version: 0.10.3.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against @@ -20,7 +20,7 @@ build-type: Simple cabal-version: 2.0 extra-source-files: README.md , ChangeLog.md -tested-with: GHC == 8.2.2 , GHC == 8.4.2 , GHC == 8.4.3, GHC == 8.6.4, GHC == 8.6.5, GHC == 8.8.1 +tested-with: GHC == 8.2.2 , GHC == 8.4.2 , GHC == 8.4.3, GHC == 8.6.4, GHC == 8.6.5, GHC == 8.8.1, GHC == 8.10.1 source-repository head type: git @@ -35,7 +35,7 @@ library , parser-combinators:Control.Applicative.Combinators default-language: Haskell2010 build-depends: base >= 4.10 && < 5 - , haskell-lsp >= 0.19 && < 0.22 + , haskell-lsp >= 0.22 && < 0.23 , aeson , aeson-pretty , ansi-terminal @@ -77,7 +77,7 @@ test-suite tests build-depends: base >= 4.10 && < 5 , hspec , lens - , haskell-lsp >= 0.19 && < 0.22 + , haskell-lsp >= 0.22 && < 0.23 , lsp-test , data-default , aeson diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index b3f535f..36841e8 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -160,7 +160,9 @@ runSessionWithConfig config' serverExe caps rootDir session = do -- collect them and then... (inBetween, initRspMsg) <- manyTill_ anyMessage (responseForId initReqId) - liftIO $ maybe (return ()) (putStrLn . ("Error while initializing: " ++) . show ) (initRspMsg ^. LSP.error) + case initRspMsg ^. LSP.result of + Left error -> liftIO $ putStrLn ("Error while initializing: " ++ show error) + Right _ -> pure () initRspVar <- initRsp <$> ask liftIO $ putMVar initRspVar initRspMsg @@ -412,12 +414,11 @@ noDiagnostics = do -- | Returns the symbols in a document. getDocumentSymbols :: TextDocumentIdentifier -> Session (Either [DocumentSymbol] [SymbolInformation]) getDocumentSymbols doc = do - ResponseMessage _ rspLid mRes mErr <- request TextDocumentDocumentSymbol (DocumentSymbolParams doc Nothing) :: Session DocumentSymbolsResponse - maybe (return ()) (throw . UnexpectedResponseError rspLid) mErr - case mRes of - Just (DSDocumentSymbols (List xs)) -> return (Left xs) - Just (DSSymbolInformation (List xs)) -> return (Right xs) - Nothing -> Prelude.error "No result and no error in DocumentSymbolsResponse" + ResponseMessage _ rspLid res <- request TextDocumentDocumentSymbol (DocumentSymbolParams doc Nothing) :: Session DocumentSymbolsResponse + case res of + Right (DSDocumentSymbols (List xs)) -> return (Left xs) + Right (DSSymbolInformation (List xs)) -> return (Right xs) + Left err -> throw (UnexpectedResponseError rspLid err) -- | Returns the code actions in the specified range. getCodeActions :: TextDocumentIdentifier -> Range -> Session [CAResult] @@ -426,8 +427,8 @@ getCodeActions doc range = do rsp <- request TextDocumentCodeAction (CodeActionParams doc range ctx Nothing) case rsp ^. result of - Just (List xs) -> return xs - _ -> throw (UnexpectedResponseError (rsp ^. LSP.id) (fromJust $ rsp ^. LSP.error)) + Right (List xs) -> return xs + Left error -> throw (UnexpectedResponseError (rsp ^. LSP.id) error) -- | Returns all the code actions in a document by -- querying the code actions at each of the current @@ -441,13 +442,11 @@ getAllCodeActions doc = do where go :: CodeActionContext -> [CAResult] -> Diagnostic -> Session [CAResult] go ctx acc diag = do - ResponseMessage _ rspLid mRes mErr <- request TextDocumentCodeAction (CodeActionParams doc (diag ^. range) ctx Nothing) + ResponseMessage _ rspLid res <- request TextDocumentCodeAction (CodeActionParams doc (diag ^. range) ctx Nothing) - case mErr of - Just e -> throw (UnexpectedResponseError rspLid e) - Nothing -> - let Just (List cmdOrCAs) = mRes - in return (acc ++ cmdOrCAs) + case res of + Left e -> throw (UnexpectedResponseError rspLid e) + Right (List cmdOrCAs) -> pure (acc ++ cmdOrCAs) getCodeActionContext :: TextDocumentIdentifier -> Session CodeActionContext getCodeActionContext doc = do @@ -581,9 +580,10 @@ getHighlights doc pos = -- | Checks the response for errors and throws an exception if needed. -- Returns the result if successful. getResponseResult :: ResponseMessage a -> a -getResponseResult rsp = fromMaybe exc (rsp ^. result) - where exc = throw $ UnexpectedResponseError (rsp ^. LSP.id) - (fromJust $ rsp ^. LSP.error) +getResponseResult rsp = + case rsp ^. result of + Right x -> x + Left err -> throw $ UnexpectedResponseError (rsp ^. LSP.id) err -- | Applies formatting to the specified document. formatDoc :: TextDocumentIdentifier -> FormattingOptions -> Session () diff --git a/src/Language/Haskell/LSP/Test/Decoding.hs b/src/Language/Haskell/LSP/Test/Decoding.hs index e635267..8805976 100644 --- a/src/Language/Haskell/LSP/Test/Decoding.hs +++ b/src/Language/Haskell/LSP/Test/Decoding.hs @@ -12,7 +12,6 @@ import System.IO import System.IO.Error import Language.Haskell.LSP.Types import Language.Haskell.LSP.Types.Lens - hiding ( error ) import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Test.Exceptions import qualified Data.HashMap.Strict as HM diff --git a/src/Language/Haskell/LSP/Test/Files.hs b/src/Language/Haskell/LSP/Test/Files.hs index 1c453a6..b56f536 100644 --- a/src/Language/Haskell/LSP/Test/Files.hs +++ b/src/Language/Haskell/LSP/Test/Files.hs @@ -9,7 +9,7 @@ where import Language.Haskell.LSP.Capture import Language.Haskell.LSP.Types -import Language.Haskell.LSP.Types.Lens hiding (error) +import Language.Haskell.LSP.Types.Lens import Language.Haskell.LSP.Messages import Control.Lens import qualified Data.HashMap.Strict as HM @@ -63,15 +63,11 @@ mapUris f event = fromServerMsg (NotPublishDiagnostics n) = NotPublishDiagnostics $ swapUri params n fromServerMsg (RspDocumentSymbols r) = - let newSymbols = case r ^. result of - Just (DSSymbolInformation si) -> Just (DSSymbolInformation (fmap (swapUri location) si)) - x -> x - in RspDocumentSymbols $ result .~ newSymbols $ r - - fromServerMsg (RspRename r) = - let oldResult = r ^. result :: Maybe WorkspaceEdit - newResult = fmap swapWorkspaceEdit oldResult - in RspRename $ result .~ newResult $ r + let swapUri' (DSSymbolInformation si) = DSSymbolInformation (swapUri location <$> si) + swapUri' (DSDocumentSymbols dss) = DSDocumentSymbols dss -- no file locations here + in RspDocumentSymbols $ r & result %~ (fmap swapUri') + + fromServerMsg (RspRename r) = RspRename $ r & result %~ (fmap swapWorkspaceEdit) fromServerMsg x = x diff --git a/src/Language/Haskell/LSP/Test/Replay.hs b/src/Language/Haskell/LSP/Test/Replay.hs index ac55e9e..861d6f7 100644 --- a/src/Language/Haskell/LSP/Test/Replay.hs +++ b/src/Language/Haskell/LSP/Test/Replay.hs @@ -13,7 +13,7 @@ import qualified Data.Text as T import Language.Haskell.LSP.Capture import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types -import Language.Haskell.LSP.Types.Lens as LSP hiding (error) +import Language.Haskell.LSP.Types.Lens as LSP import Data.Aeson import Data.Default import Data.List @@ -108,7 +108,7 @@ sendMessages (nextMsg:remainingMsgs) reqSema rspSema = sendMessages remainingMsgs reqSema rspSema - response msg@(ResponseMessage _ id _ _) = do + response msg@(ResponseMessage _ id _) = do liftIO $ putStrLn $ "Waiting for request id " ++ show id ++ " from the server" reqId <- liftIO $ takeMVar reqSema if responseId reqId /= id @@ -220,9 +220,9 @@ swapCommands pid (FromClient t (ReqExecuteCommand req):xs) = FromClient t (ReqE swapCommands pid (FromServer t (RspInitialize rsp):xs) = FromServer t (RspInitialize swapped):swapCommands pid xs where swapped = case newCommands of - Just cmds -> result . _Just . LSP.capabilities . executeCommandProvider . _Just . commands .~ cmds $ rsp + Just cmds -> result . _Right . LSP.capabilities . executeCommandProvider . _Just . commands .~ cmds $ rsp Nothing -> rsp - oldCommands = rsp ^? result . _Just . LSP.capabilities . executeCommandProvider . _Just . commands + oldCommands = rsp ^? result . _Right . LSP.capabilities . executeCommandProvider . _Just . commands newCommands = fmap (fmap (swapPid pid)) oldCommands swapCommands pid (x:xs) = x:swapCommands pid xs diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index ac4c9ff..c33d801 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -60,7 +60,7 @@ import Data.Function import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types.Capabilities import Language.Haskell.LSP.Types -import Language.Haskell.LSP.Types.Lens hiding (error) +import Language.Haskell.LSP.Types.Lens import Language.Haskell.LSP.VFS import Language.Haskell.LSP.Test.Compat import Language.Haskell.LSP.Test.Decoding diff --git a/test/Test.hs b/test/Test.hs index eb0eef0..e38af42 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -7,6 +7,7 @@ import Test.Hspec import Data.Aeson import Data.Default import qualified Data.HashMap.Strict as HM +import Data.Either import Data.Maybe import qualified Data.Text as T import Control.Applicative.Combinators @@ -37,7 +38,7 @@ main = hspec $ do in session `shouldThrow` anySessionException it "initializeResponse" $ runSession "hie" fullCaps "test/data/renamePass" $ do rsp <- initializeResponse - liftIO $ rsp ^. result `shouldNotBe` Nothing + liftIO $ rsp ^. result `shouldSatisfy` isLeft it "runSessionWithConfig" $ runSession "hie" didChangeCaps "test/data/renamePass" $ return () -- 2.30.2