From: Luke Lau Date: Mon, 25 Nov 2019 17:24:41 +0000 (+0000) Subject: Merge branch 'master' into github-actions X-Git-Url: https://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=803c622b2a390a310584d9f8170c9ec1c8ea67db;hp=d46bb3df79fd71344d0c8d7c6de5b67c99f65906 Merge branch 'master' into github-actions --- diff --git a/ChangeLog.md b/ChangeLog.md index f01ba4f..c75f2c6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,14 @@ # Revision history for lsp-test +## 0.8.2.0 -- 2019-11-17 + +* Expose `satisfyMaybe` (@cocreature) + +## 0.8.1.0 -- 2019-11-17 + +* Update to haskell-lsp-0.18.0.0 (@mpickering, @alanz) +* Tests now require hie-bios based hie + ## 0.8.0.0 -- 2019-10-18 * Make `Session` a newtype diff --git a/README.md b/README.md index 11f3709..9f0251b 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,6 @@ The tests are integration tests, so make sure you have the following language se `npm i -g javascript-typescript-langserver` Then run the tests with `stack test` or `cabal new-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) diff --git a/lsp-test.cabal b/lsp-test.cabal index 80283b7..bdb4275 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.8.0.0 +version: 0.8.2.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.10 && < 5 - , haskell-lsp == 0.17.* + , haskell-lsp == 0.18.* , aeson , aeson-pretty , ansi-terminal @@ -44,7 +44,7 @@ library , bytestring , conduit , conduit-parse == 0.2.* - , containers + , containers >= 0.5.9 , data-default , Diff , directory @@ -79,7 +79,7 @@ test-suite tests build-depends: base >= 4.10 && < 5 , hspec , lens - , haskell-lsp == 0.17.* + , haskell-lsp == 0.18.* , lsp-test , data-default , aeson diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 22091c3..a6612e2 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -188,7 +188,7 @@ runSessionWithConfig config serverExe caps rootDir session = do documentContents :: TextDocumentIdentifier -> Session T.Text documentContents doc = do vfs <- vfs <$> get - let file = vfs Map.! toNormalizedUri (doc ^. uri) + let file = vfsMap vfs Map.! toNormalizedUri (doc ^. uri) return $ Rope.toText $ Language.Haskell.LSP.VFS._text file -- | Parses an ApplyEditRequest, checks that it is for the passed document @@ -273,7 +273,7 @@ sendNotification TextDocumentDidOpen params = do n :: DidOpenTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidOpen params' oldVFS <- vfs <$> get - newVFS <- liftIO $ openVFS oldVFS n + let (newVFS,_) = openVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -283,7 +283,7 @@ sendNotification TextDocumentDidClose params = do n :: DidCloseTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidClose params' oldVFS <- vfs <$> get - newVFS <- liftIO $ closeVFS oldVFS n + let (newVFS,_) = closeVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -292,7 +292,7 @@ sendNotification TextDocumentDidChange params = do n :: DidChangeTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidChange params' oldVFS <- vfs <$> get - newVFS <- liftIO $ changeFromClientVFS oldVFS n + let (newVFS,_) = changeFromClientVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -449,10 +449,10 @@ executeCodeAction action = do -- | Adds the current version to the document, as tracked by the session. getVersionedDoc :: TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier getVersionedDoc (TextDocumentIdentifier uri) = do - fs <- vfs <$> get + fs <- vfsMap . vfs <$> get let ver = case fs Map.!? toNormalizedUri uri of - Just (VirtualFile v _ _) -> Just v + Just (VirtualFile v _) -> Just v _ -> Nothing return (VersionedTextDocumentIdentifier uri ver) diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 70481b9..5ce9b52 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -6,6 +6,7 @@ module Language.Haskell.LSP.Test.Parsing ( -- $receiving satisfy + , satisfyMaybe , message , anyRequest , anyResponse diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index b8dbe2a..67e4ae6 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -220,8 +220,9 @@ runSessionWithHandles serverIn serverOut serverProc serverHandler config caps ro mainThreadId <- myThreadId let context = SessionContext serverIn absRootDir messageChan reqMap initRsp config caps - initState = SessionState (IdInt 0) mempty mempty 0 False Nothing - runSession' = runSession context initState + initState vfs = SessionState (IdInt 0) vfs + mempty 0 False Nothing + runSession' ses = initVFS $ \vfs -> runSession context (initState vfs) ses errorHandler = throwTo mainThreadId :: SessionException -> IO() serverListenerLauncher = @@ -280,8 +281,8 @@ updateState (ReqApplyWorkspaceEdit r) = do forM_ bumpedVersions $ \(VersionedTextDocumentIdentifier uri v) -> modify $ \s -> let oldVFS = vfs s - update (VirtualFile oldV t mf) = VirtualFile (fromMaybe oldV v) t mf - newVFS = Map.adjust update (toNormalizedUri uri) oldVFS + update (VirtualFile oldV t) = VirtualFile (fromMaybe oldV v) t + newVFS = updateVFS (Map.adjust update (toNormalizedUri uri)) oldVFS in s { vfs = newVFS } where checkIfNeedsOpened uri = do @@ -289,7 +290,7 @@ updateState (ReqApplyWorkspaceEdit r) = do ctx <- ask -- if its not open, open it - unless (toNormalizedUri uri `Map.member` oldVFS) $ do + unless (toNormalizedUri uri `Map.member` (vfsMap oldVFS)) $ do let fp = fromJust $ uriToFilePath uri contents <- liftIO $ T.readFile fp let item = TextDocumentItem (filePathToUri fp) "" 0 contents @@ -297,7 +298,7 @@ updateState (ReqApplyWorkspaceEdit r) = do liftIO $ B.hPut (serverIn ctx) $ addHeader (encode msg) modifyM $ \s -> do - newVFS <- liftIO $ openVFS (vfs s) msg + let (newVFS,_) = openVFS (vfs s) msg return $ s { vfs = newVFS } getParams (TextDocumentEdit docId (List edits)) = diff --git a/test/Test.hs b/test/Test.hs index c662d46..22f8e21 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -240,7 +240,8 @@ main = hspec $ do noDiagnostics noDiagnostics - item:_ <- getCompletions doc (Position 5 5) + comps <- getCompletions doc (Position 5 5) + let item = head (filter (\x -> x ^. label == "interactWithUser") comps) liftIO $ do item ^. label `shouldBe` "interactWithUser" item ^. kind `shouldBe` Just CiFunction @@ -275,10 +276,10 @@ main = hspec $ do describe "waitForDiagnosticsSource" $ it "works" $ runSession "hie" fullCaps "test/data" $ do openDoc "Error.hs" "haskell" - [diag] <- waitForDiagnosticsSource "ghcmod" + [diag] <- waitForDiagnosticsSource "bios" liftIO $ do diag ^. severity `shouldBe` Just DsError - diag ^. source `shouldBe` Just "ghcmod" + diag ^. source `shouldBe` Just "bios" describe "rename" $ it "works" $ runSession "hie" fullCaps "test/data" $ do