Skip to content

Commit 8a75141

Browse files
committed
feat: add getDocumentLinks for lsp-test
1 parent be5a5ff commit 8a75141

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ module Language.LSP.Test (
145145
getWorkspaceSymbols,
146146
resolveWorkspaceSymbols,
147147

148+
-- ** Document Links
149+
getDocumentLinks,
150+
148151
-- ** Capabilities
149152
getRegisteredCapabilities,
150153
) where
@@ -1063,6 +1066,11 @@ resolveWorkspaceSymbols item = do
10631066
rsp <- request SMethod_WorkspaceSymbolResolve item
10641067
pure $ getResponseResult rsp
10651068

1069+
getDocumentLinks :: TextDocumentIdentifier -> Session (Maybe [DocumentLink])
1070+
getDocumentLinks doc =
1071+
let params = DocumentLinkParams Nothing Nothing doc
1072+
in nullToMaybe . getResponseResult <$> request SMethod_TextDocumentDocumentLink params
1073+
10661074
{- | Returns a list of capabilities that the server has requested to /dynamically/
10671075
register during the 'Session'.
10681076

lsp-test/test/DummyServer.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,14 @@ handlers =
284284
Success start = fromJSON data_
285285
ih = InlayHint{_data_ = Nothing, _tooltip = Just $ InL $ "start at " <> T.pack (show start), ..}
286286
resp $ Right ih
287+
, requestHandler SMethod_TextDocumentDocumentLink $ \_req resp -> do
288+
resp $
289+
Right $
290+
InL
291+
[ DocumentLink
292+
(mkRange 0 0 0 5)
293+
(Just (Uri "file://..."))
294+
Nothing
295+
Nothing
296+
]
287297
]

lsp-test/test/Test.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,9 @@ main = hspec $ around withDummyServer $ do
470470
doc <- openDoc "test/data/renamePass/Desktop/simple.hs" "haskell"
471471
inlayHints <- getAndResolveInlayHints doc (Range (Position 1 2) (Position 3 4))
472472
liftIO $ head inlayHints ^. L.tooltip `shouldBe` Just (InL $ "start at " <> T.pack (show (Position 1 2)))
473+
474+
describe "getDocumentLinks" $
475+
it "works" $ \(hin, hout) -> runSessionWithHandles hin hout def fullLatestClientCaps "." $ do
476+
let doc = TextDocumentIdentifier (Uri "")
477+
documentLinks <- getDocumentLinks doc
478+
liftIO $ documentLinks `shouldSatisfy` isJust

0 commit comments

Comments
 (0)