Merge branch 'master' into github-actions
authorLuke Lau <luke_lau@icloud.com>
Mon, 25 Nov 2019 17:24:41 +0000 (17:24 +0000)
committerLuke Lau <luke_lau@icloud.com>
Mon, 25 Nov 2019 17:24:41 +0000 (17:24 +0000)
ChangeLog.md
README.md
lsp-test.cabal
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Parsing.hs
src/Language/Haskell/LSP/Test/Session.hs
test/Test.hs

index f01ba4f1be489498bc1fa871af1f44ace48d6325..c75f2c6834648570689b339c5a1966358fe0e67d 100644 (file)
@@ -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
index 11f370918e27fb78c08c9f9236d383af5a180b7d..9f0251b3f841dbc46acb7c4fa2d5211338b20239 100644 (file)
--- 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)
index 80283b75b07f32b6844fa2caa3f8445fa86ffd5f..bdb4275d5536602de9c04a1f8077334e84a098f4 100644 (file)
@@ -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
index 22091c3451c16f00d6848502a60dafc0a9edd928..a6612e2c49c6aaffc3148c44bb285e35d8c46bae 100644 (file)
@@ -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)
 
index 70481b979a83a67434dff19f1bb304af3ee65789..5ce9b52995c05f0deb899c1327ae7476043760d2 100644 (file)
@@ -6,6 +6,7 @@
 module Language.Haskell.LSP.Test.Parsing
   ( -- $receiving
     satisfy
+  , satisfyMaybe
   , message
   , anyRequest
   , anyResponse
index b8dbe2ac04797c21ddf2d6b7a4beba3036d67c86..67e4ae65d7d44175d244f882190146030a309e3e 100644 (file)
@@ -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)) =
index c662d46af44fb141fe0ec7d13172fe119dbbb9cc..22f8e21996df80c4b9e9a81b95d07edbab5e72d3 100644 (file)
@@ -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