Add closeDoc
authorLuke Lau <luke_lau@icloud.com>
Mon, 23 Jul 2018 21:52:55 +0000 (22:52 +0100)
committerLuke Lau <luke_lau@icloud.com>
Mon, 23 Jul 2018 21:52:55 +0000 (22:52 +0100)
src/Language/Haskell/LSP/Test.hs
test/Test.hs

index b648078b8c1fe14ece70330755867b25a6bb63c8..60f13b1be25bdfe867e1d815fdb7668ae5a65630 100644 (file)
@@ -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
index 56bd01dd0a1a5ec4d2ae65418706acf19620f0e0..a4a41732e395e36c9581525f398f985f32527af0 100644 (file)
@@ -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