X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FLSP%2FTest.hs;h=6c5c4a6674681b0a077352f9274864737eb1bad5;hb=a3f3199c221524124aeabce9a91e73655800a862;hp=89abfcf8b7a0c275c2903e9de9c9833c88b61bdf;hpb=cd644f52c5c564403b5f3b0a8652e7f4154f8d6a;p=lsp-test.git diff --git a/src/Language/LSP/Test.hs b/src/Language/LSP/Test.hs index 89abfcf..6c5c4a6 100644 --- a/src/Language/LSP/Test.hs +++ b/src/Language/LSP/Test.hs @@ -62,6 +62,7 @@ module Language.LSP.Test , waitForDiagnosticsSource , noDiagnostics , getCurrentDiagnostics + , getIncompleteProgressSessions -- ** Commands , executeCommand -- ** Code Actions @@ -101,6 +102,7 @@ import Control.Monad.IO.Class import Control.Exception import Control.Lens hiding ((.=), List, Empty) import qualified Data.Map.Strict as Map +import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.IO as T import Data.Aeson @@ -369,7 +371,7 @@ sendResponse = sendMessage -- The initialize requests and responses are not included the session, -- so if you need to test it use this. initializeResponse :: Session (ResponseMessage Initialize) -initializeResponse = initRsp <$> ask >>= (liftIO . readMVar) +initializeResponse = ask >>= (liftIO . readMVar) . initRsp -- | /Creates/ a new text document. This is different from 'openDoc' -- as it sends a workspace/didChangeWatchedFiles notification letting the server @@ -381,7 +383,7 @@ initializeResponse = initRsp <$> ask >>= (liftIO . readMVar) -- -- @since 11.0.0.0 createDoc :: FilePath -- ^ The path to the document to open, __relative to the root directory__. - -> String -- ^ The text document's language identifier, e.g. @"haskell"@. + -> T.Text -- ^ The text document's language identifier, e.g. @"haskell"@. -> T.Text -- ^ The content of the text document to create. -> Session TextDocumentIdentifier -- ^ The identifier of the document just created. createDoc file languageId contents = do @@ -396,7 +398,7 @@ createDoc file languageId contents = do watchHits :: FileSystemWatcher -> Bool watchHits (FileSystemWatcher pattern kind) = -- If WatchKind is exlcuded, defaults to all true as per spec - fileMatches pattern && createHits (fromMaybe (WatchKind True True True) kind) + fileMatches (T.unpack pattern) && createHits (fromMaybe (WatchKind True True True) kind) fileMatches pattern = Glob.match (Glob.compile pattern) relOrAbs -- If the pattern is absolute then match against the absolute fp @@ -421,7 +423,7 @@ createDoc file languageId contents = do -- | Opens a text document that /exists on disk/, and sends a -- textDocument/didOpen notification to the server. -openDoc :: FilePath -> String -> Session TextDocumentIdentifier +openDoc :: FilePath -> T.Text -> Session TextDocumentIdentifier openDoc file languageId = do context <- ask let fp = rootDir context file @@ -430,12 +432,12 @@ openDoc file languageId = do -- | This is a variant of `openDoc` that takes the file content as an argument. -- Use this is the file exists /outside/ of the current workspace. -openDoc' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier +openDoc' :: FilePath -> T.Text -> T.Text -> Session TextDocumentIdentifier openDoc' file languageId contents = do context <- ask let fp = rootDir context file uri = filePathToUri fp - item = TextDocumentItem uri (T.pack languageId) 0 contents + item = TextDocumentItem uri languageId 0 contents sendNotification STextDocumentDidOpen (DidOpenTextDocumentParams item) pure $ TextDocumentIdentifier uri @@ -534,6 +536,10 @@ getCodeActionContext doc = do getCurrentDiagnostics :: TextDocumentIdentifier -> Session [Diagnostic] getCurrentDiagnostics doc = fromMaybe [] . Map.lookup (toNormalizedUri $ doc ^. uri) . curDiagnostics <$> get +-- | Returns the tokens of all progress sessions that have started but not yet ended. +getIncompleteProgressSessions :: Session (Set.Set ProgressToken) +getIncompleteProgressSessions = curProgressSessions <$> get + -- | Executes a command. executeCommand :: Command -> Session () executeCommand cmd = do @@ -718,4 +724,4 @@ getCodeLenses tId = do -- -- @since 0.11.0.0 getRegisteredCapabilities :: Session [SomeRegistration] -getRegisteredCapabilities = (Map.elems . curDynCaps) <$> get +getRegisteredCapabilities = Map.elems . curDynCaps <$> get