diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2023-08-31 16:14:40 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-09-04 12:45:23 +0000 |
commit | 6847d69008952837831b14302e13c3dd0a60146b (patch) | |
tree | 328634f0063c56485862928a26788cbcb4c931af /src/plugins/cppeditor/cppquickfixes.cpp | |
parent | 429da62c1a54607fc2e784cae058cdbc3196bbe4 (diff) |
CppEditor: Consider comments when extracting a new function
That is, do not place the newly created function in between the function
and its comment.
Fixes: QTCREATORBUG-6934
Change-Id: I79f564a90c7e3c45188f5d694cbde47029651324
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppquickfixes.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppquickfixes.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 727f0c8497..5bf8269af4 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -27,6 +27,7 @@ #include <cplusplus/ASTPath.h> #include <cplusplus/CPlusPlusForwardDeclarations.h> #include <cplusplus/CppRewriter.h> +#include <cplusplus/declarationcomments.h> #include <cplusplus/NamePrettyPrinter.h> #include <cplusplus/TypeOfExpression.h> #include <cplusplus/TypePrettyPrinter.h> @@ -5150,6 +5151,16 @@ public: // formatting) it's simpler to have two different change sets. ChangeSet change; int position = currentFile->startOf(m_refFuncDef); + + // Do not insert right between the function and an associated comment. + const QList<Token> functionDoc = commentsForDeclaration( + m_refFuncDef->symbol, m_refFuncDef, *currentFile->document(), + currentFile->cppDocument()); + if (!functionDoc.isEmpty()) { + position = currentFile->cppDocument()->translationUnit()->getTokenPositionInDocument( + functionDoc.first(), currentFile->document()); + } + change.insert(position, funcDef); change.replace(m_extractionStart, m_extractionEnd, funcCall); currentFile->setChangeSet(change); |