diff --git a/languages/clang/codecompletion/context.cpp b/languages/clang/codecompletion/context.cpp --- a/languages/clang/codecompletion/context.cpp +++ b/languages/clang/codecompletion/context.cpp @@ -22,10 +22,15 @@ #include "context.h" +#include +#include + #include #include +#include #include +#include #include #include @@ -160,7 +165,30 @@ void execute(KTextEditor::View* view, const KTextEditor::Range& word) override { - view->document()->replaceText(word, m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()) + QLatin1String(" override;")); + auto documentPath = Path(view->document()->url()); + auto project = ICore::self()->projectController()->findProjectForUrl(view->document()->url()); + + auto grp = project->projectConfiguration()->group(QLatin1String( "CustomDefinesAndIncludes" )); + QString argumentsCpp = QLatin1String( "c++11" ); + Path lastPath; + for( const QString &grpName : grp.groupList() ) { + KConfigGroup pathgrp = grp.group( grpName ); + auto path = Path(project->path(), pathgrp.readEntry( QLatin1String( "Path" ), "" )); + + if (path.isDirectParentOf(documentPath) || (path.isParentOf(documentPath) + && ((!lastPath.isEmpty() && lastPath.isParentOf(path)) + || lastPath.isEmpty()))) { + argumentsCpp = pathgrp.readEntry("parserArguments", "c++11"); + if (argumentsCpp.isEmpty()) + argumentsCpp = QLatin1String( "c++11" ); + lastPath = path; + if (path.isDirectParentOf(documentPath)) + break; + } + } + auto currentStandard = QRegularExpression(QStringLiteral("c\\+\\+\\d{2}")).match(argumentsCpp).captured(); + view->document()->replaceText(word, m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()) + + (currentStandard == QStringLiteral("c++03") ? QLatin1String(";") : QLatin1String(" override;"))); } private: