forked from qt-creator/qt-creator
Clang: Do not add parentheses when completing "using N::function"
Task-number: QTCREATORBUG-17444 Change-Id: I7a99d35af9e6471b0d4ebe19385727247b31efb7 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
committed by
Marco Bubke
parent
a951448c4d
commit
8d847daa4b
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
#include <cplusplus/MatchingText.h>
|
||||
#include <cplusplus/SimpleLexer.h>
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
#include <texteditor/completionsettings.h>
|
||||
@@ -36,6 +37,8 @@
|
||||
|
||||
#include <QTextCursor>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace ClangBackEnd;
|
||||
|
||||
@@ -74,6 +77,43 @@ static void moveToPrevChar(TextEditor::TextDocumentManipulatorInterface &manipul
|
||||
cursor.movePosition(QTextCursor::PreviousCharacter);
|
||||
}
|
||||
|
||||
static QString textUntilPreviousStatement(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
int startPosition)
|
||||
{
|
||||
static const QString stopCharacters(";{}#");
|
||||
|
||||
int endPosition = 0;
|
||||
for (int i = startPosition; i >= 0 ; --i) {
|
||||
if (stopCharacters.contains(manipulator.characterAt(i))) {
|
||||
endPosition = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return manipulator.textAt(endPosition, startPosition - endPosition);
|
||||
}
|
||||
|
||||
// 7.3.3: using typename(opt) nested-name-specifier unqualified-id ;
|
||||
static bool isAtUsingDeclaration(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
int basePosition)
|
||||
{
|
||||
SimpleLexer lexer;
|
||||
lexer.setLanguageFeatures(LanguageFeatures::defaultFeatures());
|
||||
const QString textToLex = textUntilPreviousStatement(manipulator, basePosition);
|
||||
const Tokens tokens = lexer(textToLex);
|
||||
if (tokens.empty())
|
||||
return false;
|
||||
|
||||
// The nested-name-specifier always ends with "::", so check for this first.
|
||||
const Token lastToken = tokens[tokens.size() - 1];
|
||||
if (lastToken.kind() != T_COLON_COLON)
|
||||
return false;
|
||||
|
||||
return Utils::contains(tokens, [](const Token &token) {
|
||||
return token.kind() == T_USING;
|
||||
});
|
||||
}
|
||||
|
||||
void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
int basePosition) const
|
||||
{
|
||||
@@ -133,6 +173,8 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
const QChar prevChar = manipulator.characterAt(cursor.position());
|
||||
abandonParen = QString("(;,{}").contains(prevChar);
|
||||
}
|
||||
if (!abandonParen)
|
||||
abandonParen = isAtUsingDeclaration(manipulator, basePosition);
|
||||
if (!abandonParen) {
|
||||
if (completionSettings.m_spaceAfterFunctionName)
|
||||
extraCharacters += QLatin1Char(' ');
|
||||
|
||||
Reference in New Issue
Block a user