Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codecompletion/context.cpp
Show First 20 Lines • Show All 360 Lines • ▼ Show 20 Line(s) | 355 | if (role == CodeCompletionModel::CustomHighlight && index.column() == CodeCompletionModel::Arguments && argumentHintDepth()) { | |||
---|---|---|---|---|---|
361 | highlighting << boldFormat; | 361 | highlighting << boldFormat; | ||
362 | return highlighting; | 362 | return highlighting; | ||
363 | } | 363 | } | ||
364 | 364 | | |||
365 | if (role == CodeCompletionModel::HighlightingMethod && index.column() == CodeCompletionModel::Arguments && argumentHintDepth()) { | 365 | if (role == CodeCompletionModel::HighlightingMethod && index.column() == CodeCompletionModel::Arguments && argumentHintDepth()) { | ||
366 | return QVariant(CodeCompletionModel::CustomHighlighting); | 366 | return QVariant(CodeCompletionModel::CustomHighlighting); | ||
367 | } | 367 | } | ||
368 | 368 | | |||
369 | if (index.column() == CodeCompletionModel::Arguments && !m_declaration) { | 369 | if (index.column() == CodeCompletionModel::Arguments) { | ||
370 | return m_arguments; | 370 | return m_arguments; | ||
371 | } | 371 | } | ||
372 | 372 | | |||
373 | return DeclarationItem::data(index, role, model); | 373 | return DeclarationItem::data(index, role, model); | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | private: | 376 | private: | ||
377 | CurrentArgumentRange m_range; | 377 | CurrentArgumentRange m_range; | ||
▲ Show 20 Lines • Show All 553 Lines • ▼ Show 20 Line(s) | 923 | { | |||
931 | QList<CompletionTreeItemPointer> items; | 931 | QList<CompletionTreeItemPointer> items; | ||
932 | /// Stuff like 'Foo& Foo::operator=(const Foo&)', etc. Not regularly used by our users. | 932 | /// Stuff like 'Foo& Foo::operator=(const Foo&)', etc. Not regularly used by our users. | ||
933 | QList<CompletionTreeItemPointer> specialItems; | 933 | QList<CompletionTreeItemPointer> specialItems; | ||
934 | /// Macros from the current context | 934 | /// Macros from the current context | ||
935 | QList<CompletionTreeItemPointer> macros; | 935 | QList<CompletionTreeItemPointer> macros; | ||
936 | /// Builtins reported by Clang | 936 | /// Builtins reported by Clang | ||
937 | QList<CompletionTreeItemPointer> builtin; | 937 | QList<CompletionTreeItemPointer> builtin; | ||
938 | 938 | | |||
939 | // two sets of handled declarations to prevent duplicates and make sure we show | ||||
940 | // all available overloads | ||||
939 | QSet<Declaration*> handled; | 941 | QSet<Declaration*> handled; | ||
942 | // this is only used for the CXCursor_OverloadCandidate completion items | ||||
943 | QSet<Declaration*> overloadsHandled; | ||||
940 | 944 | | |||
941 | LookAheadItemMatcher lookAheadMatcher(TopDUContextPointer(ctx->topContext())); | 945 | LookAheadItemMatcher lookAheadMatcher(TopDUContextPointer(ctx->topContext())); | ||
942 | 946 | | |||
943 | // If ctx is/inside the Class context, this represents that context. | 947 | // If ctx is/inside the Class context, this represents that context. | ||
944 | const auto currentClassContext = classDeclarationForContext(ctx, m_position); | 948 | const auto currentClassContext = classDeclarationForContext(ctx, m_position); | ||
945 | 949 | | |||
946 | clangDebug() << "Clang found" << m_results->NumResults << "completion results"; | 950 | clangDebug() << "Clang found" << m_results->NumResults << "completion results"; | ||
947 | 951 | | |||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 1095 | if (parent.c_str() != nullptr) { | |||
1092 | qid = QualifiedIdentifier(parent.toString()); | 1096 | qid = QualifiedIdentifier(parent.toString()); | ||
1093 | } | 1097 | } | ||
1094 | qid.push(id); | 1098 | qid.push(id); | ||
1095 | 1099 | | |||
1096 | if (!isValidCompletionIdentifier(qid)) { | 1100 | if (!isValidCompletionIdentifier(qid)) { | ||
1097 | continue; | 1101 | continue; | ||
1098 | } | 1102 | } | ||
1099 | 1103 | | |||
1100 | auto found = findDeclaration(qid, ctx, m_position, handled); | 1104 | auto found = findDeclaration(qid, ctx, m_position, isOverloadCandidate ? overloadsHandled : handled); | ||
1101 | 1105 | | |||
1102 | CompletionTreeItemPointer item; | 1106 | CompletionTreeItemPointer item; | ||
1103 | if (found) { | 1107 | if (found) { | ||
1104 | // TODO: Bug in Clang: protected members from base classes not accessible in derived classes. | 1108 | // TODO: Bug in Clang: protected members from base classes not accessible in derived classes. | ||
1105 | if (availability == CXAvailability_NotAccessible) { | 1109 | if (availability == CXAvailability_NotAccessible) { | ||
1106 | if (auto cl = dynamic_cast<ClassMemberDeclaration*>(found)) { | 1110 | if (auto cl = dynamic_cast<ClassMemberDeclaration*>(found)) { | ||
1107 | if (cl->accessPolicy() != Declaration::Protected) { | 1111 | if (cl->accessPolicy() != Declaration::Protected) { | ||
1108 | continue; | 1112 | continue; | ||
1109 | } | 1113 | } | ||
1110 | 1114 | | |||
1111 | auto declarationClassContext = classDeclarationForContext(DUContextPointer(found->context()), m_position); | 1115 | auto declarationClassContext = classDeclarationForContext(DUContextPointer(found->context()), m_position); | ||
1112 | 1116 | | |||
1113 | uint steps = 10; | 1117 | uint steps = 10; | ||
1114 | auto inheriters = DUChainUtils::getInheriters(declarationClassContext, steps); | 1118 | auto inheriters = DUChainUtils::getInheriters(declarationClassContext, steps); | ||
1115 | if(!inheriters.contains(currentClassContext)){ | 1119 | if(!inheriters.contains(currentClassContext)){ | ||
1116 | continue; | 1120 | continue; | ||
1117 | } | 1121 | } | ||
1118 | } else { | 1122 | } else { | ||
1119 | continue; | 1123 | continue; | ||
1120 | } | 1124 | } | ||
1121 | } | 1125 | } | ||
1122 | 1126 | | |||
1123 | auto declarationItem = new DeclarationItem(found, typed, resultType, replacement); | 1127 | DeclarationItem* declarationItem = nullptr; | ||
1128 | if (isOverloadCandidate) { | ||||
1129 | declarationItem = new ArgumentHintItem(found, resultType, typed, arguments, argumentRange); | ||||
1130 | declarationItem->setArgumentHintDepth(1); | ||||
1131 | } else { | ||||
1132 | declarationItem = new DeclarationItem(found, typed, resultType, replacement); | ||||
1133 | } | ||||
1124 | 1134 | | |||
1125 | const unsigned int completionPriority = adjustPriorityForDeclaration(found, clang_getCompletionPriority(result.CompletionString)); | 1135 | const unsigned int completionPriority = adjustPriorityForDeclaration(found, clang_getCompletionPriority(result.CompletionString)); | ||
1126 | const bool bestMatch = completionPriority <= CCP_SuperCompletion; | 1136 | const bool bestMatch = completionPriority <= CCP_SuperCompletion; | ||
1127 | 1137 | | |||
1128 | //don't set best match property for internal identifiers, also prefer declarations from current file | 1138 | //don't set best match property for internal identifiers, also prefer declarations from current file | ||
1129 | const auto isInternal = found->indexedIdentifier().identifier().toString().startsWith(QLatin1String("__")); | 1139 | const auto isInternal = found->indexedIdentifier().identifier().toString().startsWith(QLatin1String("__")); | ||
1130 | if (bestMatch && !isInternal ) { | 1140 | if (bestMatch && !isInternal ) { | ||
1131 | const int matchQuality = codeCompletionPriorityToMatchQuality(completionPriority); | 1141 | const int matchQuality = codeCompletionPriorityToMatchQuality(completionPriority); | ||
1132 | declarationItem->setMatchQuality(matchQuality); | 1142 | declarationItem->setMatchQuality(matchQuality); | ||
1133 | 1143 | | |||
1134 | // TODO: LibClang missing API to determine expected code completion type. | 1144 | // TODO: LibClang missing API to determine expected code completion type. | ||
1135 | lookAheadMatcher.addMatchedType(found->indexedType()); | 1145 | lookAheadMatcher.addMatchedType(found->indexedType()); | ||
1136 | } else { | 1146 | } else { | ||
1137 | declarationItem->setInheritanceDepth(completionPriority); | 1147 | declarationItem->setInheritanceDepth(completionPriority); | ||
1138 | 1148 | | |||
1139 | lookAheadMatcher.addDeclarations(found); | 1149 | lookAheadMatcher.addDeclarations(found); | ||
1140 | } | 1150 | } | ||
1141 | if ( isInternal ) { | 1151 | if ( isInternal ) { | ||
1142 | declarationItem->markAsUnimportant(); | 1152 | declarationItem->markAsUnimportant(); | ||
1143 | } | 1153 | } | ||
1144 | if (isOverloadCandidate) { | | |||
1145 | declarationItem->setArgumentHintDepth(1); | | |||
1146 | } | | |||
1147 | 1154 | | |||
1148 | item = declarationItem; | 1155 | item = declarationItem; | ||
1149 | } else { | 1156 | } else { | ||
1150 | if (isOverloadCandidate) { | 1157 | if (isOverloadCandidate) { | ||
1151 | // TODO: No parent context for CXCursor_OverloadCandidate items, hence qid is broken -> no declaration found | 1158 | // TODO: No parent context for CXCursor_OverloadCandidate items, hence qid is broken -> no declaration found | ||
1152 | auto ahi = new ArgumentHintItem({}, resultType, typed, arguments, argumentRange); | 1159 | auto ahi = new ArgumentHintItem({}, resultType, typed, arguments, argumentRange); | ||
1153 | ahi->setArgumentHintDepth(1); | 1160 | ahi->setArgumentHintDepth(1); | ||
1154 | item = ahi; | 1161 | item = ahi; | ||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |