[clangd] Use identifiers in file as completion candidates when build is not ready.
Summary:
o Lex the code to get the identifiers and put them into a "symbol" index.
o Adds a new completion mode without compilation/sema into code completion workflow.
o Make IncludeInserter work even when no compile command is present, by avoiding
inserting non-verbatim headers.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60126
llvm-svn: 358159
diff --git a/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp b/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp
index e38eaa3..965deef 100644
--- a/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp
+++ b/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp
@@ -9,6 +9,7 @@
#include "Context.h"
#include "Protocol.h"
#include "SourceCode.h"
+#include "clang/Format/Format.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Testing/Support/Error.h"
@@ -304,6 +305,23 @@
}
}
+TEST(SourceCodeTests, CollectIdentifiers) {
+ auto Style = format::getLLVMStyle();
+ auto IDs = collectIdentifiers(R"cpp(
+ #include "a.h"
+ void foo() { int xyz; int abc = xyz; return foo(); }
+ )cpp",
+ Style);
+ EXPECT_EQ(IDs.size(), 7u);
+ EXPECT_EQ(IDs["include"], 1u);
+ EXPECT_EQ(IDs["void"], 1u);
+ EXPECT_EQ(IDs["int"], 2u);
+ EXPECT_EQ(IDs["xyz"], 2u);
+ EXPECT_EQ(IDs["abc"], 1u);
+ EXPECT_EQ(IDs["return"], 1u);
+ EXPECT_EQ(IDs["foo"], 2u);
+}
+
} // namespace
} // namespace clangd
} // namespace clang