forked from qt-creator/qt-creator
CppEditor: Improve "definition from declaration" for templates
- Make sure the template parameters are included in the definition. - Find the correct insertion location when using an already-defined template member function as an anchor. Fixes: QTCREATORBUG-24848 Change-Id: I1272ba36403904e7aed81bcef48745793c5e2217 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <cplusplus/ASTPath.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -545,6 +546,16 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
|
||||
return noResult;
|
||||
|
||||
targetFile->cppDocument()->translationUnit()->getTokenStartPosition(functionDefinition->firstToken(), &line, &column);
|
||||
const QList<AST *> path = ASTPath(targetFile->cppDocument())(line, column);
|
||||
for (auto it = path.rbegin(); it != path.rend(); ++it) {
|
||||
if (const auto templateDecl = (*it)->asTemplateDeclaration()) {
|
||||
if (templateDecl->declaration == functionDefinition) {
|
||||
targetFile->cppDocument()->translationUnit()->getTokenStartPosition(
|
||||
templateDecl->firstToken(), &line, &column);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return InsertionLocation(QString::fromUtf8(definitionFunction->fileName()), prefix, suffix, line, column);
|
||||
|
||||
Reference in New Issue
Block a user