From: Luke Lau Date: Fri, 8 Jun 2018 19:47:10 +0000 (-0400) Subject: Add openDoc convenience function X-Git-Tag: 0.1.0.0~83 X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=3081abf6552222c5dfc7928d4c708dd03015548e Add openDoc convenience function --- 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