X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest.hs;h=592589c5abb0e39bc44f0fcbd958839b2261c2a8;hb=42757e7fe53223f3bdd81180a682faf72761afe3;hp=4b0226ca98588977c4456832fcb754d25c665953;hpb=06aef4efc7a5d9fd43b938cd45c7aa6a38bf2b77;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 4b0226c..592589c 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 @@ -171,6 +153,8 @@ runSessionWithConfig config serverExe rootDir session = do documentContents :: TextDocumentIdentifier -> Session T.Text documentContents doc = do vfs <- vfs <$> get + liftIO $ print vfs + liftIO $ print doc let file = vfs Map.! (doc ^. uri) return $ Rope.toText $ Language.Haskell.LSP.VFS._text file @@ -181,7 +165,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 +314,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 +378,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 +405,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