[clang-tools-extra] 038f03c - [clangd] Force delayed-template-parsing off in code completion.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 1 02:09:24 PDT 2020
Author: Sam McCall
Date: 2020-04-01T11:09:15+02:00
New Revision: 038f03cb5ef5d44676cbde06560ed2668f4a7acc
URL: https://github.com/llvm/llvm-project/commit/038f03cb5ef5d44676cbde06560ed2668f4a7acc
DIFF: https://github.com/llvm/llvm-project/commit/038f03cb5ef5d44676cbde06560ed2668f4a7acc.diff
LOG: [clangd] Force delayed-template-parsing off in code completion.
Summary:
It prevents code completion entirely in affected method bodies.
The main reason it's turned on is for compatibility with headers, so we turn it
off for the main file only. This is allowed because it's a compatible langopt.
Fixes https://github.com/clangd/clangd/issues/302
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77176
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 344b90ecaa32..86ea5f26d397 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1072,6 +1072,10 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
FrontendOpts.SkipFunctionBodies = true;
// Disable typo correction in Sema.
CI->getLangOpts()->SpellChecking = false;
+ // Code completion won't trigger in delayed template bodies.
+ // This is on-by-default in windows to allow parsing SDK headers; we're only
+ // disabling it for the main-file (not preamble).
+ CI->getLangOpts()->DelayedTemplateParsing = false;
// Setup code completion.
FrontendOpts.CodeCompleteOpts = Options;
FrontendOpts.CodeCompletionAt.FileName = std::string(Input.FileName);
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 06dccfa93956..3cb18f6893e9 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -127,7 +127,6 @@ CodeCompleteResult completions(llvm::StringRef Text,
Annotations Test(Text);
auto TU = TestTU::withCode(Test.code());
// To make sure our tests for completiopns inside templates work on Windows.
- TU.ExtraArgs = {"-fno-delayed-template-parsing"};
TU.Filename = FilePath.str();
return completions(TU, Test.point(), std::move(IndexSymbols),
std::move(Opts));
@@ -2660,6 +2659,20 @@ TEST(CompletionTest, NoCrashWithIncompleteLambda) {
EXPECT_THAT(Signatures, Contains(Sig("x() -> auto")));
}
+TEST(CompletionTest, DelayedTemplateParsing) {
+ Annotations Test(R"cpp(
+ int xxx;
+ template <typename T> int foo() { return xx^; }
+ )cpp");
+ auto TU = TestTU::withCode(Test.code());
+ // Even though delayed-template-parsing is on, we will disable it to provide
+ // completion in templates.
+ TU.ExtraArgs.push_back("-fdelayed-template-parsing");
+
+ EXPECT_THAT(completions(TU, Test.point()).Completions,
+ Contains(Named("xxx")));
+}
+
TEST(CompletionTest, CompletionRange) {
const char *WithRange = "auto x = [[abc]]^";
auto Completions = completions(WithRange);
More information about the cfe-commits
mailing list