diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-05-16 12:32:44 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-05-16 12:32:44 +0000 |
commit | 43714504a81f1b588622f03186b3564d7a71cdf6 (patch) | |
tree | b5109bb4cfe159e896f6c8f5dbe939f1246e295e /clang-tools-extra/clangd/CodeCompletionStrings.cpp | |
parent | 1ff7c32fc91c607b690d4bb9cf42f406be8dde68 (diff) | |
download | bcm5719-llvm-43714504a81f1b588622f03186b3564d7a71cdf6.tar.gz bcm5719-llvm-43714504a81f1b588622f03186b3564d7a71cdf6.zip |
[clangd] Retrieve minimally formatted comment text in completion.
Summary:
Previous implementation used to extract brief text from doxygen comments.
Brief text parsing slows down completion and is not suited for
non-doxygen comments.
This commit switches to providing comments that mimic the ones
originally written in the source code, doing minimal reindenting and
removing the comments markers to make the output more user-friendly.
It means we lose support for doxygen-specific features, e.g. extracting
brief text, but provide useful results for non-doxygen comments.
Switching the doxygen support back is an option, but I suggest to see
whether the current approach gives more useful results.
Reviewers: sammccall, hokein, ioeric
Reviewed By: sammccall
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D45999
llvm-svn: 332459
Diffstat (limited to 'clang-tools-extra/clangd/CodeCompletionStrings.cpp')
-rw-r--r-- | clang-tools-extra/clangd/CodeCompletionStrings.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp index 8aa4f251992..cbdd14d1095 100644 --- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp +++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp @@ -8,6 +8,8 @@ //===---------------------------------------------------------------------===// #include "CodeCompletionStrings.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/RawCommentList.h" #include <utility> namespace clang { @@ -122,13 +124,43 @@ void processSnippetChunks(const CodeCompletionString &CCS, } // namespace +std::string getDocComment(const ASTContext &Ctx, + const CodeCompletionResult &Result) { + // FIXME: clang's completion also returns documentation for RK_Pattern if they + // contain a pattern for ObjC properties. Unfortunately, there is no API to + // get this declaration, so we don't show documentation in that case. + if (Result.Kind != CodeCompletionResult::RK_Declaration) + return ""; + auto Decl = Result.getDeclaration(); + if (!Decl) + return ""; + const RawComment *RC = getCompletionComment(Ctx, Decl); + if (!RC) + return ""; + return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); +} + +std::string +getParameterDocComment(const ASTContext &Ctx, + const CodeCompleteConsumer::OverloadCandidate &Result, + unsigned ArgIndex) { + auto Func = Result.getFunction(); + if (!Func) + return ""; + const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex); + if (!RC) + return ""; + return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); +} + void getLabelAndInsertText(const CodeCompletionString &CCS, std::string *Label, std::string *InsertText, bool EnableSnippets) { return EnableSnippets ? processSnippetChunks(CCS, Label, InsertText) : processPlainTextChunks(CCS, Label, InsertText); } -std::string getDocumentation(const CodeCompletionString &CCS) { +std::string formatDocumentation(const CodeCompletionString &CCS, + llvm::StringRef DocComment) { // Things like __attribute__((nonnull(1,3))) and [[noreturn]]. Present this // information in the documentation field. std::string Result; @@ -146,13 +178,13 @@ std::string getDocumentation(const CodeCompletionString &CCS) { } } // Add brief documentation (if there is any). - if (CCS.getBriefComment() != nullptr) { + if (!DocComment.empty()) { if (!Result.empty()) { // This means we previously added annotations. Add an extra newline // character to make the annotations stand out. Result.push_back('\n'); } - Result += CCS.getBriefComment(); + Result += DocComment; } return Result; } |