packages feed

lsp-test 0.2.0.0 → 0.2.1.0

raw patch · 6 files changed

+45/−13 lines, 6 filesdep ~haskell-lsp

Dependency ranges changed: haskell-lsp

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for lsp-test +## 0.2.1.0 -- 2018-08-14++* Add getCodeActions+* Add getCurrentDiagnostics+ ## 0.2.0.0 -- 2018-08-06  * Update to haskell-lsp 0.6.0.0
README.md view
@@ -1,4 +1,4 @@-# lsp-test [![Build Status](https://travis-ci.com/Bubba/haskell-lsp-test.svg?branch=master)](https://travis-ci.com/Bubba/haskell-lsp-test) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test-0.1.0.0)+# lsp-test [![Build Status](https://travis-ci.com/Bubba/lsp-test.svg?branch=master)](https://travis-ci.com/Bubba/lsp-test) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test-0.1.0.0) lsp-test is a functional testing framework for Language Server Protocol servers.  ```haskell@@ -35,7 +35,7 @@ ```  Try out the example tests in the `example` directory with `cabal new-test`.-For more examples check the [Wiki](https://github.com/Bubba/haskell-lsp-test/wiki/Introduction)+For more examples check the [Wiki](https://github.com/Bubba/lsp-test/wiki/Introduction)  ## Developing To test make sure you have the following language servers installed:
lsp-test.cabal view
@@ -1,5 +1,5 @@ name:                lsp-test-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Functional test framework for LSP servers. description:   A test framework for writing tests against @@ -78,9 +78,9 @@   build-depends:       base >= 4.7 && < 5                      , hspec                      , lens-                     , data-default-                     , haskell-lsp >= 0.6+                     , haskell-lsp                      , lsp-test+                     , data-default                      , aeson                      , unordered-containers                      , text
src/Language/Haskell/LSP/Test.hs view
@@ -52,9 +52,11 @@   , waitForDiagnostics   , waitForDiagnosticsSource   , noDiagnostics+  , getCurrentDiagnostics   -- ** Commands   , executeCommand   -- ** Code Actions+  , getCodeActions   , getAllCodeActions   , executeCodeAction   -- ** Completions@@ -358,15 +360,24 @@     Just (DSSymbolInformation (List xs)) -> return (Right xs)     Nothing -> Prelude.error "No result and no error in DocumentSymbolsResponse" +-- | Returns the code actions in the specified range.+getCodeActions :: TextDocumentIdentifier -> Range -> Session [CAResult]+getCodeActions doc range = do+  ctx <- getCodeActionContext doc+  rsp <- request TextDocumentCodeAction (CodeActionParams doc range ctx)++  case rsp ^. result of+    Just (List xs) -> return xs+    _ -> throw (UnexpectedResponseError (rsp ^. LSP.id) (fromJust $ rsp ^. LSP.error))+ -- | Returns all the code actions in a document by  -- querying the code actions at each of the current  -- diagnostics' positions. getAllCodeActions :: TextDocumentIdentifier -> Session [CAResult] getAllCodeActions doc = do-  curDiags <- fromMaybe [] . Map.lookup (doc ^. uri) . curDiagnostics <$> get-  let ctx = CodeActionContext (List curDiags) Nothing+  ctx <- getCodeActionContext doc -  foldM (go ctx) [] curDiags+  foldM (go ctx) [] =<< getCurrentDiagnostics doc    where     go :: CodeActionContext -> [CAResult] -> Diagnostic -> Session [CAResult]@@ -378,6 +389,16 @@         Nothing ->           let Just (List cmdOrCAs) = mRes             in return (acc ++ cmdOrCAs)++getCodeActionContext :: TextDocumentIdentifier -> Session CodeActionContext+getCodeActionContext doc = do+  curDiags <- getCurrentDiagnostics doc+  return $ CodeActionContext (List curDiags) Nothing++-- | Returns the current diagnostics that have been sent to the client.+-- Note that this does not wait for more to come in.+getCurrentDiagnostics :: TextDocumentIdentifier -> Session [Diagnostic]+getCurrentDiagnostics doc = fromMaybe [] . Map.lookup (doc ^. uri) . curDiagnostics <$> get  -- | Executes a command. executeCommand :: Command -> Session ()
src/Language/Haskell/LSP/Test/Server.hs view
@@ -1,6 +1,7 @@ module Language.Haskell.LSP.Test.Server (withServer) where  import Control.Concurrent+import Control.Exception import Control.Monad import Language.Haskell.LSP.Test.Compat import System.IO@@ -21,8 +22,6 @@    pid <- getProcessID serverProc -  result <- f serverIn serverOut pid--  killThread errSinkThread-  terminateProcess serverProc-  return result+  finally (f serverIn serverOut pid) $ do+    killThread errSinkThread+    terminateProcess serverProc
test/Test.hs view
@@ -176,6 +176,13 @@         liftIO $ contents `shouldBe` "main :: IO Int\nmain = return 42\n"         noDiagnostics +  describe "getCodeActions" $+    it "works" $ runSession "hie" 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` "Apply hint:Redundant bracket"+   describe "getAllCodeActions" $     it "works" $ runSession "hie --lsp" fullCaps "test/data/refactor" $ do       doc <- openDoc "Main.hs" "haskell"