Add getHighlights
authorLuke Lau <luke_lau@icloud.com>
Tue, 17 Jul 2018 12:35:54 +0000 (13:35 +0100)
committerLuke Lau <luke_lau@icloud.com>
Tue, 17 Jul 2018 12:35:54 +0000 (13:35 +0100)
src/Language/Haskell/LSP/Test.hs
test/Test.hs

index 403c0e112600acda919a77656434e8a792f089d8..e47109e03da0f1e83c84466423ad2fd2cd2262aa 100644 (file)
@@ -71,6 +71,8 @@ module Language.Haskell.LSP.Test
   , rename
   -- ** Hover
   , getHover
+  -- ** Highlights
+  , getHighlights
   -- ** Edits
   , applyEdit
   ) where
@@ -463,9 +465,14 @@ rename doc pos newName = do
 
 -- ^ Returns the hover information at the specified position.
 getHover :: TextDocumentIdentifier -> Position -> Session (Maybe Hover)
-getHover doc pos = do
+getHover doc pos =
   let params = TextDocumentPositionParams doc pos
-  getResponseResult <$> sendRequest TextDocumentHover params
+  in getResponseResult <$> sendRequest TextDocumentHover params
+
+getHighlights :: TextDocumentIdentifier -> Position -> Session [DocumentHighlight]
+getHighlights doc pos =
+  let params = TextDocumentPositionParams doc pos
+  in getResponseResult <$> sendRequest TextDocumentDocumentHighlight params
 
 -- | Checks the response for errors and throws an exception if needed.
 -- Returns the result if successful.
index e34244041de3fbbdaf36d8973d479cffd0cf287f..a17be20f7f151f725e85c32b3031bb301692b81a 100644 (file)
@@ -267,6 +267,12 @@ main = hspec $ do
       skipManyTill loggingNotification $ count 2 noDiagnostics
       hover <- getHover doc (Position 45 9) -- putStrLn
       liftIO $ hover `shouldSatisfy` isJust
+  describe "getHighlights" $
+    it "works" $ runSession "hie --lsp" "test/data/renamePass" $ do
+      doc <- openDoc "Desktop/simple.hs" "haskell"
+      skipManyTill loggingNotification $ count 2 noDiagnostics
+      highlights <- getHighlights doc (Position 27 4) -- addItem
+      liftIO $ length highlights `shouldBe` 4
 
 mkRange sl sc el ec = Range (Position sl sc) (Position el ec)