From 61351da56a4b781f1144586c718d295e1dd49433 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 25 Feb 2022 10:26:48 +0100 Subject: [PATCH] ClangCodeModel: Add convenience function ... for creating a highlighting result from a clangd AST node. Change-Id: Ie1fcfeee5d6b4c562143fce56498ce92a7b4fddb Reviewed-by: Qt CI Bot Reviewed-by: David Schulz Reviewed-by: --- src/plugins/clangcodemodel/clangdclient.cpp | 36 +++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 0d9eaa3fc10..1c3c2ad457b 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -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; }