Merge remote-tracking branch 'origin/9.0'

Change-Id: Ie069f3b2a1200b3e665341b1d56ce836024b0d29
This commit is contained in:
Eike Ziller
2022-11-10 13:01:31 +01:00
133 changed files with 50559 additions and 45242 deletions

View File

@@ -145,6 +145,20 @@ IAssistProcessor *ClangdCompletionAssistProvider::createProcessor(
default:
break;
}
if (interface->reason() == ActivationCharacter) {
switch (interface->characterAt(interface->position() - 1).toLatin1()) {
case '"': case '<': case '/':
if (contextAnalyzer.completionAction()
!= ClangCompletionContextAnalyzer::CompleteIncludePath) {
class NoOpProcessor : public IAssistProcessor {
IAssistProposal *perform(const AssistInterface *) override { return nullptr; }
};
return new NoOpProcessor;
}
}
}
const QString snippetsGroup = contextAnalyzer.addSnippets() && !isInCommentOrString(interface)
? CppEditor::Constants::CPP_SNIPPETS_GROUP_ID
: QString();
@@ -166,10 +180,11 @@ bool ClangdCompletionAssistProvider::isActivationCharSequence(const QString &seq
// We want to minimize unneeded completion requests, as those trigger document updates,
// which trigger re-highlighting and diagnostics, which we try to delay.
// Therefore, we do not trigger on syntax elements that often occur in non-applicable
// contexts, such as '(', '<' or '/'.
// Therefore, for '"', '<', and '/', a follow-up check will verify whether we are in
// an include completion context and otherwise not start the LSP completion procedure.
switch (kind) {
case T_DOT: case T_COLON_COLON: case T_ARROW: case T_DOT_STAR: case T_ARROW_STAR: case T_POUND:
case T_STRING_LITERAL: case T_ANGLE_STRING_LITERAL: case T_SLASH:
qCDebug(clangdLogCompletion) << "detected" << sequence << "as activation char sequence";
return true;
}
@@ -417,6 +432,7 @@ IAssistProposal *CustomAssistProcessor::perform(const AssistInterface *interface
break;
}
}
delete interface;
GenericProposalModelPtr model(new GenericProposalModel);
model->loadContent(completions);
const auto proposal = new GenericProposal(m_position, model);

View File

@@ -12,6 +12,7 @@
#include <languageclient/languageclientsymbolsupport.h>
#include <languageserverprotocol/lsptypes.h>
#include <languageserverprotocol/jsonrpcmessages.h>
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/iassistprovider.h>
#include <texteditor/textdocument.h>
@@ -41,8 +42,9 @@ public:
void resetData(bool resetFollowSymbolData);
private:
IAssistProposal *perform(const AssistInterface *) override
IAssistProposal *perform(const AssistInterface *interface) override
{
delete interface;
return nullptr;
}

View File

@@ -164,9 +164,15 @@ void doSemanticHighlighting(
const Position endPos = startPos.withOffset(token.length, &doc);
return Range(startPos, endPos);
};
const auto isOutputParameter = [&ast, &tokenRange](const ExpandedSemanticToken &token) {
const int clangdMajorVersion = clangdVersion.majorVersion();
const auto isOutputParameter = [&ast, &tokenRange, clangdMajorVersion]
(const ExpandedSemanticToken &token) {
if (token.modifiers.contains(QLatin1String("usedAsMutableReference")))
return true;
if (token.modifiers.contains(QLatin1String("usedAsMutablePointer")))
return true;
if (clangdMajorVersion >= 16)
return false;
if (token.type != "variable" && token.type != "property" && token.type != "parameter")
return false;
const Range range = tokenRange(token);
@@ -260,7 +266,7 @@ void doSemanticHighlighting(
};
const std::function<HighlightingResult(const ExpandedSemanticToken &)> toResult
= [&ast, &isOutputParameter, &tokenRange, ver = clangdVersion.majorVersion()]
= [&ast, &isOutputParameter, &tokenRange, clangdMajorVersion]
(const ExpandedSemanticToken &token) {
TextStyles styles;
if (token.type == "variable") {
@@ -277,7 +283,7 @@ void doSemanticHighlighting(
? C_VIRTUAL_METHOD : C_FUNCTION;
if (token.modifiers.contains("definition")) {
styles.mixinStyles.push_back(C_FUNCTION_DEFINITION);
} else if (ver < 16 && ast.isValid()) {
} else if (clangdMajorVersion < 16 && ast.isValid()) {
const ClangdAstPath path = getAstPath(ast, tokenRange(token));
if (path.length() > 1) {
const ClangdAstNode declNode = path.at(path.length() - 2);
@@ -291,7 +297,7 @@ void doSemanticHighlighting(
styles.mainStyle = C_TYPE;
if (token.modifiers.contains("constructorOrDestructor")) {
styles.mainStyle = C_FUNCTION;
} else if (ver < 16 && ast.isValid()) {
} else if (clangdMajorVersion < 16 && ast.isValid()) {
const ClangdAstPath path = getAstPath(ast, tokenRange(token));
if (!path.isEmpty()) {
if (path.last().kind() == "CXXConstructor") {

View File

@@ -13,6 +13,7 @@
#include <utils/qtcassert.h>
#include <QApplication>
#include <QMetaObject>
#include <QTextCursor>
#include <optional>
@@ -68,6 +69,7 @@ ClangdSwitchDeclDef::ClangdSwitchDeclDef(ClangdClient *client, TextDocument *doc
[this](const DocumentUri &uri, const DocumentSymbolsResult &symbols) {
if (uri != d->uri)
return;
d->client->documentSymbolCache()->disconnect(this);
d->docSymbols = symbols;
if (d->ast)
d->handleDeclDefSwitchReplies();
@@ -108,7 +110,7 @@ void ClangdSwitchDeclDef::emitDone()
return;
d->done = true;
emit done();
QMetaObject::invokeMethod(this, &ClangdSwitchDeclDef::done, Qt::QueuedConnection);
}
std::optional<ClangdAstNode> ClangdSwitchDeclDef::Private::getFunctionNode() const

View File

@@ -1021,12 +1021,6 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_LOCAL} << 0;
QTest::newRow("const pointer argument") << 491 << 26 << 491 << 27
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const reference via member function call as output argument (object)")
<< 580 << 29 << 580 << 30
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const reference via member function call as output argument (function)")
<< 580 << 31 << 580 << 37
<< QList<int>{C_FUNCTION, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("value argument") << 501 << 57 << 501 << 58
<< QList<int>{C_LOCAL} << 0;
QTest::newRow("non-const ref argument as second arg") << 501 << 61 << 501 << 62
@@ -1035,8 +1029,6 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_PARAMETER, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const pointer argument expression") << 513 << 30 << 513 << 31
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const ref argument from qualified member (object)") << 525 << 31 << 525 << 39
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const ref argument from qualified member (member)") << 525 << 40 << 525 << 46
<< QList<int>{C_FIELD, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("non-const ref argument to constructor") << 540 << 47 << 540 << 55
@@ -1403,14 +1395,6 @@ void ClangdTestHighlighting::test()
actualStyles << s;
}
QEXPECT_FAIL("non-const reference via member function call as output argument (object)",
"See below", Continue);
QEXPECT_FAIL("non-const reference via member function call as output argument (function)",
"Without punctuation and comment tokens from clangd, it's not possible "
"to highlight entire expressions. But do we really want this? What about nested "
"calls where the inner arguments are const?",
Continue);
QCOMPARE(actualStyles, expectedStyles);
QCOMPARE(result.kind, expectedKind);
}