mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 11:39:35 +00:00
[clangd] Boost keyword completions.
Summary: These have few signals other than being keywords, so the boost is high. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48083 llvm-svn: 334711
This commit is contained in:
parent
cc7344aae3
commit
c3b5bad723
@ -59,6 +59,29 @@ static SymbolQualitySignals::SymbolCategory categorize(const NamedDecl &ND) {
|
||||
return Switch().Visit(&ND);
|
||||
}
|
||||
|
||||
static SymbolQualitySignals::SymbolCategory categorize(const CodeCompletionResult &R) {
|
||||
if (R.Declaration)
|
||||
return categorize(*R.Declaration);
|
||||
if (R.Kind == CodeCompletionResult::RK_Macro)
|
||||
return SymbolQualitySignals::Macro;
|
||||
// Everything else is a keyword or a pattern. Patterns are mostly keywords
|
||||
// too, except a few which we recognize by cursor kind.
|
||||
switch (R.CursorKind) {
|
||||
case CXCursor_CXXMethod:
|
||||
return SymbolQualitySignals::Function;
|
||||
case CXCursor_ModuleImportDecl:
|
||||
return SymbolQualitySignals::Namespace;
|
||||
case CXCursor_MacroDefinition:
|
||||
return SymbolQualitySignals::Macro;
|
||||
case CXCursor_TypeRef:
|
||||
return SymbolQualitySignals::Type;
|
||||
case CXCursor_MemberRef:
|
||||
return SymbolQualitySignals::Variable;
|
||||
default:
|
||||
return SymbolQualitySignals::Keyword;
|
||||
}
|
||||
}
|
||||
|
||||
static SymbolQualitySignals::SymbolCategory
|
||||
categorize(const index::SymbolInfo &D) {
|
||||
switch (D.Kind) {
|
||||
@ -103,10 +126,7 @@ void SymbolQualitySignals::merge(const CodeCompletionResult &SemaCCResult) {
|
||||
if (SemaCCResult.Availability == CXAvailability_Deprecated)
|
||||
Deprecated = true;
|
||||
|
||||
if (SemaCCResult.Declaration)
|
||||
Category = categorize(*SemaCCResult.Declaration);
|
||||
else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro)
|
||||
Category = Macro;
|
||||
Category = categorize(SemaCCResult);
|
||||
|
||||
if (SemaCCResult.Declaration) {
|
||||
if (auto *ID = SemaCCResult.Declaration->getIdentifier())
|
||||
@ -135,6 +155,9 @@ float SymbolQualitySignals::evaluate() const {
|
||||
Score *= 0.1f;
|
||||
|
||||
switch (Category) {
|
||||
case Keyword: // Usually relevant, but misses most signals.
|
||||
Score *= 10;
|
||||
break;
|
||||
case Type:
|
||||
case Function:
|
||||
case Variable:
|
||||
|
@ -50,12 +50,13 @@ struct SymbolQualitySignals {
|
||||
unsigned References = 0;
|
||||
|
||||
enum SymbolCategory {
|
||||
Unknown = 0,
|
||||
Variable,
|
||||
Macro,
|
||||
Type,
|
||||
Function,
|
||||
Namespace,
|
||||
Unknown,
|
||||
Keyword,
|
||||
} Category = Unknown;
|
||||
|
||||
void merge(const CodeCompletionResult &SemaCCResult);
|
||||
|
@ -58,6 +58,10 @@ TEST(QualityTests, SymbolQualitySignalExtraction) {
|
||||
EXPECT_FALSE(Quality.ReservedName);
|
||||
EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
|
||||
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
|
||||
|
||||
Quality = {};
|
||||
Quality.merge(CodeCompletionResult("if"));
|
||||
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Keyword);
|
||||
}
|
||||
|
||||
TEST(QualityTests, SymbolRelevanceSignalExtraction) {
|
||||
@ -125,10 +129,12 @@ TEST(QualityTests, SymbolQualitySignalsSanity) {
|
||||
EXPECT_GT(WithReferences.evaluate(), Default.evaluate());
|
||||
EXPECT_GT(ManyReferences.evaluate(), WithReferences.evaluate());
|
||||
|
||||
SymbolQualitySignals Variable, Macro;
|
||||
SymbolQualitySignals Keyword, Variable, Macro;
|
||||
Keyword.Category = SymbolQualitySignals::Keyword;
|
||||
Variable.Category = SymbolQualitySignals::Variable;
|
||||
Macro.Category = SymbolQualitySignals::Macro;
|
||||
EXPECT_GT(Variable.evaluate(), Default.evaluate());
|
||||
EXPECT_GT(Keyword.evaluate(), Variable.evaluate());
|
||||
EXPECT_LT(Macro.evaluate(), Default.evaluate());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user