forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/6.0'
Change-Id: I0eae76ecff1a315877e4fdd471f0de3a3a55f180
This commit is contained in:
@@ -2518,8 +2518,10 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
||||
while (!firstChildTree.isEmpty()) {
|
||||
const AstNode n = firstChildTree.takeFirst();
|
||||
const QString detail = n.detail().value_or(QString());
|
||||
if (detail.startsWith("operator"))
|
||||
return !detail.contains('=');
|
||||
if (detail.startsWith("operator")) {
|
||||
return !detail.contains('=') && !detail.contains("++")
|
||||
&& !detail.contains("--");
|
||||
}
|
||||
firstChildTree << n.children().value_or(QList<AstNode>());
|
||||
}
|
||||
return true;
|
||||
@@ -2965,19 +2967,27 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator,
|
||||
if (!edit)
|
||||
return;
|
||||
|
||||
const int labelOpenParenOffset = item.label().indexOf('(');
|
||||
const int labelClosingParenOffset = item.label().indexOf(')');
|
||||
const auto kind = static_cast<CompletionItemKind::Kind>(
|
||||
item.kind().value_or(CompletionItemKind::Text));
|
||||
const bool isMacroCall = kind == CompletionItemKind::Text && labelOpenParenOffset != -1
|
||||
&& labelClosingParenOffset > labelOpenParenOffset; // Heuristic
|
||||
const bool isFunctionLike = kind == CompletionItemKind::Function
|
||||
|| kind == CompletionItemKind::Method || kind == CompletionItemKind::Constructor;
|
||||
|| kind == CompletionItemKind::Method || kind == CompletionItemKind::Constructor
|
||||
|| isMacroCall;
|
||||
|
||||
QString rawInsertText = edit->newText();
|
||||
|
||||
// Some preparation for our magic involving (non-)insertion of parentheses and
|
||||
// cursor placement.
|
||||
if (isFunctionLike && !rawInsertText.contains('(')) {
|
||||
if (item.label().contains("()")) // function takes no arguments
|
||||
rawInsertText += "()";
|
||||
else if (item.label().contains('(')) // function takes arguments
|
||||
rawInsertText += "( )";
|
||||
if (labelOpenParenOffset != -1) {
|
||||
if (labelClosingParenOffset == labelOpenParenOffset + 1) // function takes no arguments
|
||||
rawInsertText += "()";
|
||||
else // function takes arguments
|
||||
rawInsertText += "( )";
|
||||
}
|
||||
}
|
||||
|
||||
const int firstParenOffset = rawInsertText.indexOf('(');
|
||||
@@ -3010,8 +3020,8 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator,
|
||||
}
|
||||
if (!abandonParen)
|
||||
abandonParen = isAtUsingDeclaration(manipulator, rangeStart);
|
||||
if (!abandonParen && matchPreviousWord(manipulator, cursor, detail)) // function definition?
|
||||
abandonParen = true;
|
||||
if (!abandonParen && !isMacroCall && matchPreviousWord(manipulator, cursor, detail))
|
||||
abandonParen = true; // function definition
|
||||
if (!abandonParen) {
|
||||
if (completionSettings.m_spaceAfterFunctionName)
|
||||
extraCharacters += ' ';
|
||||
|
||||
Reference in New Issue
Block a user