Add openDoc convenience function
authorLuke Lau <luke_lau@icloud.com>
Fri, 8 Jun 2018 19:47:10 +0000 (15:47 -0400)
committerLuke Lau <luke_lau@icloud.com>
Fri, 8 Jun 2018 19:47:10 +0000 (15:47 -0400)
src/Language/Haskell/LSP/Test.hs
test/Test.hs

index 4de02fe1324b184835fe09b3d8ba5e8c63997d67..068fc2dd0a3cbc17e9da1b98b0f92c5238263f5b 100644 (file)
@@ -60,6 +60,7 @@ module Language.Haskell.LSP.Test
   , (<|>)
   , satisfy
   -- * Utilities
+  , openDoc
   , getDocItem
   , getDocUri
   ) where
@@ -213,6 +214,13 @@ sendMessage msg = do
   h <- serverIn <$> ask
   liftIO $ B.hPut h $ addHeader (encode msg)
 
+-- | Opens a text document and sends a notification to the client.
+openDoc :: FilePath -> String -> Session TextDocumentIdentifier
+openDoc file languageId = do
+  item <- getDocItem file languageId
+  sendNotification TextDocumentDidOpen (DidOpenTextDocumentParams item)
+  TextDocumentIdentifier <$> getDocUri file
+
 -- | Reads in a text document as the first version.
 getDocItem :: FilePath -- ^ The path to the text document to read in.
            -> String -- ^ The language ID, e.g "haskell" for .hs files.
index 13e7ccc5d3066b687c7ca4391a3e6e8af62cbe77..fd2466677b3c80702f25482dc5e515225e8eb142 100644 (file)
@@ -14,10 +14,7 @@ main = hspec $ do
   describe "manual session validation" $ 
     it "passes a test" $
       runSession "test/recordings/renamePass" $ do
-        docItem <- getDocItem "Desktop/simple.hs" "haskell"
-        docId   <- TextDocumentIdentifier <$> getDocUri "Desktop/simple.hs"
-
-        sendNotification TextDocumentDidOpen (DidOpenTextDocumentParams docItem)
+        doc <- openDoc "Desktop/simple.hs" "haskell"
 
         skipMany loggingNotification
 
@@ -27,7 +24,7 @@ main = hspec $ do
         
         sendRequest (Proxy :: Proxy DocumentSymbolRequest)
                     TextDocumentDocumentSymbol
-                    (DocumentSymbolParams docId)
+                    (DocumentSymbolParams doc)
 
         RspDocumentSymbols rspSymbols <- response