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 += ' ';
|
||||
|
||||
@@ -209,6 +209,11 @@ bool ClangModelManagerSupport::supportsOutline(const TextEditor::TextDocument *d
|
||||
return !clientForFile(document->filePath());
|
||||
}
|
||||
|
||||
bool ClangModelManagerSupport::supportsLocalUses(const TextEditor::TextDocument *document) const
|
||||
{
|
||||
return !clientForFile(document->filePath());
|
||||
}
|
||||
|
||||
CppEditor::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument)
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
CppEditor::RefactoringEngineInterface &refactoringEngineInterface() override;
|
||||
std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override;
|
||||
bool supportsOutline(const TextEditor::TextDocument *document) const override;
|
||||
bool supportsLocalUses(const TextEditor::TextDocument *document) const override;
|
||||
|
||||
BackendCommunicator &communicator();
|
||||
QString dummyUiHeaderOnDiskDirPath() const;
|
||||
|
||||
@@ -1256,6 +1256,8 @@ void ClangdTestHighlighting::test_data()
|
||||
<< QList<int>{C_STRING} << 0;
|
||||
QTest::newRow("string literal passed to macro from header file") << 854 << 32 << 854 << 38
|
||||
<< QList<int>{C_STRING} << 0;
|
||||
QTest::newRow("user-defined operator call") << 860 << 7 << 860 << 8
|
||||
<< QList<int>{C_LOCAL} << 0;
|
||||
}
|
||||
|
||||
void ClangdTestHighlighting::test()
|
||||
|
||||
@@ -853,3 +853,9 @@ void useString()
|
||||
const char *s = USE_STRING("TEXT");
|
||||
s = USE_STRING_FROM_HEADER("TEXT");
|
||||
}
|
||||
|
||||
void useOperator()
|
||||
{
|
||||
struct S { S& operator++(); } s;
|
||||
++s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user