diff --git a/src/CSharp/CSharp/Documentation/DocumentationCommentGenerator.cs b/src/CSharp/CSharp/Documentation/DocumentationCommentGenerator.cs index 135e4624d3..4ed6a42835 100644 --- a/src/CSharp/CSharp/Documentation/DocumentationCommentGenerator.cs +++ b/src/CSharp/CSharp/Documentation/DocumentationCommentGenerator.cs @@ -312,24 +312,30 @@ private static SyntaxTriviaList Generate( sb.AppendLine("/// "); } - foreach (TypeParameterSyntax typeParameter in typeParameters) + if (!settings.IsTagIgnored(WellKnownXmlTags.TypeParam)) { - sb.Append(settings.Indentation); - sb.Append("/// "); + foreach (TypeParameterSyntax typeParameter in typeParameters) + { + sb.Append(settings.Indentation); + sb.Append("/// "); + } } - foreach (ParameterSyntax parameter in parameters) + if (!settings.IsTagIgnored(WellKnownXmlTags.Param)) { - sb.Append(settings.Indentation); - sb.Append("/// "); + foreach (ParameterSyntax parameter in parameters) + { + sb.Append(settings.Indentation); + sb.Append("/// "); + } } if (canGenerateReturns - && settings.Returns) + && !settings.IsTagIgnored(WellKnownXmlTags.Returns)) { sb.Append(settings.Indentation); sb.AppendLine("/// "); diff --git a/src/CodeFixes/CSharp/Refactorings/AddDocumentationCommentRefactoring.cs b/src/CodeFixes/CSharp/Refactorings/AddDocumentationCommentRefactoring.cs index 97d98d1066..bcced67104 100644 --- a/src/CodeFixes/CSharp/Refactorings/AddDocumentationCommentRefactoring.cs +++ b/src/CodeFixes/CSharp/Refactorings/AddDocumentationCommentRefactoring.cs @@ -1,5 +1,8 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Immutable; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -11,6 +14,8 @@ namespace Roslynator.CSharp.Refactorings { internal static class AddDocumentationCommentRefactoring { + private static readonly string[] _tagSeparator = new[] { "," }; + public static async Task RefactorAsync( Document document, MemberDeclarationSyntax memberDeclaration, @@ -34,7 +39,23 @@ public static async Task RefactorAsync( } } - newNode ??= memberDeclaration.WithNewSingleLineDocumentationComment(); + DocumentationCommentGeneratorSettings settings = DocumentationCommentGeneratorSettings.Default; + + if (document.TryGetAnalyzerOptionValue( + memberDeclaration, + CodeFixOptions.CS1591_MissingXmlCommentForPubliclyVisibleTypeOrMember_IgnoredTags, + out string value)) + { + ImmutableArray ignoredTags = value + .Split(_tagSeparator, StringSplitOptions.RemoveEmptyEntries) + .Select(f => f.Trim()) + .Where(f => f.Length > 0) + .ToImmutableArray(); + + settings = new DocumentationCommentGeneratorSettings(ignoredTags: ignoredTags); + } + + newNode ??= memberDeclaration.WithNewSingleLineDocumentationComment(settings); return await document.ReplaceNodeAsync(memberDeclaration, newNode, cancellationToken).ConfigureAwait(false); } diff --git a/src/Core/Documentation/DocumentationCommentGeneratorSettings.cs b/src/Core/Documentation/DocumentationCommentGeneratorSettings.cs index b4f1a4120e..4dfe80c822 100644 --- a/src/Core/Documentation/DocumentationCommentGeneratorSettings.cs +++ b/src/Core/Documentation/DocumentationCommentGeneratorSettings.cs @@ -9,33 +9,38 @@ internal class DocumentationCommentGeneratorSettings { public DocumentationCommentGeneratorSettings( IEnumerable summary = null, + IEnumerable ignoredTags = null, string indentation = null, - bool singleLineSummary = false, - bool returns = true) + bool singleLineSummary = false) { Summary = (summary != null) ? ImmutableArray.CreateRange(summary) : ImmutableArray.Empty; + IgnoredTags = ignoredTags?.ToImmutableArray() ?? ImmutableArray.Empty; Indentation = indentation ?? ""; SingleLineSummary = singleLineSummary; - Returns = returns; } public static DocumentationCommentGeneratorSettings Default { get; } = new DocumentationCommentGeneratorSettings(); + public ImmutableArray IgnoredTags { get; } + public ImmutableArray Summary { get; } public string Indentation { get; } public bool SingleLineSummary { get; } - public bool Returns { get; } + public bool IsTagIgnored(string tag) + { + return IgnoredTags.Contains(tag); + } public DocumentationCommentGeneratorSettings WithIndentation(string indentation) { return new DocumentationCommentGeneratorSettings( summary: Summary, + ignoredTags: IgnoredTags, indentation: indentation, - singleLineSummary: SingleLineSummary, - returns: Returns); + singleLineSummary: SingleLineSummary); } } } diff --git a/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs b/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs index 910e89098c..fd4eec624d 100644 --- a/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs @@ -69,6 +69,7 @@ private static IEnumerable CreateMembers(IEnumerable f))})" }, + ignoredTags: new[] { "returns", "value" }, indentation: " ", singleLineSummary: true); diff --git a/src/Tools/CodeGeneration/CSharp/CompilerDiagnosticDescriptorsGenerator.cs b/src/Tools/CodeGeneration/CSharp/CompilerDiagnosticDescriptorsGenerator.cs index 8411e92f72..6f4266b542 100644 --- a/src/Tools/CodeGeneration/CSharp/CompilerDiagnosticDescriptorsGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CompilerDiagnosticDescriptorsGenerator.cs @@ -79,6 +79,7 @@ private static IEnumerable CreateMembers(IEnumerable