From 3081abf6552222c5dfc7928d4c708dd03015548e Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 8 Jun 2018 15:47:10 -0400 Subject: [PATCH] Add openDoc convenience function --- src/Language/Haskell/LSP/Test.hs | 8 ++++++++ test/Test.hs | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 4de02fe..068fc2d 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -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. diff --git a/test/Test.hs b/test/Test.hs index 13e7ccc..fd24666 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -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 -- 2.30.2