forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/7.0'
Change-Id: I809383e6c060701a2751197a8bf16add92bfaf0d
This commit is contained in:
@@ -1410,10 +1410,10 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
||||
setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold);
|
||||
|
||||
const auto textMarkCreator = [this](const Utils::FilePath &filePath,
|
||||
const Diagnostic &diag) {
|
||||
const Diagnostic &diag, bool isProjectFile) {
|
||||
if (d->isTesting)
|
||||
emit textMarkCreated(filePath);
|
||||
return new ClangdTextMark(filePath, diag, this);
|
||||
return new ClangdTextMark(filePath, diag, isProjectFile, this);
|
||||
};
|
||||
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
|
||||
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
|
||||
@@ -2652,6 +2652,7 @@ private:
|
||||
int posForNodeStart(const AstNode &node) const;
|
||||
int posForNodeEnd(const AstNode &node) const;
|
||||
void insertResult(const HighlightingResult &result);
|
||||
void insertResult(const AstNode &node, TextStyle style);
|
||||
void insertAngleBracketInfo(int searchStart1, int searchEnd1, int searchStart2, int searchEnd2);
|
||||
void setResultPosFromRange(HighlightingResult &result, const Range &range);
|
||||
void collectFromNode(const AstNode &node);
|
||||
@@ -3619,6 +3620,16 @@ void ExtraHighlightingResultsCollector::insertResult(const HighlightingResult &r
|
||||
}
|
||||
}
|
||||
|
||||
void ExtraHighlightingResultsCollector::insertResult(const AstNode &node, TextStyle style)
|
||||
{
|
||||
HighlightingResult result;
|
||||
result.useTextSyles = true;
|
||||
result.textStyles.mainStyle = style;
|
||||
setResultPosFromRange(result, node.range());
|
||||
insertResult(result);
|
||||
return;
|
||||
}
|
||||
|
||||
// For matching the "<" and ">" brackets of template declarations, specializations
|
||||
// and instantiations.
|
||||
void ExtraHighlightingResultsCollector::insertAngleBracketInfo(int searchStart1, int searchEnd1,
|
||||
@@ -3673,37 +3684,30 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
|
||||
if (node.kind() == "UserDefinedLiteral")
|
||||
return;
|
||||
if (node.kind().endsWith("Literal")) {
|
||||
HighlightingResult result;
|
||||
result.useTextSyles = true;
|
||||
const bool isKeyword = node.kind() == "CXXBoolLiteral"
|
||||
|| node.kind() == "CXXNullPtrLiteral";
|
||||
const bool isStringLike = !isKeyword && (node.kind().startsWith("String")
|
||||
|| node.kind().startsWith("Character"));
|
||||
result.textStyles.mainStyle = isKeyword ? C_KEYWORD : isStringLike ? C_STRING : C_NUMBER;
|
||||
setResultPosFromRange(result, node.range());
|
||||
insertResult(result);
|
||||
const TextStyle style = isKeyword ? C_KEYWORD : isStringLike ? C_STRING : C_NUMBER;
|
||||
insertResult(node, style);
|
||||
return;
|
||||
}
|
||||
if (node.role() == "type" && node.kind() == "Builtin") {
|
||||
HighlightingResult result;
|
||||
result.useTextSyles = true;
|
||||
result.textStyles.mainStyle = C_PRIMITIVE_TYPE;
|
||||
setResultPosFromRange(result, node.range());
|
||||
insertResult(result);
|
||||
insertResult(node, C_PRIMITIVE_TYPE);
|
||||
return;
|
||||
}
|
||||
if (node.role() == "attribute" && (node.kind() == "Override" || node.kind() == "Final")) {
|
||||
HighlightingResult result;
|
||||
result.useTextSyles = true;
|
||||
result.textStyles.mainStyle = C_KEYWORD;
|
||||
setResultPosFromRange(result, node.range());
|
||||
insertResult(result);
|
||||
insertResult(node, C_KEYWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool isExpression = node.role() == "expression";
|
||||
const bool isDeclaration = node.role() == "declaration";
|
||||
if (isExpression && node.kind() == "Predefined") {
|
||||
insertResult(node, C_PREPROCESSOR);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool isDeclaration = node.role() == "declaration";
|
||||
const int nodeStartPos = posForNodeStart(node);
|
||||
const int nodeEndPos = posForNodeEnd(node);
|
||||
const QList<AstNode> children = node.children().value_or(QList<AstNode>());
|
||||
|
||||
@@ -385,6 +385,7 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
|
||||
ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
||||
const Diagnostic &diagnostic,
|
||||
bool isProjectFile,
|
||||
const Client *client)
|
||||
: TextEditor::TextMark(filePath, int(diagnostic.range().start().line() + 1), client->id())
|
||||
, m_lspDiagnostic(diagnostic)
|
||||
@@ -399,18 +400,13 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
||||
setPriority(isError ? TextEditor::TextMark::HighPriority
|
||||
: TextEditor::TextMark::NormalPriority);
|
||||
setIcon(isError ? Icons::CODEMODEL_ERROR.icon() : Icons::CODEMODEL_WARNING.icon());
|
||||
if (client->project()) {
|
||||
if (isProjectFile) {
|
||||
setLineAnnotation(diagnostic.message());
|
||||
setColor(isError ? Theme::CodeModel_Error_TextMarkColor
|
||||
: Theme::CodeModel_Warning_TextMarkColor);
|
||||
ClangDiagnosticManager::addTask(m_diagnostic);
|
||||
}
|
||||
|
||||
m_clientDeleted = QObject::connect(client, &QObject::destroyed, [this] (){
|
||||
QTC_ASSERT_STRING("ClangdClient deleted before TextMark");
|
||||
delete this;
|
||||
});
|
||||
|
||||
// Copy to clipboard action
|
||||
QVector<QAction *> actions;
|
||||
QAction *action = new QAction();
|
||||
@@ -438,11 +434,6 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
||||
setActions(actions);
|
||||
}
|
||||
|
||||
ClangdTextMark::~ClangdTextMark()
|
||||
{
|
||||
QObject::disconnect(m_clientDeleted);
|
||||
}
|
||||
|
||||
bool ClangdTextMark::addToolTipContent(QLayout *target) const
|
||||
{
|
||||
const auto canApplyFixIt = [c = m_client, diag = m_lspDiagnostic, fp = fileName()] {
|
||||
|
||||
@@ -72,8 +72,8 @@ class ClangdTextMark : public TextEditor::TextMark
|
||||
public:
|
||||
ClangdTextMark(const ::Utils::FilePath &filePath,
|
||||
const LanguageServerProtocol::Diagnostic &diagnostic,
|
||||
bool isProjectFile,
|
||||
const LanguageClient::Client *client);
|
||||
~ClangdTextMark();
|
||||
|
||||
private:
|
||||
bool addToolTipContent(QLayout *target) const override;
|
||||
@@ -81,8 +81,6 @@ private:
|
||||
const LanguageServerProtocol::Diagnostic m_lspDiagnostic;
|
||||
const ClangBackEnd::DiagnosticContainer m_diagnostic;
|
||||
const QPointer<const LanguageClient::Client> m_client;
|
||||
|
||||
QMetaObject::Connection m_clientDeleted;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -1302,6 +1302,12 @@ void ClangdTestHighlighting::test_data()
|
||||
<< QList<int>{C_FIELD} << 0;
|
||||
QTest::newRow("output arg") << 945 << 20 << 945 << 23
|
||||
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
|
||||
QTest::newRow("built-in define 1") << 950 << 21 << 950 << 29
|
||||
<< QList<int>{C_PREPROCESSOR} << 0;
|
||||
QTest::newRow("built-in define 2") << 951 << 21 << 951 << 33
|
||||
<< QList<int>{C_PREPROCESSOR} << 0;
|
||||
QTest::newRow("built-in define 3") << 952 << 21 << 952 << 40
|
||||
<< QList<int>{C_PREPROCESSOR} << 0;
|
||||
}
|
||||
|
||||
void ClangdTestHighlighting::test()
|
||||
|
||||
@@ -944,3 +944,10 @@ void inputsAndOutputsFromObject(const WithVector &s)
|
||||
std::vector<int> out;
|
||||
transform(s.v, out, [] {});
|
||||
}
|
||||
|
||||
void builtinDefines()
|
||||
{
|
||||
const auto f1 = __func__;
|
||||
const auto f2 = __FUNCTION__;
|
||||
const auto f3 = __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user