diff options
author | Eric Liu <ioeric@google.com> | 2018-11-30 11:12:40 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-11-30 11:12:40 +0000 |
commit | b1317fa8dfc0792a4ff9eae334556db89d92cd40 (patch) | |
tree | 27ef40e16edba0b3cfe6da1f9edaecd14f36e4b9 /clang-tools-extra/clangd/CodeComplete.cpp | |
parent | 471d0864dfa9b4f9de813c2d7492d40a52768cc9 (diff) | |
download | bcm5719-llvm-b1317fa8dfc0792a4ff9eae334556db89d92cd40.tar.gz bcm5719-llvm-b1317fa8dfc0792a4ff9eae334556db89d92cd40.zip |
[clangd] Drop injected class name when class scope is not explicitly specified.
Summary: E.g. allow injected "A::A" in `using A::A^` but not in "A^".
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D55065
llvm-svn: 347982
Diffstat (limited to 'clang-tools-extra/clangd/CodeComplete.cpp')
-rw-r--r-- | clang-tools-extra/clangd/CodeComplete.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 28cc5837cef..218e385d0ec 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -656,6 +656,13 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) { llvm_unreachable("unknown code completion context"); } +static bool isInjectedClass(const NamedDecl &D) { + if (auto *R = dyn_cast_or_null<RecordDecl>(&D)) + if (R->isInjectedClassName()) + return true; + return false; +} + // Some member calls are blacklisted because they're so rarely useful. static bool isBlacklistedMember(const NamedDecl &D) { // Destructor completion is rarely useful, and works inconsistently. @@ -663,9 +670,8 @@ static bool isBlacklistedMember(const NamedDecl &D) { if (D.getKind() == Decl::CXXDestructor) return true; // Injected name may be useful for A::foo(), but who writes A::A::foo()? - if (auto *R = dyn_cast_or_null<RecordDecl>(&D)) - if (R->isInjectedClassName()) - return true; + if (isInjectedClass(D)) + return true; // Explicit calls to operators are also rare. auto NameKind = D.getDeclName().getNameKind(); if (NameKind == DeclarationName::CXXOperatorName || @@ -744,6 +750,11 @@ struct CompletionRecorder : public CodeCompleteConsumer { !Context.getBaseType().isNull() // is this a member-access context? && isBlacklistedMember(*Result.Declaration)) continue; + // Skip injected class name when no class scope is not explicitly set. + // E.g. show injected A::A in `using A::A^` but not in "A^". + if (Result.Declaration && !Context.getCXXScopeSpecifier().hasValue() && + isInjectedClass(*Result.Declaration)) + continue; // We choose to never append '::' to completion results in clangd. Result.StartsNestedNameSpecifier = false; Results.push_back(Result); |