-- * Sessions
runSession
, runSessionWithHandles
+ , runSessionWithCapabilities
, Session
-- * Sending
, sendRequest
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
-> 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
(Just $ T.pack absRootDir)
(Just $ filePathToUri absRootDir)
Nothing
- def
+ caps
(Just TraceOff)
withServer serverExe $ \serverIn serverOut _ -> runSessionWithHandles serverIn serverOut listenServer rootDir $ do
modify (\s -> s { vfs = newVFS })
sendNotification' n
+-- | Close a virtual file if we send a close text document notification
+sendNotification TextDocumentDidClose params = do
+ let params' = fromJust $ decode $ encode params
+ n :: DidCloseTextDocumentNotification
+ n = NotificationMessage "2.0" TextDocumentDidClose params'
+ oldVFS <- vfs <$> get
+ newVFS <- liftIO $ closeVFS oldVFS n
+ modify (\s -> s { vfs = newVFS })
+ sendNotification' n
+
sendNotification method params = sendNotification' (NotificationMessage "2.0" method params)
sendNotification' :: (ToJSON a, ToJSON b) => NotificationMessage a b -> Session ()