X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest.hs;h=3ba86905c2d48d6c015812421253fa7319f3a3e6;hb=c6e68648c1e3b586e1ee8b0dcda1485ff5ae28ba;hp=4b0226ca98588977c4456832fcb754d25c665953;hpb=06aef4efc7a5d9fd43b938cd45c7aa6a38bf2b77;p=opengl.git diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 4b0226c..3ba8690 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -39,25 +39,6 @@ module Language.Haskell.LSP.Test , loggingNotification , publishDiagnosticsNotification -- * Combinators - , choice - , option - , optional - , between - , some - , many - , sepBy - , sepBy1 - , sepEndBy1 - , sepEndBy - , endBy1 - , endBy - , count - , manyTill - , skipMany - , skipSome - , skipManyTill - , skipSomeTill - , (<|>) , satisfy -- * Utilities , initializeResponse @@ -77,11 +58,12 @@ module Language.Haskell.LSP.Test -- ** Code Actions , getAllCodeActions , executeCodeAction + -- ** Completions + , getCompletions -- ** Edits , applyEdit ) where -import Control.Applicative import Control.Applicative.Combinators import Control.Concurrent import Control.Monad @@ -181,7 +163,7 @@ getDocumentEdit doc = do req <- message :: Session ApplyWorkspaceEditRequest unless (checkDocumentChanges req || checkChanges req) $ - liftIO $ throw (IncorrectApplyEditRequestException (show req)) + liftIO $ throw (IncorrectApplyEditRequest (show req)) documentContents doc where @@ -330,7 +312,7 @@ waitForDiagnostics = do noDiagnostics :: Session () noDiagnostics = do diagsNot <- message :: Session PublishDiagnosticsNotification - when (diagsNot ^. params . LSP.diagnostics /= List []) $ liftIO $ throw UnexpectedDiagnosticsException + when (diagsNot ^. params . LSP.diagnostics /= List []) $ liftIO $ throw UnexpectedDiagnostics -- | Returns the symbols in a document. getDocumentSymbols :: TextDocumentIdentifier -> Session [SymbolInformation] @@ -394,8 +376,8 @@ getVersionedDoc (TextDocumentIdentifier uri) = do return (VersionedTextDocumentIdentifier uri ver) -- | Applys an edit to the document and returns the updated document version. -applyEdit :: TextEdit -> TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier -applyEdit edit doc = do +applyEdit :: TextDocumentIdentifier -> TextEdit -> Session VersionedTextDocumentIdentifier +applyEdit doc edit = do verDoc <- getVersionedDoc doc @@ -421,3 +403,14 @@ applyEdit edit doc = do -- version may have changed getVersionedDoc doc +-- | Returns the completions for the position in the document. +getCompletions :: TextDocumentIdentifier -> Position -> Session [CompletionItem] +getCompletions doc pos = do + rsp <- sendRequest TextDocumentCompletion (TextDocumentPositionParams doc pos) + + let exc = throw $ UnexpectedResponseError (rsp ^. LSP.id) + (fromJust $ rsp ^. LSP.error) + res = fromMaybe exc (rsp ^. result) + case res of + Completions (List items) -> return items + CompletionList (CompletionListType _ (List items)) -> return items