+ es `shouldBe` [TextEdit (Range (Position 0 0) (Position 0 5)) "howdy"]
+ contents <- documentContents doc
+ liftIO $ contents `shouldBe` "howdy:: IO Int\nmain = return (42)\n"
+
+ describe "getDocumentEdit" $
+ it "automatically consumes applyedit requests" $
+ runSession serverExe fullCaps "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+
+ let args = toJSON (doc ^. uri)
+ reqParams = ExecuteCommandParams "doAnEdit" (Just (List [args])) Nothing
+ request_ WorkspaceExecuteCommand reqParams
+ contents <- getDocumentEdit doc
+ liftIO $ contents `shouldBe` "howdy:: IO Int\nmain = return (42)\n"
+
+ describe "getCodeActions" $
+ it "works" $ runSession serverExe fullCaps "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+ waitForDiagnostics
+ [CACodeAction action] <- getCodeActions doc (Range (Position 1 14) (Position 1 18))
+ liftIO $ action ^. title `shouldBe` "Delete this"
+
+ describe "getAllCodeActions" $
+ it "works" $ runSession serverExe fullCaps "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+ _ <- waitForDiagnostics
+ actions <- getAllCodeActions doc
+ liftIO $ do
+ let [CACodeAction action] = actions
+ action ^. title `shouldBe` "Delete this"
+ action ^. command . _Just . command `shouldBe` "deleteThis"
+
+ describe "getDocumentSymbols" $
+ it "works" $ runSession serverExe fullCaps "test/data/renamePass" $ do
+ doc <- openDoc "Desktop/simple.hs" "haskell"
+
+ skipMany loggingNotification
+
+ Left (mainSymbol:_) <- getDocumentSymbols doc
+
+ liftIO $ do
+ mainSymbol ^. name `shouldBe` "foo"
+ mainSymbol ^. kind `shouldBe` SkObject
+ mainSymbol ^. range `shouldBe` mkRange 0 0 3 6
+
+ describe "applyEdit" $ do
+ it "increments the version" $ runSession serverExe docChangesCaps "test/data/renamePass" $ do
+ doc <- openDoc "Desktop/simple.hs" "haskell"
+ VersionedTextDocumentIdentifier _ (Just oldVersion) <- getVersionedDoc doc
+ let edit = TextEdit (Range (Position 1 1) (Position 1 3)) "foo"
+ VersionedTextDocumentIdentifier _ (Just newVersion) <- applyEdit doc edit
+ liftIO $ newVersion `shouldBe` oldVersion + 1
+ it "changes the document contents" $ runSession serverExe fullCaps "test/data/renamePass" $ do
+ doc <- openDoc "Desktop/simple.hs" "haskell"
+ let edit = TextEdit (Range (Position 0 0) (Position 0 2)) "foo"
+ applyEdit doc edit
+ contents <- documentContents doc
+ liftIO $ contents `shouldSatisfy` T.isPrefixOf "foodule"
+
+ -- describe "getCompletions" $
+ -- it "works" $ runSession serverExe def "test/data/renamePass" $ do
+ -- doc <- openDoc "Desktop/simple.hs" "haskell"
+
+ -- -- wait for module to be loaded
+ -- skipMany loggingNotification
+ -- noDiagnostics
+ -- noDiagnostics
+
+ -- comps <- getCompletions doc (Position 5 5)
+ -- let item = head (filter (\x -> x ^. label == "interactWithUser") comps)
+ -- liftIO $ do
+ -- item ^. label `shouldBe` "interactWithUser"
+ -- item ^. kind `shouldBe` Just CiFunction
+ -- item ^. detail `shouldBe` Just "Items -> IO ()\nMain"
+
+ -- describe "getReferences" $
+ -- it "works" $ runSession serverExe fullCaps "test/data/renamePass" $ do
+ -- doc <- openDoc "Desktop/simple.hs" "haskell"
+ -- let pos = Position 40 3 -- interactWithUser
+ -- uri = doc ^. LSP.uri
+ -- refs <- getReferences doc pos True
+ -- liftIO $ refs `shouldContain` map (Location uri) [
+ -- mkRange 41 0 41 16
+ -- , mkRange 75 6 75 22
+ -- , mkRange 71 6 71 22
+ -- ]
+
+ -- describe "getDefinitions" $
+ -- it "works" $ runSession serverExe fullCaps "test/data/renamePass" $ do
+ -- doc <- openDoc "Desktop/simple.hs" "haskell"
+ -- let pos = Position 49 25 -- addItem
+ -- defs <- getDefinitions doc pos
+ -- liftIO $ defs `shouldBe` [Location (doc ^. uri) (mkRange 28 0 28 7)]