Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codecompletion/context.cpp
Show First 20 Lines • Show All 945 Lines • ▼ Show 20 Line(s) | 923 | { | |||
---|---|---|---|---|---|
946 | clangDebug() << "Clang found" << m_results->NumResults << "completion results"; | 946 | clangDebug() << "Clang found" << m_results->NumResults << "completion results"; | ||
947 | 947 | | |||
948 | for (uint i = 0; i < m_results->NumResults; ++i) { | 948 | for (uint i = 0; i < m_results->NumResults; ++i) { | ||
949 | if (abort) { | 949 | if (abort) { | ||
950 | return {}; | 950 | return {}; | ||
951 | } | 951 | } | ||
952 | 952 | | |||
953 | auto result = m_results->Results[i]; | 953 | auto result = m_results->Results[i]; | ||
954 | #if CINDEX_VERSION_MINOR >= 30 | ||||
955 | const bool isOverloadCandidate = result.CursorKind == CXCursor_OverloadCandidate; | ||||
956 | #else | ||||
957 | const bool isOverloadCandidate = false; | ||||
958 | #endif | ||||
954 | 959 | | |||
955 | const auto availability = clang_getCompletionAvailability(result.CompletionString); | 960 | const auto availability = clang_getCompletionAvailability(result.CompletionString); | ||
956 | if (availability == CXAvailability_NotAvailable) { | 961 | if (availability == CXAvailability_NotAvailable) { | ||
957 | continue; | 962 | continue; | ||
958 | } | 963 | } | ||
959 | 964 | | |||
960 | const bool isMacroDefinition = result.CursorKind == CXCursor_MacroDefinition; | 965 | const bool isMacroDefinition = result.CursorKind == CXCursor_MacroDefinition; | ||
961 | if (isMacroDefinition && m_filters & NoMacros) { | 966 | if (isMacroDefinition && m_filters & NoMacros) { | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 1013 | if (kind == CXCompletionChunk_Optional) { | |||
1010 | if (completionString) { | 1015 | if (completionString) { | ||
1011 | processChunks(completionString); | 1016 | processChunks(completionString); | ||
1012 | } | 1017 | } | ||
1013 | continue; | 1018 | continue; | ||
1014 | } | 1019 | } | ||
1015 | 1020 | | |||
1016 | // We don't need function signature for declaration items, we can get it directly from the declaration. Also adding the function signature to the "display" would break the "Detailed completion" option. | 1021 | // We don't need function signature for declaration items, we can get it directly from the declaration. Also adding the function signature to the "display" would break the "Detailed completion" option. | ||
1017 | if (isDeclaration && !typed.isEmpty()) { | 1022 | if (isDeclaration && !typed.isEmpty()) { | ||
1018 | #if CINDEX_VERSION_MINOR >= 30 | | |||
1019 | // TODO: When parent context for CXCursor_OverloadCandidate is fixed remove this check | 1023 | // TODO: When parent context for CXCursor_OverloadCandidate is fixed remove this check | ||
1020 | if (result.CursorKind != CXCursor_OverloadCandidate) { | 1024 | if (!isOverloadCandidate) { | ||
1021 | break; | 1025 | break; | ||
1022 | } | 1026 | } | ||
1023 | #else | | |||
1024 | break; | | |||
1025 | #endif | | |||
1026 | } | 1027 | } | ||
1027 | 1028 | | |||
1028 | const QString string = ClangString(clang_getCompletionChunkText(completionString, j)).toString(); | 1029 | const QString string = ClangString(clang_getCompletionChunkText(completionString, j)).toString(); | ||
1029 | 1030 | | |||
1030 | switch (kind) { | 1031 | switch (kind) { | ||
1031 | case CXCompletionChunk_TypedText: | 1032 | case CXCompletionChunk_TypedText: | ||
1032 | typed = string; | 1033 | typed = string; | ||
1033 | replacement = string; | 1034 | replacement = string; | ||
Show All 15 Lines | |||||
1049 | case CXCompletionChunk_RightParen: | 1050 | case CXCompletionChunk_RightParen: | ||
1050 | --parenDepth; | 1051 | --parenDepth; | ||
1051 | if (signatureState == Inside && !parenDepth) { | 1052 | if (signatureState == Inside && !parenDepth) { | ||
1052 | arguments += QLatin1Char(')'); | 1053 | arguments += QLatin1Char(')'); | ||
1053 | signatureState = After; | 1054 | signatureState = After; | ||
1054 | } | 1055 | } | ||
1055 | break; | 1056 | break; | ||
1056 | case CXCompletionChunk_Text: | 1057 | case CXCompletionChunk_Text: | ||
1057 | #if CINDEX_VERSION_MINOR >= 30 | 1058 | if (isOverloadCandidate) { | ||
1058 | if (result.CursorKind == CXCursor_OverloadCandidate) { | | |||
1059 | typed += string; | 1059 | typed += string; | ||
1060 | } | 1060 | } | ||
1061 | #endif | | |||
1062 | break; | 1061 | break; | ||
1063 | case CXCompletionChunk_CurrentParameter: | 1062 | case CXCompletionChunk_CurrentParameter: | ||
1064 | argumentRange.start = arguments.size(); | 1063 | argumentRange.start = arguments.size(); | ||
1065 | argumentRange.end = string.size(); | 1064 | argumentRange.end = string.size(); | ||
1066 | break; | 1065 | break; | ||
1067 | default: | 1066 | default: | ||
1068 | break; | 1067 | break; | ||
1069 | } | 1068 | } | ||
1070 | if (signatureState == Inside) { | 1069 | if (signatureState == Inside) { | ||
1071 | arguments += string; | 1070 | arguments += string; | ||
1072 | } | 1071 | } | ||
1073 | } | 1072 | } | ||
1074 | }; | 1073 | }; | ||
1075 | 1074 | | |||
1076 | processChunks(result.CompletionString); | 1075 | processChunks(result.CompletionString); | ||
1077 | 1076 | | |||
1078 | #if CINDEX_VERSION_MINOR >= 30 | | |||
1079 | // TODO: No closing paren if default parameters present | 1077 | // TODO: No closing paren if default parameters present | ||
1080 | if (result.CursorKind == CXCursor_OverloadCandidate && !arguments.endsWith(QLatin1Char(')'))) { | 1078 | if (isOverloadCandidate && !arguments.endsWith(QLatin1Char(')'))) { | ||
1081 | arguments += QLatin1Char(')'); | 1079 | arguments += QLatin1Char(')'); | ||
1082 | } | 1080 | } | ||
1083 | #endif | | |||
1084 | // ellide text to the right for overly long result types (templates especially) | 1081 | // ellide text to the right for overly long result types (templates especially) | ||
1085 | elideStringRight(resultType, MAX_RETURN_TYPE_STRING_LENGTH); | 1082 | elideStringRight(resultType, MAX_RETURN_TYPE_STRING_LENGTH); | ||
1086 | 1083 | | |||
1087 | static const auto noIcon = QIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, | 1084 | static const auto noIcon = QIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
1088 | QStringLiteral("kdevelop/pics/namespace.png"))); | 1085 | QStringLiteral("kdevelop/pics/namespace.png"))); | ||
1089 | 1086 | | |||
1090 | if (isDeclaration) { | 1087 | if (isDeclaration) { | ||
1091 | const Identifier id(typed); | 1088 | const Identifier id(typed); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 1103 | if (found) { | |||
1139 | } else { | 1136 | } else { | ||
1140 | declarationItem->setInheritanceDepth(completionPriority); | 1137 | declarationItem->setInheritanceDepth(completionPriority); | ||
1141 | 1138 | | |||
1142 | lookAheadMatcher.addDeclarations(found); | 1139 | lookAheadMatcher.addDeclarations(found); | ||
1143 | } | 1140 | } | ||
1144 | if ( isInternal ) { | 1141 | if ( isInternal ) { | ||
1145 | declarationItem->markAsUnimportant(); | 1142 | declarationItem->markAsUnimportant(); | ||
1146 | } | 1143 | } | ||
1147 | #if CINDEX_VERSION_MINOR >= 30 | 1144 | if (isOverloadCandidate) { | ||
1148 | if (result.CursorKind == CXCursor_OverloadCandidate) { | | |||
1149 | declarationItem->setArgumentHintDepth(1); | 1145 | declarationItem->setArgumentHintDepth(1); | ||
1150 | } | 1146 | } | ||
1151 | #endif | | |||
1152 | 1147 | | |||
1153 | item = declarationItem; | 1148 | item = declarationItem; | ||
1154 | } else { | 1149 | } else { | ||
1155 | #if CINDEX_VERSION_MINOR >= 30 | 1150 | if (isOverloadCandidate) { | ||
1156 | if (result.CursorKind == CXCursor_OverloadCandidate) { | | |||
1157 | // TODO: No parent context for CXCursor_OverloadCandidate items, hence qid is broken -> no declaration found | 1151 | // TODO: No parent context for CXCursor_OverloadCandidate items, hence qid is broken -> no declaration found | ||
1158 | auto ahi = new ArgumentHintItem({}, resultType, typed, arguments, argumentRange); | 1152 | auto ahi = new ArgumentHintItem({}, resultType, typed, arguments, argumentRange); | ||
1159 | ahi->setArgumentHintDepth(1); | 1153 | ahi->setArgumentHintDepth(1); | ||
1160 | item = ahi; | 1154 | item = ahi; | ||
1161 | } else { | 1155 | } else { | ||
1162 | #endif | | |||
1163 | // still, let's trust that Clang found something useful and put it into the completion result list | 1156 | // still, let's trust that Clang found something useful and put it into the completion result list | ||
1164 | clangDebug() << "Could not find declaration for" << qid; | 1157 | clangDebug() << "Could not find declaration for" << qid; | ||
1165 | auto instance = new SimpleItem(typed + arguments, resultType, replacement, noIcon); | 1158 | auto instance = new SimpleItem(typed + arguments, resultType, replacement, noIcon); | ||
1166 | instance->markAsUnimportant(); | 1159 | instance->markAsUnimportant(); | ||
1167 | item = CompletionTreeItemPointer(instance); | 1160 | item = CompletionTreeItemPointer(instance); | ||
1168 | #if CINDEX_VERSION_MINOR >= 30 | | |||
1169 | } | 1161 | } | ||
1170 | #endif | | |||
1171 | } | 1162 | } | ||
1172 | 1163 | | |||
1173 | if (isValidSpecialCompletionIdentifier(qid)) { | 1164 | if (isValidSpecialCompletionIdentifier(qid)) { | ||
1174 | // If it's a special completion identifier e.g. "operator=(const&)" and we don't have a declaration for it, don't add it into completion list, as this item is completely useless and pollutes the test case. | 1165 | // If it's a special completion identifier e.g. "operator=(const&)" and we don't have a declaration for it, don't add it into completion list, as this item is completely useless and pollutes the test case. | ||
1175 | // This happens e.g. for "class A{}; a.|". At | we have "operator=(const A&)" as a special completion identifier without a declaration. | 1166 | // This happens e.g. for "class A{}; a.|". At | we have "operator=(const A&)" as a special completion identifier without a declaration. | ||
1176 | if(item->declaration()){ | 1167 | if(item->declaration()){ | ||
1177 | specialItems.append(item); | 1168 | specialItems.append(item); | ||
1178 | } | 1169 | } | ||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |