Add openDoc convenience function
[lsp-test.git] / src / Language / Haskell / LSP / 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.