@@ -566,6 +566,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
566566 {" declarationProvider" , true },
567567 {" definitionProvider" , true },
568568 {" documentHighlightProvider" , true },
569+ {" documentLinkProvider" ,
570+ llvm::json::Object{
571+ {" resolveProvider" , false },
572+ }},
569573 {" hoverProvider" , true },
570574 {" renameProvider" , std::move (RenameProvider)},
571575 {" selectionRangeProvider" , true },
@@ -1200,6 +1204,25 @@ void ClangdLSPServer::onSelectionRange(
12001204 });
12011205}
12021206
1207+ void ClangdLSPServer::onDocumentLink (
1208+ const DocumentLinkParams &Params,
1209+ Callback<std::vector<DocumentLink>> Reply) {
1210+
1211+ // TODO(forster): This currently resolves all targets eagerly. This is slow,
1212+ // because it blocks on the preamble/AST being built. We could respond to the
1213+ // request faster by using string matching or the lexer to find the includes
1214+ // and resolving the targets lazily.
1215+ Server->documentLinks (
1216+ Params.textDocument .uri .file (),
1217+ [Reply = std::move (Reply)](
1218+ llvm::Expected<std::vector<DocumentLink>> Links) mutable {
1219+ if (!Links) {
1220+ return Reply (Links.takeError ());
1221+ }
1222+ return Reply (std::move (Links));
1223+ });
1224+ }
1225+
12031226ClangdLSPServer::ClangdLSPServer (
12041227 class Transport &Transp, const FileSystemProvider &FSProvider,
12051228 const clangd::CodeCompleteOptions &CCOpts,
@@ -1243,6 +1266,7 @@ ClangdLSPServer::ClangdLSPServer(
12431266 MsgHandler->bind (" textDocument/typeHierarchy" , &ClangdLSPServer::onTypeHierarchy);
12441267 MsgHandler->bind (" typeHierarchy/resolve" , &ClangdLSPServer::onResolveTypeHierarchy);
12451268 MsgHandler->bind (" textDocument/selectionRange" , &ClangdLSPServer::onSelectionRange);
1269+ MsgHandler->bind (" textDocument/documentLink" , &ClangdLSPServer::onDocumentLink);
12461270 // clang-format on
12471271}
12481272
0 commit comments