Merge branch 'master' of https://github.com/Bubba/haskell-lsp-test
authorLuke Lau <luke_lau@icloud.com>
Wed, 20 Jun 2018 16:41:51 +0000 (17:41 +0100)
committerLuke Lau <luke_lau@icloud.com>
Wed, 20 Jun 2018 16:41:51 +0000 (17:41 +0100)
README.md
haskell-lsp-test.cabal
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Server.hs
stack.yaml
test/Test.hs

index f866ccfcc30af7ff000583314e73bae5813aaefb..0af386e54c3a75c8be2f2af3af767ff6fb2693ce 100644 (file)
--- a/README.md
+++ b/README.md
@@ -7,9 +7,8 @@ runSession "session/root/dir" $ do
   
   skipMany notification
   
-  sendRequest (Proxy :: Proxy DocumentSymbolRequest)
-              TextDocumentDocumentSymbol
-              (DocumentSymbolParams doc)
+  sendRequest TextDocumentDocumentSymbol (DocumentSymbolParams doc)
               
-  RspDocumentSymbols rspSymbols <- response
+  rspSymbols <- response :: DocumentSymbolsResponse
   let (List symbols) = fromJust (rspSymbols ^. result)
+```
index 51f5fb94ff2762da84d2164ac6c758da878fc02b..eef87c601a08b41cd0cff95414727d39ff648a40 100644 (file)
@@ -20,7 +20,7 @@ library
   default-language:    Haskell2010
   build-depends:       base >= 4.7 && < 5
                      , haskell-lsp-types
-                     , haskell-lsp
+                     , haskell-lsp >= 0.3
                      , aeson
                      , bytestring
                      , conduit
@@ -57,9 +57,11 @@ test-suite tests
   build-depends:       base >= 4.7 && < 5
                      , hspec
                      , lens
+                     , data-default
                      , directory
                      , haskell-lsp-test
                      , haskell-lsp
+                     , haskell-lsp-types
                      , conduit
                      , conduit-parse
                      , aeson
index b2d731e675cd897de03008106bbcb316bf5253bc..48869b4b4d640c81aa3d39adf87cb6356caee44a 100644 (file)
@@ -16,6 +16,7 @@ module Language.Haskell.LSP.Test
   -- * Sessions
     runSession
   , runSessionWithHandles
+  , runSessionWithCapabilities
   , Session
   -- * Sending
   , sendRequest
@@ -75,6 +76,7 @@ import qualified Data.Map as Map
 import Data.Maybe
 import Language.Haskell.LSP.Types
 import qualified  Language.Haskell.LSP.Types as LSP (error, id)
+import Language.Haskell.LSP.TH.ClientCapabilities
 import Language.Haskell.LSP.VFS
 import Language.Haskell.LSP.Test.Compat
 import Language.Haskell.LSP.Test.Decoding
@@ -91,7 +93,15 @@ runSession :: String -- ^ The command to run the server.
            -> FilePath -- ^ The filepath to the root directory for the session.
            -> Session a -- ^ The session to run.
            -> IO a
-runSession serverExe rootDir session = do
+runSession = runSessionWithCapabilities def
+
+-- | Starts a new sesion with a client with the specified capabilities.
+runSessionWithCapabilities :: ClientCapabilities -- ^ The capabilities the client should have.
+                           -> String -- ^ The command to run the server.
+                           -> FilePath -- ^ The filepath to the root directory for the session.
+                           -> Session a -- ^ The session to run.
+                           -> IO a
+runSessionWithCapabilities caps serverExe rootDir session = do
   pid <- getProcessID
   absRootDir <- canonicalizePath rootDir
 
@@ -99,7 +109,7 @@ runSession serverExe rootDir session = do
                                           (Just $ T.pack absRootDir)
                                           (Just $ filePathToUri absRootDir)
                                           Nothing
-                                          def
+                                          caps
                                           (Just TraceOff)
 
   withServer serverExe $ \serverIn serverOut _ -> runSessionWithHandles serverIn serverOut listenServer rootDir $ do
index 8159bef129784d07fcab9cd6e7b842ab4d9d47f5..473f2c76e1c39c46252e0f1b0a0933a05db60185 100644 (file)
@@ -8,6 +8,8 @@ import System.Process
 
 withServer :: String -> (Handle -> Handle -> Int -> IO a) -> IO a
 withServer serverExe f = do
+  -- TODO Probably should just change runServer to accept
+  -- separate command and arguments
   let cmd:args = words serverExe
       createProc = (proc cmd args) { std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
   (Just serverIn, Just serverOut, Just serverErr, serverProc) <- createProcess createProc
index 76fa9bc997b85c0a17983d6800d98d791efaddda..e77a024ce2d66fb951acaf36a22fbc407ce0edd0 100644 (file)
@@ -3,10 +3,11 @@ packages:
   - .
 
 extra-deps:
+  # - haskell-lsp
   - github: Bubba/haskell-lsp-client
     commit: b7cf14eb48837a73032e867dab90db1708220c66
   - github: Bubba/haskell-lsp
-    commit: 554b1535ae120f8541f860db5f131372da102bef
+    commit: 3e046bf095568099dae606e1c20a92f1dc60b7b9
     subdirs:
       - .
       - ./haskell-lsp-types
index d615cb904fea91caac358fc30e07fd7f1f89dbc0..d83d03d5082b2cc138b2ea9bcfb86b984954cdfd 100644 (file)
@@ -4,6 +4,7 @@
 {-# LANGUAGE DeriveAnyClass #-}
 import           Test.Hspec
 import           Data.Aeson
+import           Data.Default
 import qualified Data.HashMap.Strict as HM
 import           Data.Maybe
 import           Control.Monad.IO.Class
@@ -11,6 +12,7 @@ import           Control.Lens hiding (List)
 import           GHC.Generics
 import           Language.Haskell.LSP.Test
 import           Language.Haskell.LSP.Test.Replay
+import           Language.Haskell.LSP.TH.ClientCapabilities
 import           Language.Haskell.LSP.Types
 import           ParsingTests
 
@@ -45,6 +47,12 @@ main = hspec $ do
       rsp <- getInitializeResponse
       liftIO $ rsp ^. result `shouldNotBe` Nothing
 
+    it "can register specific capabilities" $ do
+      let caps = def { _workspace = Just workspaceCaps }
+          workspaceCaps = def { _didChangeConfiguration = Just configCaps }
+          configCaps = DidChangeConfigurationClientCapabilities (Just True)
+      runSessionWithCapabilities caps "hie --lsp" "test/data/renamePass" $ return ()
+
   describe "replay session" $ do
     it "passes a test" $
       replaySession "hie --lsp" "test/data/renamePass" `shouldReturn` True