X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest.hs;h=3331c096a7a71e9a84e6cd76348f04faff6aad36;hb=502c8dc3ff63383487536922176330a3f459a462;hp=b2d731e675cd897de03008106bbcb316bf5253bc;hpb=2ed0dbaf1233ec79ed0801b406ae9fbf4e36e8a4;p=opengl.git diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index b2d731e..3331c09 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -16,7 +16,12 @@ module Language.Haskell.LSP.Test -- * Sessions runSession , runSessionWithHandles + , runSessionWithConfig , Session + , SessionConfig(..) + , MonadSessionConfig(..) + , SessionException(..) + , anySessionException -- * Sending , sendRequest , sendNotification @@ -73,11 +78,12 @@ import qualified Data.ByteString.Lazy.Char8 as B import Data.Default import qualified Data.Map as Map import Data.Maybe -import Language.Haskell.LSP.Types -import qualified Language.Haskell.LSP.Types as LSP (error, id) +import Language.Haskell.LSP.Types hiding (id, capabilities) +import qualified Language.Haskell.LSP.Types as LSP import Language.Haskell.LSP.VFS import Language.Haskell.LSP.Test.Compat import Language.Haskell.LSP.Test.Decoding +import Language.Haskell.LSP.Test.Exceptions import Language.Haskell.LSP.Test.Parsing import Language.Haskell.LSP.Test.Session import Language.Haskell.LSP.Test.Server @@ -91,18 +97,27 @@ 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 - pid <- getProcessID +runSession = runSessionWithConfig def + +-- | Starts a new sesion with a client with the specified capabilities. +runSessionWithConfig :: SessionConfig -- ^ 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 +runSessionWithConfig config serverExe rootDir session = do + pid <- getCurrentProcessID absRootDir <- canonicalizePath rootDir let initializeParams = InitializeParams (Just pid) (Just $ T.pack absRootDir) (Just $ filePathToUri absRootDir) Nothing - def + (capabilities config) (Just TraceOff) - withServer serverExe $ \serverIn serverOut _ -> runSessionWithHandles serverIn serverOut listenServer rootDir $ do + withServer serverExe $ \serverIn serverOut _ -> + runSessionWithHandles serverIn serverOut listenServer config rootDir $ do -- Wrap the session around initialize and shutdown calls sendRequest Initialize initializeParams @@ -209,6 +224,16 @@ sendNotification TextDocumentDidOpen params = 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 ()