diff --git a/clang-tools-extra/clangd/FormattedString.h b/clang-tools-extra/clangd/FormattedString.h --- a/clang-tools-extra/clangd/FormattedString.h +++ b/clang-tools-extra/clangd/FormattedString.h @@ -35,6 +35,15 @@ virtual ~Block() = default; }; +class RawBlock : public Block { + public: + RawBlock(std::string Text) : Text(std::move(Text)) {} + virtual void renderMarkdown(llvm::raw_ostream &OS) const override { OS << Text; } + virtual void renderPlainText(llvm::raw_ostream &OS) const override { OS << Text; } + private: + std::string Text; +}; + /// Represents parts of the markup that can contain strings, like inline code, /// code block or plain text. /// One must introduce different paragraphs to create separate blocks. @@ -88,6 +97,9 @@ void addCodeBlock(std::string Code, std::string Language = "cpp"); BulletList &addBulletList(); + void addRaw(std::string Text) { + Children.push_back(std::make_unique(std::move(Text))); + } /// Doesn't contain any trailing newlines. std::string asMarkdown() const; diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h --- a/clang-tools-extra/clangd/Hover.h +++ b/clang-tools-extra/clangd/Hover.h @@ -71,6 +71,8 @@ /// Contains the evaluated value of the symbol if available. llvm::Optional Value; + llvm::Optional RawResponse; + /// Produce a user-readable information. markup::Document present() const; }; diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -439,6 +439,15 @@ // Look for a close enclosing expression to show the value of. if (!HI->Value) HI->Value = printExprValue(N, AST.getASTContext()); + } else if (auto *SL = N->ASTNode.get()) { + if (SL->getBeginLoc().isFileID()) { + const char *Data = SM.getCharacterData(SL->getBeginLoc()); + // safe because null-terminated + if (Data && !strncmp("R\"md(", Data, 5)) { + HI.emplace(); + HI->RawResponse = SL->getString(); + } + } } // FIXME: support hovers for other nodes? // - certain expressions (sizeof etc) @@ -463,6 +472,10 @@ markup::Document HoverInfo::present() const { markup::Document Output; + if (RawResponse) { + Output.addRaw(*RawResponse); + return Output; + } // Header contains a text of the form: // variable `var` : `int` //