Changeset View
Changeset View
Standalone View
Standalone View
completion/context.cpp
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
78 | CodeCompletionContext::CodeCompletionContext(DUContextPointer context, const QString& text, const QString& followingText, const KDevelop::CursorInRevision& position, int depth, const QStringList& knownArgumentExpressions, int line) | 78 | CodeCompletionContext::CodeCompletionContext(DUContextPointer context, const QString& text, const QString& followingText, const KDevelop::CursorInRevision& position, int depth, const QStringList& knownArgumentExpressions, int line) | ||
79 | : KDevelop::CodeCompletionContext(context, text, position, depth) | 79 | : KDevelop::CodeCompletionContext(context, text, position, depth) | ||
80 | , m_memberAccessOperation(NoMemberAccess), m_followingText( followingText ), | 80 | , m_memberAccessOperation(NoMemberAccess), m_followingText( followingText ), | ||
81 | m_knownArgumentExpressions( knownArgumentExpressions) | 81 | m_knownArgumentExpressions( knownArgumentExpressions) | ||
82 | { | 82 | { | ||
83 | #warning What to do with knownArgumentExpressions ? | 83 | #warning What to do with knownArgumentExpressions ? | ||
84 | m_valid = isValidPosition(); | 84 | m_valid = isValidPosition(); | ||
85 | if( !m_valid ) { | 85 | if( !m_valid ) { | ||
86 | kDebug() << "position not valid for code-completion" ; | 86 | qDebug() << "position not valid for code-completion" ; | ||
87 | return; | 87 | return; | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | ifDebug( kDebug() << "non-processed text: " << m_text; ) | 90 | ifDebug( qDebug() << "non-processed text: " << m_text; ) | ||
91 | 91 | | |||
92 | // m_text = Utils::clearComments( m_text ); | 92 | // m_text = Utils::clearComments( m_text ); | ||
93 | // m_text = Utils::clearStrings( m_text ); | 93 | // m_text = Utils::clearStrings( m_text ); | ||
94 | // m_text = Utils::stripFinalWhitespace( m_text ); | 94 | // m_text = Utils::stripFinalWhitespace( m_text ); | ||
95 | 95 | | |||
96 | ifDebug( kDebug() << "processed text: " << m_text; ) | 96 | ifDebug( qDebug() << "processed text: " << m_text; ) | ||
97 | 97 | | |||
98 | ///@todo template-parameters | 98 | ///@todo template-parameters | ||
99 | 99 | | |||
100 | ///First: find out what kind of completion we are dealing with | 100 | ///First: find out what kind of completion we are dealing with | ||
101 | 101 | | |||
102 | if (m_text.endsWith( ';' ) || m_text.endsWith('}') || m_text.endsWith('{') || m_text.endsWith(')') ) { | 102 | if (m_text.endsWith( ';' ) || m_text.endsWith('}') || m_text.endsWith('{') || m_text.endsWith(')') ) { | ||
103 | ///We're at the beginning of a new statement. General completion is valid. | 103 | ///We're at the beginning of a new statement. General completion is valid. | ||
104 | return; | 104 | return; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 148 | { | |||
155 | 155 | | |||
156 | typedef QPair<Declaration*, int> DeclarationDepthPair; | 156 | typedef QPair<Declaration*, int> DeclarationDepthPair; | ||
157 | 157 | | |||
158 | if(!m_storedItems.isEmpty()) { | 158 | if(!m_storedItems.isEmpty()) { | ||
159 | items = m_storedItems; | 159 | items = m_storedItems; | ||
160 | 160 | | |||
161 | } else { | 161 | } else { | ||
162 | standardAccessCompletionItems(items); | 162 | standardAccessCompletionItems(items); | ||
163 | kDebug() << "Found declarations:" << items.count(); | 163 | qDebug() << "Found declarations:" << items.count(); | ||
164 | } | 164 | } | ||
165 | 165 | | |||
166 | return items; | 166 | return items; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | void CodeCompletionContext::standardAccessCompletionItems(QList< CompletionTreeItemPointer >& items) { | 169 | void CodeCompletionContext::standardAccessCompletionItems(QList< CompletionTreeItemPointer >& items) { | ||
170 | //Normal case: Show all visible declarations | 170 | //Normal case: Show all visible declarations | ||
171 | typedef QPair<Declaration*, int> DeclarationDepthPair; | 171 | typedef QPair<Declaration*, int> DeclarationDepthPair; | ||
172 | QSet<QualifiedIdentifier> hadNamespaceDeclarations; | 172 | QSet<QualifiedIdentifier> hadNamespaceDeclarations; | ||
173 | 173 | | |||
174 | bool typeIsConst = false; | 174 | bool typeIsConst = false; | ||
175 | /*if (Declaration* func = Cpp::localFunctionFromCodeContext(m_duContext.data())) { | 175 | /*if (Declaration* func = Cpp::localFunctionFromCodeContext(m_duContext.data())) { | ||
176 | if (func->abstractType() && (func->abstractType()->modifiers() & AbstractType::ConstModifier)) | 176 | if (func->abstractType() && (func->abstractType()->modifiers() & AbstractType::ConstModifier)) | ||
177 | typeIsConst = true; | 177 | typeIsConst = true; | ||
178 | }*/ | 178 | }*/ | ||
179 | 179 | | |||
180 | QList<DeclarationDepthPair> decls = m_duContext->allDeclarations(m_duContext->type() == DUContext::Class ? m_duContext->range().end : m_position, m_duContext->topContext()); | 180 | QVector<DeclarationDepthPair> decls = m_duContext->allDeclarations(m_duContext->type() == DUContext::Class ? m_duContext->range().end : m_position, m_duContext->topContext()); | ||
181 | 181 | | |||
182 | QList<Declaration*> moreDecls; | 182 | QList<Declaration*> moreDecls; | ||
183 | 183 | | |||
184 | Q_ASSERT(m_duContext); | 184 | Q_ASSERT(m_duContext); | ||
185 | if(m_duContext) { | 185 | if(m_duContext) { | ||
186 | //Collect the Declarations from all "using namespace" imported contexts | 186 | //Collect the Declarations from all "using namespace" imported contexts | ||
187 | TopDUContext* top = m_duContext->topContext(); | 187 | TopDUContext* top = m_duContext->topContext(); | ||
188 | 188 | | |||
Show All 13 Lines | 201 | foreach (Declaration* import, top->findLocalDeclarations(KDevelop::Identifier(globalStaticImportIdentifier))) | |||
202 | if (NamespaceAliasDeclaration* alias = dynamic_cast<NamespaceAliasDeclaration*>(import)) | 202 | if (NamespaceAliasDeclaration* alias = dynamic_cast<NamespaceAliasDeclaration*>(import)) | ||
203 | if (alias->importIdentifier().last() == Identifier("*")) | 203 | if (alias->importIdentifier().last() == Identifier("*")) | ||
204 | // TODO static-filter | 204 | // TODO static-filter | ||
205 | packages.insert( alias->importIdentifier().left(-1) ); | 205 | packages.insert( alias->importIdentifier().left(-1) ); | ||
206 | else | 206 | else | ||
207 | // TODO static-filter | 207 | // TODO static-filter | ||
208 | moreDecls << top->findDeclarations(alias->importIdentifier()); | 208 | moreDecls << top->findDeclarations(alias->importIdentifier()); | ||
209 | 209 | | |||
210 | kDebug() << "Found imported packages to retrieve declarations from:"; | 210 | qDebug() << "Found imported packages to retrieve declarations from:"; | ||
211 | 211 | | |||
212 | foreach(const QualifiedIdentifier &package, packages) { | 212 | foreach(const QualifiedIdentifier &package, packages) { | ||
213 | QList<Declaration*> importedContextDecls = m_duContext->findDeclarations( package ); | 213 | QList<Declaration*> importedContextDecls = m_duContext->findDeclarations( package ); | ||
214 | kDebug() << package.toStringList().join(".") << "context declarations found: " << importedContextDecls.count(); | 214 | qDebug() << package.toStringList().join(".") << "context declarations found: " << importedContextDecls.count(); | ||
215 | foreach(Declaration* contextDecl, importedContextDecls) { | 215 | foreach(Declaration* contextDecl, importedContextDecls) { | ||
216 | if(contextDecl->kind() != Declaration::Namespace || !contextDecl->internalContext()) | 216 | if(contextDecl->kind() != Declaration::Namespace || !contextDecl->internalContext()) | ||
217 | continue; | 217 | continue; | ||
218 | DUContext* context = contextDecl->internalContext(); | 218 | DUContext* context = contextDecl->internalContext(); | ||
219 | 219 | | |||
220 | /*if(context->range().contains(m_duContext->range())) { | 220 | /*if(context->range().contains(m_duContext->range())) { | ||
221 | kDebug() << "Ignoring same context " << context << m_duContext; | 221 | qDebug() << "Ignoring same context " << context << m_duContext; | ||
222 | continue; //If the context surrounds the current one, the declarations are visible through allDeclarations(..). | 222 | continue; //If the context surrounds the current one, the declarations are visible through allDeclarations(..). | ||
223 | }*/ | 223 | }*/ | ||
224 | 224 | | |||
225 | foreach(Declaration* decl, context->localDeclarations()) | 225 | foreach(Declaration* decl, context->localDeclarations()) | ||
226 | if(filterDeclaration(decl)) { | 226 | if(filterDeclaration(decl)) { | ||
227 | kDebug() << "Adding declaration" << decl << decl->toString(); | 227 | qDebug() << "Adding declaration" << decl << decl->toString(); | ||
228 | moreDecls << decl; | 228 | moreDecls << decl; | ||
229 | } else { | 229 | } else { | ||
230 | kDebug() << "Filtered out declaration" << decl; | 230 | qDebug() << "Filtered out declaration" << decl; | ||
231 | } | 231 | } | ||
232 | } | 232 | } | ||
233 | } | 233 | } | ||
234 | } | 234 | } | ||
235 | 235 | | |||
236 | /*QList<DeclarationDepthPair> oldDecls = decls; | 236 | /*QList<DeclarationDepthPair> oldDecls = decls; | ||
237 | decls.clear(); | 237 | decls.clear(); | ||
238 | 238 | | |||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
289 | 289 | | |||
290 | if(classFun && !classFun->isStatic() && classFun->context()->owner() && !m_onlyShowSignals && !m_onlyShowSlots && !m_onlyShowTypes) { | 290 | if(classFun && !classFun->isStatic() && classFun->context()->owner() && !m_onlyShowSignals && !m_onlyShowSlots && !m_onlyShowTypes) { | ||
291 | AbstractType::Ptr classType = classFun->context()->owner()->abstractType(); | 291 | AbstractType::Ptr classType = classFun->context()->owner()->abstractType(); | ||
292 | if(classFun->abstractType()->modifiers() & AbstractType::ConstModifier) | 292 | if(classFun->abstractType()->modifiers() & AbstractType::ConstModifier) | ||
293 | classType->setModifiers((AbstractType::CommonModifiers)(classType->modifiers() | AbstractType::ConstModifier)); | 293 | classType->setModifiers((AbstractType::CommonModifiers)(classType->modifiers() | AbstractType::ConstModifier)); | ||
294 | PointerType::Ptr thisPointer(new PointerType()); | 294 | PointerType::Ptr thisPointer(new PointerType()); | ||
295 | thisPointer->setModifiers(AbstractType::ConstModifier); | 295 | thisPointer->setModifiers(AbstractType::ConstModifier); | ||
296 | thisPointer->setBaseType(classType); | 296 | thisPointer->setBaseType(classType); | ||
297 | KSharedPtr<TypeConversionCompletionItem> item( new TypeConversionCompletionItem("this", thisPointer->indexed(), 0, KSharedPtr <Cpp::CodeCompletionContext >(this)) ); | 297 | QExplicitlySharedDataPointer<TypeConversionCompletionItem> item( new TypeConversionCompletionItem("this", thisPointer->indexed(), 0, QExplicitlySharedDataPointer <Cpp::CodeCompletionContext >(this)) ); | ||
298 | item->setPrefix(thisPointer->toString()); | 298 | item->setPrefix(thisPointer->toString()); | ||
299 | QList<CompletionTreeItemPointer> lst; | 299 | QList<CompletionTreeItemPointer> lst; | ||
300 | lst += CompletionTreeItemPointer(item.data()); | 300 | lst += CompletionTreeItemPointer(item.data()); | ||
301 | eventuallyAddGroup(i18n("C++ Builtin"), 800, lst); | 301 | eventuallyAddGroup(i18n("C++ Builtin"), 800, lst); | ||
302 | } | 302 | } | ||
303 | 303 | | |||
304 | //Eventually add missing include-completion in cases like NotIncludedClass| | 304 | //Eventually add missing include-completion in cases like NotIncludedClass| | ||
305 | // if(!m_followingText.trimmed().isEmpty()) { | 305 | // if(!m_followingText.trimmed().isEmpty()) { | ||
306 | // uint oldItemCount = items.count(); | 306 | // uint oldItemCount = items.count(); | ||
307 | // items += missingIncludeCompletionItems(totalExpression, m_followingText.trimmed() + ": ", ExpressionEvaluationResult(), m_duContext.data(), 0); | 307 | // items += missingIncludeCompletionItems(totalExpression, m_followingText.trimmed() + ": ", ExpressionEvaluationResult(), m_duContext.data(), 0); | ||
308 | #ifndef TEST_COMPLETION | 308 | #ifndef TEST_COMPLETION | ||
309 | MissingIncludeCompletionModel::self().startWithExpression(m_duContext, QString(), m_followingText.trimmed()); | 309 | MissingIncludeCompletionModel::self().startWithExpression(m_duContext, QString(), m_followingText.trimmed()); | ||
310 | #endif | 310 | #endif | ||
311 | // kDebug() << QString("added %1 missing-includes for %2").arg(items.count()-oldItemCount).arg(totalExpression); | 311 | // qDebug() << QString("added %1 missing-includes for %2").arg(items.count()-oldItemCount).arg(totalExpression); | ||
312 | // } | 312 | // } | ||
313 | 313 | | |||
314 | eventuallyAddGroup(i18n("C++ Builtin"), 800, keywordCompletionItems()); | 314 | eventuallyAddGroup(i18n("C++ Builtin"), 800, keywordCompletionItems()); | ||
315 | #endif | 315 | #endif | ||
316 | } | 316 | } | ||
317 | 317 | | |||
318 | bool CodeCompletionContext::filterDeclaration(KDevelop::Declaration* decl, KDevelop::DUContext* declarationContext, bool dynamic, bool typeIsConst) | 318 | bool CodeCompletionContext::filterDeclaration(KDevelop::Declaration* decl, KDevelop::DUContext* declarationContext, bool dynamic, bool typeIsConst) | ||
319 | { | 319 | { | ||
320 | if(!decl) | 320 | if(!decl) | ||
321 | return false; | 321 | return false; | ||
322 | 322 | | |||
323 | if (dynamic_cast<NamespaceAliasDeclaration*>(decl)) | 323 | if (dynamic_cast<NamespaceAliasDeclaration*>(decl)) | ||
324 | return false; | 324 | return false; | ||
325 | 325 | | |||
326 | if (decl->kind() == DUContext::Namespace) | 326 | if (decl->kind() == Declaration::Kind::Namespace) | ||
327 | return false; | 327 | return false; | ||
328 | 328 | | |||
329 | //if(m_onlyShowTypes && decl->kind() != Declaration::Type && decl->kind() != Declaration::Namespace) | 329 | //if(m_onlyShowTypes && decl->kind() != Declaration::Type && decl->kind() != Declaration::Namespace) | ||
330 | //return false; | 330 | //return false; | ||
331 | 331 | | |||
332 | /*if(m_onlyShowSignals || m_onlyShowSlots) { | 332 | /*if(m_onlyShowSignals || m_onlyShowSlots) { | ||
333 | Cpp::QtFunctionDeclaration* qtFunction = dynamic_cast<Cpp::QtFunctionDeclaration*>(decl); | 333 | Cpp::QtFunctionDeclaration* qtFunction = dynamic_cast<Cpp::QtFunctionDeclaration*>(decl); | ||
334 | if(!qtFunction || (m_onlyShowSignals && !qtFunction->isSignal()) || (m_onlyShowSlots && !qtFunction->isSlot())) | 334 | if(!qtFunction || (m_onlyShowSignals && !qtFunction->isSignal()) || (m_onlyShowSlots && !qtFunction->isSlot())) | ||
Show All 24 Lines |