Add option to configure capabilities
authorLuke Lau <luke_lau@icloud.com>
Wed, 20 Jun 2018 15:27:02 +0000 (16:27 +0100)
committerLuke Lau <luke_lau@icloud.com>
Wed, 20 Jun 2018 15:27:02 +0000 (16:27 +0100)
haskell-lsp-test.cabal
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Server.hs
stack.yaml
test/Test.hs

index 9fb63a305ecb7e48d7bfdcf5297998cd045c50ba..810a1131bfd24a7e527bf1c7e6659b374c0c38db 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
@@ -56,9 +56,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 047e35b0ac715d765eeb4f1c02f11a63b015426e..7f13a59e111a4e93e63d60198b165a43388bd1db 100644 (file)
@@ -16,6 +16,7 @@ module Language.Haskell.LSP.Test
   -- * Sessions
     runSession
   , runSessionWithHandles
+  , runSessionWithCapabilities
   , Session
   -- * Sending
   , sendRequest
@@ -76,6 +77,7 @@ import qualified Data.HashMap.Strict as HashMap
 import Data.List
 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.Messages
 import Language.Haskell.LSP.VFS
 import Language.Haskell.LSP.Test.Compat
@@ -92,7 +94,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
 
@@ -100,7 +110,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 8f715333092c46b503316b77b0163d8596b9fa18..0bffa5e1a7c3f7a23d40205887b9216441bf5454 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