diff options
author | Kirill Bobyrev <omtcyfz@gmail.com> | 2018-07-11 14:49:49 +0000 |
---|---|---|
committer | Kirill Bobyrev <omtcyfz@gmail.com> | 2018-07-11 14:49:49 +0000 |
commit | 47d7f52dea9b33bde34c07672170b9f9617011d6 (patch) | |
tree | 95a1a9784f4b20360600914585179be37eb1974e /clang | |
parent | 09832e33b47b11d9ba12b686b04c02e7412e9e4f (diff) | |
download | bcm5719-llvm-47d7f52dea9b33bde34c07672170b9f9617011d6.tar.gz bcm5719-llvm-47d7f52dea9b33bde34c07672170b9f9617011d6.zip |
[clangd] Uprank delcarations when "using q::name" is present in the main file
Having `using qualified::name;` for some symbol is an important signal
for clangd code completion as the user is more likely to use such
symbol. This patch helps to uprank the relevant symbols by saving
UsingShadowDecl in the new field of CodeCompletionResult and checking
whether the corresponding UsingShadowDecl is located in the main file
later in ClangD code completion routine. While the relative importance
of such signal is a subject to change in the future, this patch simply
bumps DeclProximity score to the value of 1.0 which should be enough for
now.
The patch was tested using
`$ ninja check-clang check-clang-tools`
No unexpected failures were noticed after running the relevant testsets.
Reviewers: sammccall, ioeric
Subscribers: MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D49012
llvm-svn: 336810
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Sema/CodeCompleteConsumer.h | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 29 |
2 files changed, 24 insertions, 16 deletions
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h b/clang/include/clang/Sema/CodeCompleteConsumer.h index 8022fa74c4b..606f3b36901 100644 --- a/clang/include/clang/Sema/CodeCompleteConsumer.h +++ b/clang/include/clang/Sema/CodeCompleteConsumer.h @@ -45,8 +45,9 @@ class LangOptions; class NamedDecl; class NestedNameSpecifier; class Preprocessor; -class Sema; class RawComment; +class Sema; +class UsingShadowDecl; /// Default priority values for code-completion results based /// on their kind. @@ -836,6 +837,12 @@ public: /// informative rather than required. NestedNameSpecifier *Qualifier = nullptr; + /// If this Decl was unshadowed by using declaration, this can store a + /// pointer to the UsingShadowDecl which was used in the unshadowing process. + /// This information can be used to uprank CodeCompletionResults / which have + /// corresponding `using decl::qualified::name;` nearby. + const UsingShadowDecl *ShadowDecl = nullptr; + /// Build a result that refers to a declaration. CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, NestedNameSpecifier *Qualifier = nullptr, @@ -847,7 +854,7 @@ public: QualifierIsInformative(QualifierIsInformative), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(Qualifier) { - //FIXME: Add assert to check FixIts range requirements. + // FIXME: Add assert to check FixIts range requirements. computeCursorKindAndAvailability(Accessible); } diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 9beefc05a2c..700f5a2fee2 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -859,12 +859,12 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { } // Look through using declarations. - if (const UsingShadowDecl *Using = - dyn_cast<UsingShadowDecl>(R.Declaration)) { - MaybeAddResult(Result(Using->getTargetDecl(), - getBasePriority(Using->getTargetDecl()), - R.Qualifier), - CurContext); + if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) { + CodeCompletionResult Result(Using->getTargetDecl(), + getBasePriority(Using->getTargetDecl()), + R.Qualifier); + Result.ShadowDecl = Using; + MaybeAddResult(Result, CurContext); return; } @@ -977,10 +977,11 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, // Look through using declarations. if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) { - AddResult(Result(Using->getTargetDecl(), - getBasePriority(Using->getTargetDecl()), - R.Qualifier), - CurContext, Hiding); + CodeCompletionResult Result(Using->getTargetDecl(), + getBasePriority(Using->getTargetDecl()), + R.Qualifier); + Result.ShadowDecl = Using; + AddResult(Result, CurContext, Hiding); return; } @@ -1004,10 +1005,10 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, if (AsNestedNameSpecifier) { R.StartsNestedNameSpecifier = true; R.Priority = CCP_NestedNameSpecifier; - } - else if (Filter == &ResultBuilder::IsMember && !R.Qualifier && InBaseClass && - isa<CXXRecordDecl>(R.Declaration->getDeclContext() - ->getRedeclContext())) + } else if (Filter == &ResultBuilder::IsMember && !R.Qualifier && + InBaseClass && + isa<CXXRecordDecl>( + R.Declaration->getDeclContext()->getRedeclContext())) R.QualifierIsInformative = true; // If this result is supposed to have an informative qualifier, add one. |