| 123 | } |
| 124 | |
| 125 | QList<KDevelop::CompletionTreeItemPointer> CodeCompletionContext::normalCompletion() |
| 126 | { |
| 127 | QList<CompletionTreeItemPointer> items; |
| 128 | QChar lastChar = m_text.size() > 0 ? m_text.at(m_text.size() - 1) : QLatin1Char('\0'); |
| 129 | bool inQmlObjectScope = (m_duContext->type() == DUContext::Class); |
| 130 | |
| 131 | // Start with the function call-tips, because functionCallTips is also responsible |
| 132 | // for setting m_declarationForTypeMatch |
| 133 | items << functionCallTips(); |
| 134 | |
| 135 | if (lastChar == QLatin1Char('.') || lastChar == QLatin1Char('[')) { |
| 136 | // Offer completions for object members and array subscripts |
| 137 | items << fieldCompletions( |
| 138 | m_text.left(m_text.size() - 1), |
| 139 | lastChar == QLatin1Char('[') ? CompletionItem::QuotesAndBracket : |
| 140 | CompletionItem::NoDecoration |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | // "object." must only display the members of object, the declarations |
| 145 | // available in the current context. |
| 146 | if (lastChar != QLatin1Char('.')) { |
| 147 | if (inQmlObjectScope) { |
| 148 | DUChainReadLocker lock; |
| 149 | |
| 150 | // The cursor is in a QML object and there is nothing before it. Display |
| 151 | // a list of properties and signals that can be used in a script binding. |
| 152 | // Note that the properties/signals of parent QML objects are not displayed here |
| 153 | items << completionsInContext(m_duContext, |
| 154 | CompletionOnlyLocal | CompletionHideWrappers, |
| 155 | CompletionItem::ColonOrBracket); |
| 156 | items << completionsFromImports(CompletionHideWrappers); |
| 157 | items << completionsInContext(DUContextPointer(m_duContext->topContext()), |
| 158 | CompletionHideWrappers, |
| 159 | CompletionItem::NoDecoration); |
| 160 | } else { |
| 161 | items << completionsInContext(m_duContext, |
| 162 | CompletionInContextFlags(), |
| 163 | CompletionItem::NoDecoration); |
| 164 | items << completionsFromImports(CompletionInContextFlags()); |
| 165 | items << completionsFromNodeModule(CompletionInContextFlags(), QStringLiteral("__builtin_ecmascript")); |
| 166 | |
| 167 | if (!QmlJS::isQmlFile(m_duContext.data())) { |
| 168 | items << completionsFromNodeModule(CompletionInContextFlags(), QStringLiteral("__builtin_dom")); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return items; |
| 174 | } |
| 175 | |
| 176 | QList<CompletionTreeItemPointer> CodeCompletionContext::commentCompletion() |
| 177 | { |