forked from qt-creator/qt-creator
ClangCodeModel: Add convenience function
... for creating a highlighting result from a clangd AST node. Change-Id: Ie1fcfeee5d6b4c562143fce56498ce92a7b4fddb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -2548,6 +2548,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);
|
||||
@@ -3515,6 +3516,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,
|
||||
@@ -3569,41 +3580,26 @@ 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";
|
||||
if (isExpression && node.kind() == "Predefined") {
|
||||
HighlightingResult result;
|
||||
result.useTextSyles = true;
|
||||
result.textStyles.mainStyle = C_PREPROCESSOR;
|
||||
setResultPosFromRange(result, node.range());
|
||||
insertResult(result);
|
||||
insertResult(node, C_PREPROCESSOR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user