From 5d58e92cc411d9f89f55737b6a225075e77f4f6b Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 20 Jun 2018 16:27:02 +0100 Subject: [PATCH] Add option to configure capabilities --- haskell-lsp-test.cabal | 4 +++- src/Language/Haskell/LSP/Test.hs | 14 ++++++++++++-- src/Language/Haskell/LSP/Test/Server.hs | 2 ++ stack.yaml | 3 ++- test/Test.hs | 8 ++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/haskell-lsp-test.cabal b/haskell-lsp-test.cabal index 9fb63a3..810a113 100644 --- a/haskell-lsp-test.cabal +++ b/haskell-lsp-test.cabal @@ -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 diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 047e35b..7f13a59 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -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 diff --git a/src/Language/Haskell/LSP/Test/Server.hs b/src/Language/Haskell/LSP/Test/Server.hs index 8159bef..473f2c7 100644 --- a/src/Language/Haskell/LSP/Test/Server.hs +++ b/src/Language/Haskell/LSP/Test/Server.hs @@ -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 diff --git a/stack.yaml b/stack.yaml index 76fa9bc..e77a024 100644 --- a/stack.yaml +++ b/stack.yaml @@ -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 diff --git a/test/Test.hs b/test/Test.hs index 8f71533..0bffa5e 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -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 -- 2.30.2