[clang-tools-extra] r332460 - [clangd] Parse all comments in Sema and completion.
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Wed May 16 05:32:50 PDT 2018
Author: ibiryukov
Date: Wed May 16 05:32:49 2018
New Revision: 332460
URL: http://llvm.org/viewvc/llvm-project?rev=332460&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=332460&r1=332459&r2=332460&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Wed May 16 05:32:49 2018
@@ -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>> CppFil
}
// createInvocationFromCommandLine sets DisableFree.
CI->getFrontendOpts().DisableFree = false;
+ CI->getLangOpts()->CommentOpts.ParseAllComments = true;
}
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332460&r1=332459&r2=332460&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 16 05:32:49 2018
@@ -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<Co
return false;
}
CI->getFrontendOpts().DisableFree = false;
+ CI->getLangOpts()->CommentOpts.ParseAllComments = true;
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName);
Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=332460&r1=332459&r2=332460&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed May 16 05:32:49 2018
@@ -628,6 +628,30 @@ TEST(CompletionTest, DynamicIndexMultiFi
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; }
More information about the cfe-commits
mailing list