- replay "test/recordings/documentSymbolFail/client.log"
- "test/recordings/documentSymbolFail/server.log"
- "test/recordings/documentSymbolFail"
- `shouldReturn` False
-
- -- describe "file swapping" $ do
- -- it "gets the base directory" $ do
- -- h <- openFile "test/recordings/renamePass/client.log" ReadMode
- -- msgs <- getAllMessages h
- -- rootDir msgs `shouldBe` "/Users/luke/Desktop"
-
- -- it "gets builds a mapping of files" $ do
- -- h <- openFile "test/recordings/renamePass/client.log" ReadMode
- -- msgs <- getAllMessages h
- -- let root = rootDir msgs
- -- swapped <- swapFiles root "test/recordings/renamePass/" msgs
- -- let (Just n) = decode (swapped !! 3) :: Maybe LSP.DidOpenNotification
-
- -- cd <- getCurrentDirectory
-
- -- n .^ params . uri `shouldBe` LSP.uriFromFilePath (cd </> "test/recordings/renamePass/")
+ let selector (ReplayOutOfOrderException _ _) = True
+ selector _ = False
+ in replaySession "hie --lsp" "test/data/renameFail" `shouldThrow` selector
+
+ describe "manual javascript session" $
+ it "passes a test" $
+ runSession "javascript-typescript-stdio" "test/data/javascriptPass" $ do
+ doc <- openDoc "test.js" "javascript"
+
+ noDiagnostics
+
+ (fooSymbol:_) <- getDocumentSymbols doc
+
+ liftIO $ do
+ fooSymbol ^. name `shouldBe` "foo"
+ fooSymbol ^. kind `shouldBe` SkFunction
+
+ describe "text document VFS" $
+ it "sends back didChange notifications" $
+ runSession "hie --lsp" "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+
+ let args = toJSON $ AOP (doc ^. uri)
+ (Position 1 14)
+ "Redundant bracket"
+ reqParams = ExecuteCommandParams "applyrefact:applyOne" (Just (List [args]))
+ sendRequest_ WorkspaceExecuteCommand reqParams
+
+ editReq <- request :: Session ApplyWorkspaceEditRequest
+ liftIO $ do
+ let (Just cs) = editReq ^. params . edit . changes
+ [(u, List es)] = HM.toList cs
+ u `shouldBe` doc ^. uri
+ es `shouldBe` [TextEdit (Range (Position 1 0) (Position 1 18)) "main = return 42"]
+
+ noDiagnostics
+
+ contents <- documentContents doc
+ liftIO $ contents `shouldBe` "main :: IO Int\nmain = return 42"
+
+ describe "documentEdit" $
+ it "automatically consumes applyedit requests" $
+ runSession "hie --lsp" "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+
+ let args = toJSON $ AOP (doc ^. uri)
+ (Position 1 14)
+ "Redundant bracket"
+ reqParams = ExecuteCommandParams "applyrefact:applyOne" (Just (List [args]))
+ sendRequest_ WorkspaceExecuteCommand reqParams
+ contents <- getDocumentEdit doc
+ liftIO $ contents `shouldBe` "main :: IO Int\nmain = return 42"
+ noDiagnostics
+
+ describe "getAllCodeActions" $
+ it "works" $ runSession "hie --lsp" "test/data/refactor" $ do
+ doc <- openDoc "Main.hs" "haskell"
+ _ <- waitForDiagnostics
+ actions <- getAllCodeActions doc
+ liftIO $ do
+ let [CommandOrCodeActionCommand action] = actions
+ action ^. title `shouldBe` "Apply hint:Redundant bracket"
+ action ^. command `shouldSatisfy` T.isSuffixOf ":applyrefact:applyOne"
+
+ describe "getDocumentSymbols" $
+ it "works" $ runSession "hie --lsp" "test/data/renamePass" $ do
+ doc <- openDoc "Desktop/simple.hs" "haskell"
+
+ skipMany loggingNotification
+
+ noDiagnostics
+
+ (mainSymbol:_) <- getDocumentSymbols doc
+
+ liftIO $ do
+ mainSymbol ^. name `shouldBe` "main"
+ mainSymbol ^. kind `shouldBe` SkFunction
+ mainSymbol ^. location . range `shouldBe` Range (Position 3 0) (Position 3 4)
+ mainSymbol ^. containerName `shouldBe` Nothing
+
+ parsingSpec
+
+data ApplyOneParams = AOP
+ { file :: Uri
+ , start_pos :: Position
+ , hintTitle :: String
+ } deriving (Generic, ToJSON)
+