Commit 9cbb6f2f authored by Milian Wolff's avatar Milian Wolff

Try a bit harder to find types for look-ahead completion

We now look at the return type of functions we complete, instead of
just adding the functions themselves. This sounds like a valid
approach but in the end isn't sufficient to solve all cases - we
really need to expand the libclang API to get this done properly.

Most notably, since self-assignment isn't allowed anymore, we cannot
find the correct type for the `int* p = ...` case anymore and just
fail then... For now, we will mark the test as an expected failure.
parent d4a791c6
......@@ -727,7 +727,9 @@ public:
/// Only items with @p type will be returned through @sa matchedItems
void addMatchedType(const IndexedType& type)
{
matchedTypes.insert(type);
if (type.isValid()) {
matchedTypes.insert(type);
}
}
/// @return look-ahead items that math given types. @sa addMatchedType
......@@ -777,11 +779,11 @@ private:
}
}
if(!declaration->abstractType()){
if (!localDecl->abstractType()) {
continue;
}
if (declaration->abstractType()->whichType() == AbstractType::TypeIntegral) {
if (localDecl->abstractType()->whichType() == AbstractType::TypeIntegral) {
if (auto integralType = declaration->abstractType().cast<IntegralType>()) {
if (integralType->dataType() == IntegralType::TypeVoid) {
continue;
......@@ -1235,11 +1237,14 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
//don't set best match property for internal identifiers, also prefer declarations from current file
const auto isInternal = found->indexedIdentifier().identifier().toString().startsWith(QLatin1String("__"));
if (bestMatch && !isInternal ) {
if (bestMatch && !isInternal) {
const int matchQuality = codeCompletionPriorityToMatchQuality(completionPriority);
declarationItem->setMatchQuality(matchQuality);
// TODO: LibClang missing API to determine expected code completion type.
if (auto functionType = found->type<FunctionType>()) {
lookAheadMatcher.addMatchedType(IndexedType(functionType->returnType()));
}
lookAheadMatcher.addMatchedType(found->indexedType());
} else {
declarationItem->setInheritanceDepth(completionPriority);
......
......@@ -177,6 +177,9 @@ void executeCompletionTest(const ReferencedTopDUContext& top, const CompletionIt
if (QTest::currentTestFunction() == QByteArrayLiteral("testImplementAfterEdit") && expectedCompletionItems.position.line() == 3) {
QEXPECT_FAIL("", "TU is not properly updated after edit", Continue);
}
if (QTest::currentTestFunction() == QByteArrayLiteral("testClangCodeCompletion")) {
QEXPECT_FAIL("look-ahead pointer", "self-assignment isn't done anymore, so we don't find any suitable type anymore", Continue);
}
if (tester.names.size() != expectedCompletionItems.completions.size()) {
qDebug() << "different results:\nactual:" << tester.names << "\nexpected:" << expectedCompletionItems.completions;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment