Skip to content

Commit 6fbe066

Browse files
authored
lsp-test: export runSessionWithConfig' to allow modifying the CreateProcess (#449)
* Export runSessionWithConfig' to allow modifying the CreateProcess * More meaningful name for runSessionWithConfig' * Fix up haddocks * Remove stray whitespace
1 parent b0f8596 commit 6fbe066

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lsp-test/src/Language/LSP/Test.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Language.LSP.Test
2525
Session
2626
, runSession
2727
, runSessionWithConfig
28+
, runSessionWithConfigCustomProcess
2829
, runSessionWithHandles
2930
, runSessionWithHandles'
3031
-- ** Config
@@ -133,7 +134,7 @@ import System.Environment
133134
import System.IO
134135
import System.Directory
135136
import System.FilePath
136-
import System.Process (ProcessHandle)
137+
import System.Process (ProcessHandle, CreateProcess)
137138
import qualified System.FilePath.Glob as Glob
138139
import Control.Monad.State (execState)
139140

@@ -159,9 +160,19 @@ runSessionWithConfig :: SessionConfig -- ^ Configuration options for the session
159160
-> FilePath -- ^ The filepath to the root directory for the session.
160161
-> Session a -- ^ The session to run.
161162
-> IO a
162-
runSessionWithConfig config' serverExe caps rootDir session = do
163+
runSessionWithConfig = runSessionWithConfigCustomProcess id
164+
165+
-- | Starts a new session with a custom configuration and server 'CreateProcess'.
166+
runSessionWithConfigCustomProcess :: (CreateProcess -> CreateProcess) -- ^ Tweak the 'CreateProcess' used to start the server.
167+
-> SessionConfig -- ^ Configuration options for the session.
168+
-> String -- ^ The command to run the server.
169+
-> C.ClientCapabilities -- ^ The capabilities that the client should declare.
170+
-> FilePath -- ^ The filepath to the root directory for the session.
171+
-> Session a -- ^ The session to run.
172+
-> IO a
173+
runSessionWithConfigCustomProcess modifyCreateProcess config' serverExe caps rootDir session = do
163174
config <- envOverrideConfig config'
164-
withServer serverExe (logStdErr config) $ \serverIn serverOut serverProc ->
175+
withServer serverExe (logStdErr config) modifyCreateProcess $ \serverIn serverOut serverProc ->
165176
runSessionWithHandles' (Just serverProc) serverIn serverOut config caps rootDir session
166177

167178
-- | Starts a new session, using the specified handles to communicate with the
@@ -770,7 +781,7 @@ getSemanticTokens :: TextDocumentIdentifier -> Session (Maybe SemanticTokens)
770781
getSemanticTokens doc = do
771782
let params = SemanticTokensParams Nothing Nothing doc
772783
rsp <- request STextDocumentSemanticTokensFull params
773-
pure $ getResponseResult rsp
784+
pure $ getResponseResult rsp
774785

775786
-- | Returns a list of capabilities that the server has requested to /dynamically/
776787
-- register during the 'Session'.

lsp-test/src/Language/LSP/Test/Replay.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ replaySession serverExe sessionDir = do
4444
-- decode session
4545
let unswappedEvents = map (fromJust . decode) entries
4646
47-
withServer serverExe False $ \serverIn serverOut serverProc -> do
47+
withServer serverExe False id $ \serverIn serverOut serverProc -> do
4848
4949
pid <- getProcessID serverProc
5050
events <- swapCommands pid <$> swapFiles sessionDir unswappedEvents

lsp-test/src/Language/LSP/Test/Server.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import Language.LSP.Test.Compat
66
import System.IO
77
import System.Process hiding (withCreateProcess)
88

9-
withServer :: String -> Bool -> (Handle -> Handle -> ProcessHandle -> IO a) -> IO a
10-
withServer serverExe logStdErr f = do
9+
withServer :: String -> Bool -> (CreateProcess -> CreateProcess) -> (Handle -> Handle -> ProcessHandle -> IO a) -> IO a
10+
withServer serverExe logStdErr modifyCreateProcess f = do
1111
-- TODO Probably should just change runServer to accept
1212
-- separate command and arguments
1313
let cmd:args = words serverExe
1414
createProc = (proc cmd args) { std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
15-
withCreateProcess createProc $ \(Just serverIn) (Just serverOut) (Just serverErr) serverProc -> do
15+
withCreateProcess (modifyCreateProcess createProc) $ \(Just serverIn) (Just serverOut) (Just serverErr) serverProc -> do
1616
-- Need to continuously consume to stderr else it gets blocked
1717
-- Can't pass NoStream either to std_err
1818
hSetBuffering serverErr NoBuffering

0 commit comments

Comments
 (0)