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:
Christian Kandeler
2022-02-25 10:26:48 +01:00
parent 64a1bf6c43
commit 61351da56a

View File

@@ -2548,6 +2548,7 @@ private:
int posForNodeStart(const AstNode &node) const; int posForNodeStart(const AstNode &node) const;
int posForNodeEnd(const AstNode &node) const; int posForNodeEnd(const AstNode &node) const;
void insertResult(const HighlightingResult &result); void insertResult(const HighlightingResult &result);
void insertResult(const AstNode &node, TextStyle style);
void insertAngleBracketInfo(int searchStart1, int searchEnd1, int searchStart2, int searchEnd2); void insertAngleBracketInfo(int searchStart1, int searchEnd1, int searchStart2, int searchEnd2);
void setResultPosFromRange(HighlightingResult &result, const Range &range); void setResultPosFromRange(HighlightingResult &result, const Range &range);
void collectFromNode(const AstNode &node); 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 // For matching the "<" and ">" brackets of template declarations, specializations
// and instantiations. // and instantiations.
void ExtraHighlightingResultsCollector::insertAngleBracketInfo(int searchStart1, int searchEnd1, void ExtraHighlightingResultsCollector::insertAngleBracketInfo(int searchStart1, int searchEnd1,
@@ -3569,41 +3580,26 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
if (node.kind() == "UserDefinedLiteral") if (node.kind() == "UserDefinedLiteral")
return; return;
if (node.kind().endsWith("Literal")) { if (node.kind().endsWith("Literal")) {
HighlightingResult result;
result.useTextSyles = true;
const bool isKeyword = node.kind() == "CXXBoolLiteral" const bool isKeyword = node.kind() == "CXXBoolLiteral"
|| node.kind() == "CXXNullPtrLiteral"; || node.kind() == "CXXNullPtrLiteral";
const bool isStringLike = !isKeyword && (node.kind().startsWith("String") const bool isStringLike = !isKeyword && (node.kind().startsWith("String")
|| node.kind().startsWith("Character")); || node.kind().startsWith("Character"));
result.textStyles.mainStyle = isKeyword ? C_KEYWORD : isStringLike ? C_STRING : C_NUMBER; const TextStyle style = isKeyword ? C_KEYWORD : isStringLike ? C_STRING : C_NUMBER;
setResultPosFromRange(result, node.range()); insertResult(node, style);
insertResult(result);
return; return;
} }
if (node.role() == "type" && node.kind() == "Builtin") { if (node.role() == "type" && node.kind() == "Builtin") {
HighlightingResult result; insertResult(node, C_PRIMITIVE_TYPE);
result.useTextSyles = true;
result.textStyles.mainStyle = C_PRIMITIVE_TYPE;
setResultPosFromRange(result, node.range());
insertResult(result);
return; return;
} }
if (node.role() == "attribute" && (node.kind() == "Override" || node.kind() == "Final")) { if (node.role() == "attribute" && (node.kind() == "Override" || node.kind() == "Final")) {
HighlightingResult result; insertResult(node, C_KEYWORD);
result.useTextSyles = true;
result.textStyles.mainStyle = C_KEYWORD;
setResultPosFromRange(result, node.range());
insertResult(result);
return; return;
} }
const bool isExpression = node.role() == "expression"; const bool isExpression = node.role() == "expression";
if (isExpression && node.kind() == "Predefined") { if (isExpression && node.kind() == "Predefined") {
HighlightingResult result; insertResult(node, C_PREPROCESSOR);
result.useTextSyles = true;
result.textStyles.mainStyle = C_PREPROCESSOR;
setResultPosFromRange(result, node.range());
insertResult(result);
return; return;
} }