MCPcopy Create free account
hub / github.com/KDE/kdevelop / data

Method data

plugins/qmljs/codecompletion/items/completionitem.cpp:33–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33QVariant CompletionItem::data(const QModelIndex& index, int role, const CodeCompletionModel* model) const
34{
35 DUChainReadLocker lock;
36 Declaration* decl = declaration().data();
37
38 if (!decl) {
39 return QVariant();
40 }
41
42 auto* classDecl = dynamic_cast<ClassDeclaration *>(decl);
43 auto declType = decl->abstractType().dynamicCast<StructureType>();
44 auto funcType = decl->abstractType().dynamicCast<QmlJS::FunctionType>();
45
46 if (role == CodeCompletionModel::BestMatchesCount) {
47 return 5;
48 } else if (role == CodeCompletionModel::MatchQuality) {
49 AbstractType::Ptr referenceType =
50 static_cast<QmlJS::CodeCompletionContext*>(model->completionContext().data())->typeToMatch();
51
52 if (!referenceType) {
53 return QVariant();
54 }
55
56 AbstractType::Ptr declType = decl->abstractType();
57 if (!declType) {
58 return QVariant();
59 }
60
61 auto declFunc = declType.dynamicCast<QmlJS::FunctionType>();
62
63 if (declType->equals(referenceType.constData())) {
64 // Perfect type match
65 return QVariant(10);
66 } else if (declFunc && declFunc->returnType() &&
67 declFunc->returnType()->equals(referenceType.constData())) {
68 // Also very nice: a function returning the proper type
69 return QVariant(9);
70 } else {
71 // Completely different types, no luck
72 return QVariant();
73 }
74 } else if (role == Qt::DisplayRole && funcType) {
75 // Functions are displayed using the "type funcName(arg, arg, arg...)" format
76 Declaration* funcDecl = funcType->declaration(decl->topContext());
77
78 if (funcDecl) {
79 switch (index.column()) {
80 case CodeCompletionModel::Prefix:
81 return funcType->returnType()->toString();
82 case CodeCompletionModel::Name:
83 // Return the identifier of the declaration being listed, not of its
84 // function declaration (because the function may have been declared
85 // anonymously, even if it has been assigned to a variable)
86 return decl->identifier().toString();
87 case CodeCompletionModel::Arguments:
88 {
89 QStringList args;
90 const auto localDeclarations = funcDecl->internalContext()->localDeclarations();

Callers 15

qmakeExecutableMethod · 0.45
parseMethod · 0.45
nextTokenKindMethod · 0.45
toStringFunction · 0.45
runMethod · 0.45
commitMethod · 0.45
parseSchemaMethod · 0.45
valueOwnerMethod · 0.45
importsMethod · 0.45
PrototypeIteratorMethod · 0.45
initializeRootScopeMethod · 0.45
foreachFunction · 0.45

Calls 15

typeToMatchMethod · 0.80
localDeclarationsMethod · 0.80
joinMethod · 0.80
classTypeMethod · 0.80
declarationIdMethod · 0.80
baseClassesSizeMethod · 0.80
baseClassesMethod · 0.80
QVariantClass · 0.50
dataFunction · 0.50
abstractTypeMethod · 0.45
completionContextMethod · 0.45
equalsMethod · 0.45

Tested by 4

toStringFunction · 0.36
testQMLIdMethod · 0.36
runSessionMethod · 0.36
containsItemForTextFunction · 0.36