X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest.hs;h=3def44000291d1e495cdc3924be80da94a4762b8;hb=f940434fbd873e90124a46bd1386c59e8cee49f7;hp=592589c5abb0e39bc44f0fcbd958839b2261c2a8;hpb=42757e7fe53223f3bdd81180a682faf72761afe3;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 592589c..3def440 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -52,6 +52,7 @@ module Language.Haskell.LSP.Test , getDocumentSymbols -- ** Diagnostics , waitForDiagnostics + , waitForDiagnosticsSource , noDiagnostics -- ** Commands , executeCommand @@ -60,6 +61,8 @@ module Language.Haskell.LSP.Test , executeCodeAction -- ** Completions , getCompletions + -- ** References + , getReferences -- ** Edits , applyEdit ) where @@ -153,8 +156,6 @@ 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 @@ -308,6 +309,17 @@ waitForDiagnostics = do let (List diags) = diagsNot ^. params . LSP.diagnostics return diags +waitForDiagnosticsSource :: String -> Session [Diagnostic] +waitForDiagnosticsSource src = do + diags <- waitForDiagnostics + let res = filter matches diags + if null res + then waitForDiagnosticsSource src + else return res + where + matches :: Diagnostic -> Bool + matches d = d ^. source == Just (T.pack src) + -- | Expects a 'PublishDiagnosticsNotification' and throws an -- 'UnexpectedDiagnosticsException' if there are any diagnostics -- returned. @@ -416,3 +428,9 @@ getCompletions doc pos = do case res of Completions (List items) -> return items CompletionList (CompletionListType _ (List items)) -> return items + +getReferences :: TextDocumentIdentifier -> Position -> Bool -> Session [Location] +getReferences doc pos inclDecl = + let ctx = ReferenceContext inclDecl + params = ReferenceParams doc pos ctx + in fromMaybe [] . (^. result) <$> sendRequest TextDocumentReferences params