From: Luke Lau Date: Mon, 23 Jul 2018 21:52:55 +0000 (+0100) Subject: Add closeDoc X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=commitdiff_plain;h=776b8e1a475e2150797d432f0c13ccf685b1cd4b Add closeDoc --- diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index b648078..60f13b1 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -46,6 +46,7 @@ module Language.Haskell.LSP.Test , initializeResponse -- ** Documents , openDoc + , closeDoc , documentContents , getDocumentEdit , getDocUri @@ -308,6 +309,17 @@ openDoc file languageId = do contents <- liftIO $ T.readFile fp return $ TextDocumentItem (filePathToUri fp) (T.pack languageId) 0 contents +-- | Closes a text document and sends a notification to the client. +closeDoc :: TextDocumentIdentifier -> Session () +closeDoc docId = do + let params = DidCloseTextDocumentParams (TextDocumentIdentifier (docId ^. uri)) + sendNotification TextDocumentDidClose params + + oldVfs <- vfs <$> get + let notif = NotificationMessage "" TextDocumentDidClose params + newVfs <- liftIO $ closeVFS oldVfs notif + modify $ \s -> s { vfs = newVfs } + -- | Gets the Uri for the file corrected to the session directory. getDocUri :: FilePath -> Session Uri getDocUri file = do diff --git a/test/Test.hs b/test/Test.hs index 56bd01d..a4a4173 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -289,6 +289,16 @@ main = hspec $ do formatRange doc (FormattingOptions 4 True) (Range (Position 1 10) (Position 2 10)) documentContents doc >>= liftIO . (`shouldNotBe` oldContents) + describe "closeDoc" $ + it "works" $ + let sesh = + runSession "hie --lsp" "test/data" $ do + doc <- openDoc "Format.hs" "haskell" + closeDoc doc + -- need to evaluate to throw + documentContents doc >>= liftIO . print + in sesh `shouldThrow` anyException + mkRange sl sc el ec = Range (Position sl sc) (Position el ec) didChangeCaps :: ClientCapabilities