When caching global completion results, keep track of the simplified
type class, so that we can adjust priorities appropriately when the
preferred type for the context and the actual type of the completion
are similar.
This gets us one step closer to parity of the cached completion
results with the non-cached completion results.
llvm-svn: 111139
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 8ac5b68..a573fb4 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -191,6 +191,10 @@
Ctx->getLangOptions());
CachedResult.Priority = Results[I].Priority;
CachedResult.Kind = Results[I].CursorKind;
+ CachedResult.TypeClass
+ = getSimplifiedTypeClass(
+ Ctx->getCanonicalType(getDeclUsageType(*Ctx,
+ Results[I].Declaration)));
CachedCompletionResults.push_back(CachedResult);
break;
}
@@ -215,6 +219,7 @@
| (1 << (CodeCompletionContext::CCC_ObjCMessageReceiver - 1));
CachedResult.Priority = Results[I].Priority;
CachedResult.Kind = Results[I].CursorKind;
+ CachedResult.TypeClass = STC_Void;
CachedCompletionResults.push_back(CachedResult);
break;
}
@@ -1417,7 +1422,24 @@
AddedResult = true;
}
- AllResults.push_back(Result(C->Completion, C->Priority, C->Kind));
+ // Adjust priority based on similar type classes.
+ unsigned Priority = C->Priority;
+ if (!Context.getPreferredType().isNull()) {
+ if (C->Kind == CXCursor_MacroDefinition) {
+ Priority = getMacroUsagePriority(C->Completion->getTypedText(),
+ Context.getPreferredType()->isAnyPointerType());
+ } else {
+ CanQualType Expected
+ = S.Context.getCanonicalType(Context.getPreferredType());
+ SimplifiedTypeClass ExpectedSTC = getSimplifiedTypeClass(Expected);
+ if (ExpectedSTC == C->TypeClass) {
+ // FIXME: How can we check for an exact match?
+ Priority /= CCF_SimilarTypeMatch;
+ }
+ }
+ }
+
+ AllResults.push_back(Result(C->Completion, Priority, C->Kind));
}
// If we did not add any cached completion results, just forward the