From d6417f5584aa7673fa0212029a96cc9cacb1aad5 Mon Sep 17 00:00:00 2001 From: Michael Forster Date: Thu, 12 Dec 2019 14:30:02 +0100 Subject: [clangd] Implement "textDocument/documentLink" protocol support Summary: This adds an implementation for the "textDocument/documentLink" LSP request. It returns links for all `#include` directives to the resolved target files. Fixes https://github.com/clangd/clangd/issues/217. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70872 --- clang-tools-extra/clangd/Protocol.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'clang-tools-extra/clangd/Protocol.h') diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index f110292b091..1ccfa587bf8 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -1250,6 +1250,39 @@ struct SelectionRange { }; llvm::json::Value toJSON(const SelectionRange &); +/// Parameters for the document link request. +struct DocumentLinkParams { + /// The document to provide document links for. + TextDocumentIdentifier textDocument; +}; +bool fromJSON(const llvm::json::Value &, DocumentLinkParams &); + +/// A range in a text document that links to an internal or external resource, +/// like another text document or a web site. +struct DocumentLink { + /// The range this link applies to. + Range range; + + /// The uri this link points to. If missing a resolve request is sent later. + URIForFile target; + + // TODO(forster): The following optional fields defined by the language + // server protocol are unsupported: + // + // data?: any - A data entry field that is preserved on a document link + // between a DocumentLinkRequest and a + // DocumentLinkResolveRequest. + + friend bool operator==(const DocumentLink &LHS, const DocumentLink &RHS) { + return LHS.range == RHS.range && LHS.target == RHS.target; + } + + friend bool operator!=(const DocumentLink &LHS, const DocumentLink &RHS) { + return !(LHS == RHS); + } +}; +llvm::json::Value toJSON(const DocumentLink &DocumentLink); + } // namespace clangd } // namespace clang -- cgit v1.2.3