withServer serverExe (logStdErr config) $ \serverIn serverOut serverProc ->
runSessionWithHandles' (Just serverProc) serverIn serverOut config caps rootDir session
-
+-- | Starts a new session, using the specified handles to communicate with the
+-- server. You can use this to host the server within the same process.
+-- An example with haskell-lsp might look like:
+--
+-- > (hinRead, hinWrite) <- createPipe
+-- > (houtRead, houtWrite) <- createPipe
+-- >
+-- > forkIO $ void $ runWithHandles hinRead houtWrite initCallbacks handlers def
+-- > Test.runSessionWithHandles hinWrite houtRead defaultConfig fullCaps "." $ do
+-- > -- ...
runSessionWithHandles :: Handle -- ^ The input handle
-> Handle -- ^ The output handle
-> SessionConfig
Nothing
caps
(Just TraceOff)
- Nothing
+ (List <$> initialWorkspaceFolders config)
runSession' serverIn serverOut serverProc listenServer config caps rootDir exitServer $ do
-- Wrap the session around initialize and shutdown calls
-- initRspMsg <- sendRequest Initialize initializeParams :: Session InitializeResponse
where
-- | Asks the server to shutdown and exit politely
exitServer :: Session ()
- exitServer = request_ SShutdown (Nothing :: Maybe Value) >> sendNotification SExit Empty
+ exitServer = request_ SShutdown Empty >> sendNotification SExit Empty
-- | Listens to the server output until the shutdown ack,
-- makes sure it matches the record and signals any semaphores
getDocumentSymbols doc = do
ResponseMessage _ rspLid res <- request STextDocumentDocumentSymbol (DocumentSymbolParams Nothing Nothing doc) :: Session DocumentSymbolsResponse
case res of
- Right (L (List xs)) -> return (Left xs)
- Right (R (List xs)) -> return (Right xs)
+ Right (InL (List xs)) -> return (Left xs)
+ Right (InR (List xs)) -> return (Right xs)
Left err -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) err)
-- | Returns the code actions in the specified range.
rsp <- request STextDocumentCompletion (CompletionParams doc pos Nothing Nothing Nothing)
case getResponseResult rsp of
- L (List items) -> return items
- R (CompletionList _ (List items)) -> return items
+ InL (List items) -> return items
+ InR (CompletionList _ (List items)) -> return items
-- | Returns the references for the position in the document.
getReferences :: TextDocumentIdentifier -- ^ The document to lookup in.
let params = paramCons doc pos Nothing Nothing
rsp <- request method params
case getResponseResult rsp of
- L loc -> pure (L [loc])
- R (L (List locs)) -> pure (L locs)
- R (R (List locLinks)) -> pure (R locLinks)
+ InL loc -> pure (InL [loc])
+ InR (InL (List locs)) -> pure (InL locs)
+ InR (InR (List locLinks)) -> pure (InR locLinks)
-- | Renames the term at the specified position.
rename :: TextDocumentIdentifier -> Position -> String -> Session ()
updateState (FromServerMess SWorkspaceApplyEdit req)
-- | Returns the hover information at the specified position.
-getHover :: TextDocumentIdentifier -> Position -> Session Hover
+getHover :: TextDocumentIdentifier -> Position -> Session (Maybe Hover)
getHover doc pos =
let params = HoverParams doc pos Nothing
in getResponseResult <$> request STextDocumentHover params