Skip to content

Commit fc3b353

Browse files
committed
Fix getTypeDefinitions
1 parent 198816c commit fc3b353

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

lsp-test/src/Language/Haskell/LSP/Test.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,19 @@ getDefinitions doc pos = do
604604
let params = TextDocumentPositionParams doc pos Nothing
605605
rsp <- request TextDocumentDefinition params :: Session DefinitionResponse
606606
case getResponseResult rsp of
607-
SingleLoc loc -> pure [loc]
608-
MultiLoc locs -> pure locs
607+
SingleLoc loc -> pure [loc]
608+
MultiLoc locs -> pure locs
609609

610610
-- | Returns the type definition(s) for the term at the specified position.
611611
getTypeDefinitions :: TextDocumentIdentifier -- ^ The document the term is in.
612-
-> Position -- ^ The position the term is at.
613-
-> Session [Location] -- ^ The location(s) of the definitions
614-
getTypeDefinitions doc pos =
612+
-> Position -- ^ The position the term is at.
613+
-> Session [Location] -- ^ The location(s) of the definitions
614+
getTypeDefinitions doc pos = do
615615
let params = TextDocumentPositionParams doc pos Nothing
616-
in getResponseResult <$> request TextDocumentTypeDefinition params
616+
rsp <- request TextDocumentTypeDefinition params :: Session TypeDefinitionResponse
617+
case getResponseResult rsp of
618+
SingleLoc loc -> pure [loc]
619+
MultiLoc locs -> pure locs
617620

618621
-- | Renames the term at the specified position.
619622
rename :: TextDocumentIdentifier -> Position -> String -> Session ()
@@ -676,4 +679,4 @@ getCodeLenses tId = do
676679
--
677680
-- @since 0.11.0.0
678681
getRegisteredCapabilities :: Session [Registration]
679-
getRegisteredCapabilities = (Map.elems . curDynCaps) <$> get
682+
getRegisteredCapabilities = (Map.elems . curDynCaps) <$> get

lsp-test/test/Test.hs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,13 @@ main = findServer >>= \serverExe -> hspec $ do
221221
contents <- documentContents doc
222222
liftIO $ contents `shouldSatisfy` T.isPrefixOf "foodule"
223223

224-
-- describe "getCompletions" $
225-
-- it "works" $ runSession serverExe def "test/data/renamePass" $ do
226-
-- doc <- openDoc "Desktop/simple.hs" "haskell"
227-
228-
-- -- wait for module to be loaded
229-
-- skipMany loggingNotification
230-
-- noDiagnostics
231-
-- noDiagnostics
224+
describe "getCompletions" $
225+
it "works" $ runSession serverExe def "test/data/renamePass" $ do
226+
doc <- openDoc "Desktop/simple.hs" "haskell"
232227

233-
-- comps <- getCompletions doc (Position 5 5)
234-
-- let item = head (filter (\x -> x ^. label == "interactWithUser") comps)
235-
-- liftIO $ do
236-
-- item ^. label `shouldBe` "interactWithUser"
237-
-- item ^. kind `shouldBe` Just CiFunction
238-
-- item ^. detail `shouldBe` Just "Items -> IO ()\nMain"
228+
comps <- getCompletions doc (Position 5 5)
229+
let item = head comps
230+
liftIO $ item ^. label `shouldBe` "foo"
239231

240232
-- describe "getReferences" $
241233
-- it "works" $ runSession serverExe fullCaps "test/data/renamePass" $ do
@@ -413,4 +405,4 @@ findServer = do
413405
let serverName = "dummy-server"
414406
e <- findExecutable serverName
415407
e' <- findExeRecursive serverName "dist-newstyle"
416-
pure $ fromJust $ e <|> e'
408+
pure $ fromJust $ e <|> e'

lsp-test/test/dummy-server/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ handlers lfvar = def
109109
send $ RspCodeAction $ makeResponseMessage req caresults
110110
, didChangeWatchedFilesNotificationHandler = pure $ \_ ->
111111
send $ NotLogMessage $ fmServerLogMessageNotification MtLog "got workspace/didChangeWatchedFiles"
112+
, completionHandler = pure $ \req -> do
113+
let res = CompletionList (CompletionListType False (List [item]))
114+
item =
115+
CompletionItem "foo" (Just CiConstant) (List []) Nothing
116+
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
117+
Nothing Nothing Nothing Nothing Nothing
118+
send $ RspCompletion $ makeResponseMessage req res
112119
}
113120
where send msg = readMVar lfvar >>= \lf -> (sendFunc lf) msg
114121

115-
mkRange sl sc el ec = Range (Position sl sc) (Position el ec)
122+
mkRange sl sc el ec = Range (Position sl sc) (Position el ec)

0 commit comments

Comments
 (0)