From 256632a07e99d94e949d0c190f9a0f3de8e39ed1 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 23 Dec 2022 02:47:34 +0100 Subject: C#: Skip documentation syntax in MustBeVariant analyzer --- .../MustBeVariantAnalyzer.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'modules/mono/editor') diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs index 98ca534c66..2a9758516c 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs @@ -26,6 +26,10 @@ namespace Godot.SourceGenerators private void AnalyzeNode(SyntaxNodeAnalysisContext context) { + // Ignore syntax inside comments + if (IsInsideDocumentation(context.Node)) + return; + var typeArgListSyntax = (TypeArgumentListSyntax)context.Node; // Method invocation or variable declaration that contained the type arguments @@ -73,6 +77,26 @@ namespace Godot.SourceGenerators } } + /// + /// Check if the syntax node is inside a documentation syntax. + /// + /// Syntax node to check. + /// if the syntax node is inside a documentation syntax. + private bool IsInsideDocumentation(SyntaxNode? syntax) + { + while (syntax != null) + { + if (syntax is DocumentationCommentTriviaSyntax) + { + return true; + } + + syntax = syntax.Parent; + } + + return false; + } + /// /// Check if the given type argument is being used in a type parameter that contains /// the MustBeVariantAttribute; otherwise, we ignore the attribute. -- cgit v1.2.3