Fix getTypeDefinitions
authorLuke Lau <luke_lau@icloud.com>
Mon, 8 Jun 2020 17:08:09 +0000 (18:08 +0100)
committerLuke Lau <luke_lau@icloud.com>
Mon, 8 Jun 2020 17:08:09 +0000 (18:08 +0100)
src/Language/Haskell/LSP/Test.hs
test/Test.hs
test/dummy-server/Main.hs

index 81bdc8a8b465087baa960fbc6b1303e8497fcff7..200dbb84807856959a2dfe0bf92faa8947eb8958 100644 (file)
@@ -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 ()
index c4aae07303337e44dbfa89d89040edebc073b96a..7b911f4e585a92809b4f4488f3252770ea8fdb2b 100644 (file)
@@ -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
index aa73677eb061e8be697723286469b36692d20d1d..ab917e8fa50ff825b35b996f78fd94fb80ad96b6 100644 (file)
@@ -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