diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-05-16 12:32:49 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-05-16 12:32:49 +0000 |
commit | c22d344743aabeb9b971027386c10f273c7155c2 (patch) | |
tree | 708eb3ab6f1d2a7c7f5226006bf0c9e70adfef02 /clang-tools-extra | |
parent | 43714504a81f1b588622f03186b3564d7a71cdf6 (diff) | |
download | bcm5719-llvm-c22d344743aabeb9b971027386c10f273c7155c2.tar.gz bcm5719-llvm-c22d344743aabeb9b971027386c10f273c7155c2.zip |
[clangd] Parse all comments in Sema and completion.
Summary:
And add tests for the comment extraction code.
clangd will now show non-doxygen comments in completion for results
coming from Sema and Dynamic index.
Static index does not include the comments yet, I will enable it in
a separate commit after investigating which implications it has for
the size of the index.
Reviewers: sammccall, hokein, ioeric
Reviewed By: sammccall
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46002
llvm-svn: 332460
Diffstat (limited to 'clang-tools-extra')
-rw-r--r-- | clang-tools-extra/clangd/ClangdUnit.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/clangd/CodeComplete.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp | 24 |
3 files changed, 28 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index ab87463774c..eb2fc184ccf 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -25,6 +25,7 @@ #include "clang/Sema/Sema.h" #include "clang/Serialization/ASTWriter.h" #include "clang/Tooling/CompilationDatabase.h" +#include "clang/Basic/LangOptions.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/CrashRecoveryContext.h" @@ -316,6 +317,7 @@ llvm::Optional<std::vector<Diag>> CppFile::rebuild(ParseInputs &&Inputs) { } // createInvocationFromCommandLine sets DisableFree. CI->getFrontendOpts().DisableFree = false; + CI->getLangOpts()->CommentOpts.ParseAllComments = true; } std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer = diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 1581914257a..afac7ebca90 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -25,6 +25,7 @@ #include "Trace.h" #include "URI.h" #include "index/Index.h" +#include "clang/Basic/LangOptions.h" #include "clang/Format/Format.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" @@ -648,6 +649,7 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer, return false; } CI->getFrontendOpts().DisableFree = false; + CI->getLangOpts()->CommentOpts.ParseAllComments = true; std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer = llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName); diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp index c11bbf3c88c..a142891ee3c 100644 --- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp +++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp @@ -628,6 +628,30 @@ TEST(CompletionTest, DynamicIndexMultiFile) { Doc("Doooc"), Detail("void")))); } +TEST(CompletionTest, Documentation) { + auto Results = completions( + R"cpp( + // Non-doxygen comment. + int foo(); + /// Doxygen comment. + /// \param int a + int bar(int a); + /* Multi-line + block comment + */ + int baz(); + + int x = ^ + )cpp"); + EXPECT_THAT(Results.items, + Contains(AllOf(Named("foo"), Doc("Non-doxygen comment.")))); + EXPECT_THAT( + Results.items, + Contains(AllOf(Named("bar"), Doc("Doxygen comment.\n\\param int a")))); + EXPECT_THAT(Results.items, + Contains(AllOf(Named("baz"), Doc("Multi-line\nblock comment")))); +} + TEST(CodeCompleteTest, DisableTypoCorrection) { auto Results = completions(R"cpp( namespace clang { int v; } |