X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=test%2FTest.hs;h=c6ef7e29e90ca44e6ad592e379aa7f3ef64579f7;hp=3c53aec67dd292859abc0285e939da6d3d3d532f;hb=22df37c703e39fa5ebeb130be5785b3a9713c520;hpb=502c8dc3ff63383487536922176330a3f459a462 diff --git a/test/Test.hs b/test/Test.hs index 3c53aec..c6ef7e2 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} + import Test.Hspec import Data.Aeson import Data.Default @@ -26,7 +27,7 @@ main = hspec $ do skipMany loggingNotification - checkNoDiagnostics + noDiagnostics rspSymbols <- documentSymbols doc @@ -46,7 +47,7 @@ main = hspec $ do anyRequest in session `shouldThrow` anyException it "can get initialize response" $ runSession "hie --lsp" "test/data/renamePass" $ do - rsp <- getInitializeResponse + rsp <- initializeResponse liftIO $ rsp ^. result `shouldNotBe` Nothing it "can register specific capabilities" $ do @@ -99,7 +100,7 @@ main = hspec $ do runSession "javascript-typescript-stdio" "test/data/javascriptPass" $ do doc <- openDoc "test.js" "javascript" - checkNoDiagnostics + noDiagnostics rspSymbols <- documentSymbols doc @@ -109,7 +110,7 @@ main = hspec $ do fooSymbol ^. name `shouldBe` "foo" fooSymbol ^. kind `shouldBe` SkFunction - describe "text document state" $ + describe "text document VFS" $ it "sends back didChange notifications" $ runSession "hie --lsp" "test/data/refactor" $ do doc <- openDoc "Main.hs" "haskell" @@ -129,11 +130,28 @@ main = hspec $ do u `shouldBe` doc ^. uri es `shouldBe` [TextEdit (Range (Position 1 0) (Position 1 18)) "main = return 42"] - checkNoDiagnostics + 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 + skipMany anyNotification + _ <- response :: Session ExecuteCommandResponse + + contents <- documentEdit doc + liftIO $ contents `shouldBe` "main :: IO Int\nmain = return 42" + noDiagnostics + parsingSpec data ApplyOneParams = AOP @@ -142,12 +160,3 @@ data ApplyOneParams = AOP , hintTitle :: String } deriving (Generic, ToJSON) -checkNoDiagnostics :: Session () -checkNoDiagnostics = do - diagsNot <- notification :: Session PublishDiagnosticsNotification - liftIO $ diagsNot ^. params . diagnostics `shouldBe` List [] - -documentSymbols :: TextDocumentIdentifier -> Session DocumentSymbolsResponse -documentSymbols doc = do - sendRequest TextDocumentDocumentSymbol (DocumentSymbolParams doc) - response