From 72257c6a7b5461c529c415b93e1c3507e1c843a7 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 8 Jun 2020 18:08:09 +0100 Subject: [PATCH] Fix getTypeDefinitions --- src/Language/Haskell/LSP/Test.hs | 7 +++++-- test/Test.hs | 20 ++++++-------------- test/dummy-server/Main.hs | 7 +++++++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 81bdc8a..200dbb8 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -611,9 +611,12 @@ getDefinitions doc pos = do getTypeDefinitions :: TextDocumentIdentifier -- ^ The document the term is in. -> Position -- ^ The position the term is at. -> Session [Location] -- ^ The location(s) of the definitions -getTypeDefinitions doc pos = +getTypeDefinitions doc pos = do let params = TextDocumentPositionParams doc pos Nothing - in getResponseResult <$> request TextDocumentTypeDefinition params + rsp <- request TextDocumentTypeDefinition params :: Session TypeDefinitionResponse + case getResponseResult rsp of + SingleLoc loc -> pure [loc] + MultiLoc locs -> pure locs -- | Renames the term at the specified position. rename :: TextDocumentIdentifier -> Position -> String -> Session () diff --git a/test/Test.hs b/test/Test.hs index c4aae07..7b911f4 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -221,21 +221,13 @@ main = findServer >>= \serverExe -> hspec $ do contents <- documentContents doc liftIO $ contents `shouldSatisfy` T.isPrefixOf "foodule" - -- describe "getCompletions" $ - -- it "works" $ runSession serverExe def "test/data/renamePass" $ do - -- doc <- openDoc "Desktop/simple.hs" "haskell" - - -- -- wait for module to be loaded - -- skipMany loggingNotification - -- noDiagnostics - -- noDiagnostics + describe "getCompletions" $ + it "works" $ runSession serverExe def "test/data/renamePass" $ do + doc <- openDoc "Desktop/simple.hs" "haskell" - -- comps <- getCompletions doc (Position 5 5) - -- let item = head (filter (\x -> x ^. label == "interactWithUser") comps) - -- liftIO $ do - -- item ^. label `shouldBe` "interactWithUser" - -- item ^. kind `shouldBe` Just CiFunction - -- item ^. detail `shouldBe` Just "Items -> IO ()\nMain" + comps <- getCompletions doc (Position 5 5) + let item = head comps + liftIO $ item ^. label `shouldBe` "foo" -- describe "getReferences" $ -- it "works" $ runSession serverExe fullCaps "test/data/renamePass" $ do diff --git a/test/dummy-server/Main.hs b/test/dummy-server/Main.hs index aa73677..ab917e8 100644 --- a/test/dummy-server/Main.hs +++ b/test/dummy-server/Main.hs @@ -109,6 +109,13 @@ handlers lfvar = def send $ RspCodeAction $ makeResponseMessage req caresults , didChangeWatchedFilesNotificationHandler = pure $ \_ -> send $ NotLogMessage $ fmServerLogMessageNotification MtLog "got workspace/didChangeWatchedFiles" + , completionHandler = pure $ \req -> do + let res = CompletionList (CompletionListType False (List [item])) + item = + CompletionItem "foo" (Just CiConstant) (List []) Nothing + Nothing Nothing Nothing Nothing Nothing Nothing Nothing + Nothing Nothing Nothing Nothing Nothing + send $ RspCompletion $ makeResponseMessage req res } where send msg = readMVar lfvar >>= \lf -> (sendFunc lf) msg -- 2.30.2