From 06bdf9bcd66aae00bf241b592e50d6ed449d1d8c Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 3 May 2025 09:55:44 -0700 Subject: [PATCH 01/32] Upgrade nuget packages --- .../CodeDocumentor.Test.csproj | 24 +++++++++---------- CodeDocumentor/CodeDocumentor.csproj | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index 214ca35..57410c4 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -445,27 +445,27 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + compile; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CodeDocumentor/CodeDocumentor.csproj b/CodeDocumentor/CodeDocumentor.csproj index 96e9b0c..3cc87c7 100644 --- a/CodeDocumentor/CodeDocumentor.csproj +++ b/CodeDocumentor/CodeDocumentor.csproj @@ -124,10 +124,10 @@ - + compile; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -135,14 +135,14 @@ 13.0.3 - 5.4.4 + 5.5.0 8.0.0 - - - + + + From 902736c22ef025edbbc1685ba1332ab2b7ac471e Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 3 May 2025 09:56:03 -0700 Subject: [PATCH 02/32] added check for parts array --- CodeDocumentor/Helper/CommentHelper.cs | 51 +++++++++++++++----------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/CodeDocumentor/Helper/CommentHelper.cs b/CodeDocumentor/Helper/CommentHelper.cs index 16fed5d..593a671 100644 --- a/CodeDocumentor/Helper/CommentHelper.cs +++ b/CodeDocumentor/Helper/CommentHelper.cs @@ -35,7 +35,7 @@ public static string CreateClassComment(string name) .TranslateParts() .TryInsertTheWord((parts) => { - if (!parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) + if (parts.Count > 0 && !parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) { parts.Insert(0, "The"); //for records we always force "The" } @@ -113,7 +113,7 @@ public static string CreateFieldComment(string name) .HandleAsyncKeyword() .Tap((parts) => { - if (char.IsLower(parts[0], 0)) //if first letter of a field is lower its prob a private field. Lets adjust for it + if (parts.Count > 0 && char.IsLower(parts[0], 0)) //if first letter of a field is lower its prob a private field. Lets adjust for it { parts[0] = parts[0].ToTitleCase(); } @@ -243,7 +243,7 @@ public static string CreateParameterComment(ParameterSyntax parameter) .TranslateParts() .TryInsertTheWord((parts) => { - if (!parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) + if (parts.Count > 0 && !parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) { parts.Insert(0, "The"); //for parameters we always force "The" } @@ -318,7 +318,7 @@ public static string CreateRecordComment(string name) .TranslateParts() .TryInsertTheWord((parts) => { - if (!parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) + if (parts.Count > 0 && !parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase)) { parts.Insert(0, "The"); //for records we always force "The" } @@ -410,6 +410,7 @@ internal static List ToLowerParts(this List parts, bool forceFir { var i = forceFirstCharToLower || ( + parts.Count > 0 && !parts[0].Equals("The", StringComparison.InvariantCultureIgnoreCase) && !parts[0].Equals("If true,", StringComparison.InvariantCultureIgnoreCase) && !parts[0].IsVerb() //if the first word is a verb we are not adding The anyway so we need to leave it Pascal @@ -426,7 +427,7 @@ internal static List ToLowerParts(this List parts, bool forceFir }, i); //First letter is always caps unless it was forced lower - if (!forceFirstCharToLower && char.IsLower(parts[0], 0)) + if (!forceFirstCharToLower && parts.Count > 0 && char.IsLower(parts[0], 0)) { parts[0] = parts[0].ToTitleCase(); } @@ -463,7 +464,7 @@ internal static List TryInsertTheWord(this List parts, Action
  • 0) { var checkWord = parts[0].GetWordFirstPart(); var skipThe = checkWord.IsVerb(); @@ -485,19 +486,22 @@ internal static List TryInsertTheWord(this List parts, Action
  • AddPropertyBooleanPart(this List parts) { - var booleanPart = " a value indicating whether to"; - if (parts[0].IsPastTense() || parts[0].IsVerb()) + if (parts.Count > 0) { - booleanPart = "a value indicating whether"; - } + var booleanPart = " a value indicating whether to"; + if (parts[0].IsPastTense() || parts[0].IsVerb()) + { + booleanPart = "a value indicating whether"; + } - //is messes up readability. Lets remove it. ex) IsEnabledForDays - var isTwoLettweWord = parts[0].IsTwoLetterPropertyExclusionVerb();//we only care if forst word is relavent - if (isTwoLettweWord) - { - parts.Remove(parts[0]); + //is messes up readability. Lets remove it. ex) IsEnabledForDays + var isTwoLettweWord = parts[0].IsTwoLetterPropertyExclusionVerb();//we only care if forst word is relavent + if (isTwoLettweWord) + { + parts.Remove(parts[0]); + } + parts.Insert(0, booleanPart); } - parts.Insert(0, booleanPart); return parts; } @@ -597,13 +601,16 @@ private static List TryIncudeReturnType(this List parts, TypeSyn private static List TryPluarizeFirstWord(this List parts) { - if (parts.Count >= 2) + if (parts.Count > 0) { - parts[0] = Pluralizer.Pluralize(parts[0], parts[1]); - } - else - { - parts[0] = Pluralizer.Pluralize(parts[0]); + if (parts.Count >= 2) + { + parts[0] = Pluralizer.Pluralize(parts[0], parts[1]); + } + else + { + parts[0] = Pluralizer.Pluralize(parts[0]); + } } return parts; } From 58689a4e5123ed983fdf3cb522ddc369282f0983 Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 3 May 2025 09:56:20 -0700 Subject: [PATCH 03/32] bumped version --- .github/workflows/dotnet.yml | 4 ++-- Manifests/vs2022/source.extension.vsixmanifest | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e9432e4..6cdb818 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -29,8 +29,8 @@ env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_NOLOGO: true VisxDirectory: ${{github.workspace}}/vsix - Version: '2.1.0.${{ github.run_number }}' - BaseVersion: '2.1.0.0' + Version: '2.1.1.${{ github.run_number }}' + BaseVersion: '2.1.1.0' defaults: run: diff --git a/Manifests/vs2022/source.extension.vsixmanifest b/Manifests/vs2022/source.extension.vsixmanifest index 8111fa9..8966d9f 100644 --- a/Manifests/vs2022/source.extension.vsixmanifest +++ b/Manifests/vs2022/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + CodeDocumentor An Extension to generate XML documentation automatically using IntelliSense for interface,class,enum, field, constructor, property and method. logo.png From dcb12fcb62a0103e7e9a3ae6e2dc250f4486b44a Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 3 May 2025 16:07:23 -0700 Subject: [PATCH 04/32] checkpoint --- .../CodeDocumentor.Test.csproj | 16 +++++ .../Methods/MethodUnitTests.cs | 20 +++--- .../Crefs/MethodWithNullableReturnTestCode.cs | 14 +++++ .../MethodWithNullableReturnTestFixCode.cs | 18 ++++++ .../MethodWithNullableStringReturnTestCode.cs | 14 +++++ ...thodWithNullableStringReturnTestFixCode.cs | 18 ++++++ .../Builders/DocumentationBuilder.cs | 2 +- .../BaseReturnTypeCommentConstruction.cs | 62 ++++++++++++++++--- 8 files changed, 144 insertions(+), 20 deletions(-) create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestCode.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestCode.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index 57410c4..c4b9705 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -38,6 +38,10 @@ + + + + @@ -166,15 +170,27 @@ Always + + Always + Always + + Always + Always + + Always + Always + + Always + Always diff --git a/CodeDocumentor.Test/Methods/MethodUnitTests.cs b/CodeDocumentor.Test/Methods/MethodUnitTests.cs index 146bba3..48440b0 100644 --- a/CodeDocumentor.Test/Methods/MethodUnitTests.cs +++ b/CodeDocumentor.Test/Methods/MethodUnitTests.cs @@ -91,15 +91,17 @@ public async Task ShowMethodDiagnosticAndFix(string testCode, string fixCode, in [Theory] - [InlineData("MethodWithStringReturnTestCode", "MethodWithStringReturnTestFixCode", 9, 23)] - [InlineData("MethodWithReturnTestCode", "MethodWithReturnTestFixCode", 9, 29)] - [InlineData("MethodWithObjectReturnTestCode", "MethodWithObjectReturnTestFixCode", 9, 23)] - [InlineData("MethodWithIntReturnTestCode", "MethodWithIntReturnTestFixCode", 9, 20)] - [InlineData("MethodWithCrefTestCode", "MethodWithCrefTestFixCode", 10, 35, false)] - [InlineData("MethodWithCrefTestCodeNaturalLang", "MethodWithCrefTestFixCodeNaturalLang", 10, 35)] - [InlineData("MethodWithExceptionTestCode", "MethodWithExceptionTestFixCode", 9, 23)] - [InlineData("MethodWithInlineExceptionTestCode", "MethodWithInlineExceptionTestFixCode", 9, 23)] - [InlineData("MethodWithMixedExceptionTestCode", "MethodWithMixedExceptionTestFixCode", 9, 23)] + //[InlineData("MethodWithNullableReturnTestCode", "MethodWithNullableReturnTestFixCode", 9, 30)] + [InlineData("MethodWithNullableStringReturnTestCode", "MethodWithNullableStringReturnTestFixCode", 9, 24)] + //[InlineData("MethodWithStringReturnTestCode", "MethodWithStringReturnTestFixCode", 9, 23)] + //[InlineData("MethodWithReturnTestCode", "MethodWithReturnTestFixCode", 9, 29)] + //[InlineData("MethodWithObjectReturnTestCode", "MethodWithObjectReturnTestFixCode", 9, 23)] + //[InlineData("MethodWithIntReturnTestCode", "MethodWithIntReturnTestFixCode", 9, 20)] + //[InlineData("MethodWithCrefTestCode", "MethodWithCrefTestFixCode", 10, 35, false)] + //[InlineData("MethodWithCrefTestCodeNaturalLang", "MethodWithCrefTestFixCodeNaturalLang", 10, 35)] + //[InlineData("MethodWithExceptionTestCode", "MethodWithExceptionTestFixCode", 9, 23)] + //[InlineData("MethodWithInlineExceptionTestCode", "MethodWithInlineExceptionTestFixCode", 9, 23)] + //[InlineData("MethodWithMixedExceptionTestCode", "MethodWithMixedExceptionTestFixCode", 9, 23)] public async Task ShowMethodDiagnosticAndFixWhenCrefsIsTrue(string testCode, string fixCode, int line, int column, bool useNaturalLanguageForReturnNode = true) { var fix = _fixture.LoadTestFile($"./Methods/TestFiles/Crefs/{fixCode}.cs"); diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestCode.cs new file mode 100644 index 0000000..5e46490 --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestCode.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + public MethodTester? ShowMethodWithReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs new file mode 100644 index 0000000..fe06cfc --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + /// + /// Show method with return tester. + /// + /// A nullable + public MethodTester? ShowMethodWithReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestCode.cs new file mode 100644 index 0000000..be31c4e --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestCode.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + public string? ShowMethodWithStringReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs new file mode 100644 index 0000000..6d136aa --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + /// + /// Show method with string return tester. + /// + /// A nullable + public string? ShowMethodWithStringReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor/Builders/DocumentationBuilder.cs b/CodeDocumentor/Builders/DocumentationBuilder.cs index 91d9f0f..db04501 100644 --- a/CodeDocumentor/Builders/DocumentationBuilder.cs +++ b/CodeDocumentor/Builders/DocumentationBuilder.cs @@ -108,7 +108,7 @@ internal DocumentationBuilder WithPropertyValueTypes(BasePropertyDeclarationSynt internal DocumentationBuilder WithReturnType(MethodDeclarationSyntax declarationSyntax) { - var returnType = declarationSyntax.ReturnType.ToString(); + var returnType = declarationSyntax.ReturnType.ToString().Replace("?",string.Empty); if (returnType != "void") { var commentConstructor = new ReturnCommentConstruction(declarationSyntax.ReturnType); diff --git a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs b/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs index 9364aa1..d6aec60 100644 --- a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs +++ b/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs @@ -37,6 +37,7 @@ public abstract class BaseReturnTypeCommentConstruction /// The comment internal virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOptions options) { + var returnComment = string.Empty; if (returnType is IdentifierNameSyntax identifier) { var parent = GetMethodDeclarationSyntax(returnType); @@ -48,32 +49,73 @@ internal virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOpt var startWord = DocumentationHeaderHelper.DetermineStartingWord(identifier.Identifier.ValueText.AsSpan(), options.UseProperCasing); if (!string.IsNullOrEmpty(startWord)) { - return $"{startWord} {typeParamNode.ToFullString()}"; + returnComment = $"{startWord} {typeParamNode.ToFullString()}"; } + else + { + returnComment = typeParamNode.ToFullString(); + } + } + else + { + returnComment = typeParamNode.ToFullString(); } - return typeParamNode.ToFullString(); } - return GenerateGeneralComment(identifier.Identifier.ValueText.AsSpan(), options); + else + { + returnComment = GenerateGeneralComment(identifier.Identifier.ValueText.AsSpan(), options); + } } - if (returnType is QualifiedNameSyntax qst) + else if (returnType is NullableTypeSyntax nts) { - return GenerateGeneralComment(qst.ToString().AsSpan(), options); + returnComment = BuildComment(nts.ElementType, options); } - if (returnType is GenericNameSyntax gst) + else if (returnType is QualifiedNameSyntax qst) { - return GenerateGenericTypeComment(gst, options); + returnComment = GenerateGeneralComment(qst.ToString().AsSpan(), options); } - if (returnType is ArrayTypeSyntax ast) + else if (returnType is GenericNameSyntax gst) + { + returnComment = GenerateGenericTypeComment(gst, options); + } + else if (returnType is ArrayTypeSyntax ast) { var comment = string.Format(ArrayCommentTemplate, DocumentationHeaderHelper.DetermineSpecificObjectName(ast.ElementType, options.TryToIncludeCrefsForReturnTypes)); var arrayOptions = options.Clone(); arrayOptions.IncludeStartingWordInText = true; arrayOptions.TryToIncludeCrefsForReturnTypes = false; - return GenerateGeneralComment(comment.AsSpan(), arrayOptions); + returnComment = GenerateGeneralComment(comment.AsSpan(), arrayOptions); } - return returnType is PredefinedTypeSyntax pst + else + { + returnComment = returnType is PredefinedTypeSyntax pst ? GenerateGeneralComment(pst.Keyword.ValueText.AsSpan(), options) : GenerateGeneralComment(returnType.ToFullString().AsSpan(), options); + } + + if (returnType is NullableTypeSyntax) + { + var returnParts = returnComment.Split(new[] { ' ' }, 2).ToList(); + if (returnParts.Count > 1) + { + //insert "nullable" in second to last position + returnParts.Insert(1, "nullable"); + } + else + { + if (options.UseProperCasing) + { + returnParts.Insert(0, "Nullable"); + } + else + { + returnParts.Insert(0, "nullable"); + } + } + returnComment = string.Join(" ", returnParts); + returnComment = returnComment.Replace("?", string.Empty); + } + return returnComment; } /// From 85134b5120b07e33d5201345061c0a92e7d38b50 Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 10 May 2025 11:46:12 -0700 Subject: [PATCH 05/32] update --- .../CodeDocumentor.Test.csproj | 8 +++ .../Methods/MethodUnitTests.cs | 20 +++---- ...hodWithNullableDictionaryReturnTestCode.cs | 14 +++++ ...WithNullableDictionaryReturnTestFixCode.cs | 18 +++++++ .../MethodWithNullableReturnTestFixCode.cs | 2 +- ...thodWithNullableStringReturnTestFixCode.cs | 2 +- CodeDocumentor/CodeDocumentor.Package.cs | 18 +++++-- .../BaseReturnTypeCommentConstruction.cs | 54 +++++++++---------- CodeDocumentor/Helper/CommentHelper.cs | 1 + CodeDocumentor/Helper/Translator.cs | 10 ++++ .../Models/ReturnTypeBuilderOptions.cs | 1 + 11 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestCode.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestFixCode.cs diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index c4b9705..555b579 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -38,6 +38,8 @@ + + @@ -164,6 +166,12 @@ Always + + Always + + + Always + Always diff --git a/CodeDocumentor.Test/Methods/MethodUnitTests.cs b/CodeDocumentor.Test/Methods/MethodUnitTests.cs index 48440b0..1feec9e 100644 --- a/CodeDocumentor.Test/Methods/MethodUnitTests.cs +++ b/CodeDocumentor.Test/Methods/MethodUnitTests.cs @@ -91,17 +91,17 @@ public async Task ShowMethodDiagnosticAndFix(string testCode, string fixCode, in [Theory] - //[InlineData("MethodWithNullableReturnTestCode", "MethodWithNullableReturnTestFixCode", 9, 30)] + [InlineData("MethodWithNullableReturnTestCode", "MethodWithNullableReturnTestFixCode", 9, 30)] [InlineData("MethodWithNullableStringReturnTestCode", "MethodWithNullableStringReturnTestFixCode", 9, 24)] - //[InlineData("MethodWithStringReturnTestCode", "MethodWithStringReturnTestFixCode", 9, 23)] - //[InlineData("MethodWithReturnTestCode", "MethodWithReturnTestFixCode", 9, 29)] - //[InlineData("MethodWithObjectReturnTestCode", "MethodWithObjectReturnTestFixCode", 9, 23)] - //[InlineData("MethodWithIntReturnTestCode", "MethodWithIntReturnTestFixCode", 9, 20)] - //[InlineData("MethodWithCrefTestCode", "MethodWithCrefTestFixCode", 10, 35, false)] - //[InlineData("MethodWithCrefTestCodeNaturalLang", "MethodWithCrefTestFixCodeNaturalLang", 10, 35)] - //[InlineData("MethodWithExceptionTestCode", "MethodWithExceptionTestFixCode", 9, 23)] - //[InlineData("MethodWithInlineExceptionTestCode", "MethodWithInlineExceptionTestFixCode", 9, 23)] - //[InlineData("MethodWithMixedExceptionTestCode", "MethodWithMixedExceptionTestFixCode", 9, 23)] + [InlineData("MethodWithStringReturnTestCode", "MethodWithStringReturnTestFixCode", 9, 23)] + [InlineData("MethodWithReturnTestCode", "MethodWithReturnTestFixCode", 9, 29)] + [InlineData("MethodWithObjectReturnTestCode", "MethodWithObjectReturnTestFixCode", 9, 23)] + [InlineData("MethodWithIntReturnTestCode", "MethodWithIntReturnTestFixCode", 9, 20)] + [InlineData("MethodWithCrefTestCode", "MethodWithCrefTestFixCode", 10, 35, false)] + [InlineData("MethodWithCrefTestCodeNaturalLang", "MethodWithCrefTestFixCodeNaturalLang", 10, 35)] + [InlineData("MethodWithExceptionTestCode", "MethodWithExceptionTestFixCode", 9, 23)] + [InlineData("MethodWithInlineExceptionTestCode", "MethodWithInlineExceptionTestFixCode", 9, 23)] + [InlineData("MethodWithMixedExceptionTestCode", "MethodWithMixedExceptionTestFixCode", 9, 23)] public async Task ShowMethodDiagnosticAndFixWhenCrefsIsTrue(string testCode, string fixCode, int line, int column, bool useNaturalLanguageForReturnNode = true) { var fix = _fixture.LoadTestFile($"./Methods/TestFiles/Crefs/{fixCode}.cs"); diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestCode.cs new file mode 100644 index 0000000..cd5a4c5 --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestCode.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + public Dictionary? ShowMethodWithReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestFixCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestFixCode.cs new file mode 100644 index 0000000..8bbf94f --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableDictionaryReturnTestFixCode.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp40 +{ + public class MethodTester + { + /// + /// Show method with return tester. + /// + /// ]]> + public Dictionary? ShowMethodWithReturnTester() + { + return null; + } + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs index fe06cfc..af173fb 100644 --- a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableReturnTestFixCode.cs @@ -9,7 +9,7 @@ public class MethodTester /// /// Show method with return tester. /// - /// A nullable + /// A public MethodTester? ShowMethodWithReturnTester() { return null; diff --git a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs index 6d136aa..92ab2c6 100644 --- a/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs +++ b/CodeDocumentor.Test/Methods/TestFiles/Crefs/MethodWithNullableStringReturnTestFixCode.cs @@ -9,7 +9,7 @@ public class MethodTester /// /// Show method with string return tester. /// - /// A nullable + /// A public string? ShowMethodWithStringReturnTester() { return null; diff --git a/CodeDocumentor/CodeDocumentor.Package.cs b/CodeDocumentor/CodeDocumentor.Package.cs index 7392fb3..c709d33 100644 --- a/CodeDocumentor/CodeDocumentor.Package.cs +++ b/CodeDocumentor/CodeDocumentor.Package.cs @@ -44,8 +44,13 @@ namespace CodeDocumentor.Vsix2022 [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] public sealed class CodeDocumentorPackage : AsyncPackage { + /// + /// Gets or sets the container factory. This is used ONLY in unit testing + /// public static Func ContainerFactory { get; set; } + private static readonly object _lock = new object(); + public static Container DIContainer() { if (ContainerFactory != null) @@ -54,9 +59,16 @@ public static Container DIContainer() } if (_DIContainer == null) { - _DIContainer = new Container(); - _DIContainer.RegisterServices(); - _DIContainer.Verify(); + lock (_lock) + { + if (_DIContainer == null) + { + var c = new Container(); + c.RegisterServices(); + c.Verify(); + _DIContainer = c; + } + } } return _DIContainer; } diff --git a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs b/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs index d6aec60..024e2e5 100644 --- a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs +++ b/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs @@ -66,10 +66,10 @@ internal virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOpt returnComment = GenerateGeneralComment(identifier.Identifier.ValueText.AsSpan(), options); } } - else if (returnType is NullableTypeSyntax nts) - { - returnComment = BuildComment(nts.ElementType, options); - } + //else if (returnType is NullableTypeSyntax nts) + //{ + // returnComment = BuildComment(nts.ElementType, options); + //} else if (returnType is QualifiedNameSyntax qst) { returnComment = GenerateGeneralComment(qst.ToString().AsSpan(), options); @@ -93,28 +93,28 @@ internal virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOpt : GenerateGeneralComment(returnType.ToFullString().AsSpan(), options); } - if (returnType is NullableTypeSyntax) - { - var returnParts = returnComment.Split(new[] { ' ' }, 2).ToList(); - if (returnParts.Count > 1) - { - //insert "nullable" in second to last position - returnParts.Insert(1, "nullable"); - } - else - { - if (options.UseProperCasing) - { - returnParts.Insert(0, "Nullable"); - } - else - { - returnParts.Insert(0, "nullable"); - } - } - returnComment = string.Join(" ", returnParts); - returnComment = returnComment.Replace("?", string.Empty); - } + //if (returnType is NullableTypeSyntax) + //{ + // var returnParts = returnComment.Split(new[] { ' ' }, 2).ToList(); + // if (returnParts.Count > 1) + // { + // //insert "nullable" in second to last position + // returnParts.Insert(1, "nullable"); + // } + // else + // { + // if (options.UseProperCasing) + // { + // returnParts.Insert(0, "Nullable"); + // } + // else + // { + // returnParts.Insert(0, "nullable"); + // } + // } + // returnComment = string.Join(" ", returnParts); + // returnComment = returnComment.Replace("?", string.Empty); + //} return returnComment; } @@ -137,7 +137,7 @@ private static MethodDeclarationSyntax GetMethodDeclarationSyntax(SyntaxNode nod /// The comment. private string GenerateGeneralComment(ReadOnlySpan returnType, ReturnTypeBuilderOptions options) { - var rt = returnType.ToString(); + var rt = returnType.ToString().Trim(); string startWord = ""; if (options.IncludeStartingWordInText) { diff --git a/CodeDocumentor/Helper/CommentHelper.cs b/CodeDocumentor/Helper/CommentHelper.cs index 593a671..c758afd 100644 --- a/CodeDocumentor/Helper/CommentHelper.cs +++ b/CodeDocumentor/Helper/CommentHelper.cs @@ -60,6 +60,7 @@ public static string CreateConstructorComment(string name, bool isPrivate) { return name; } + name = name.Trim(); if (isPrivate) { comment = $"Prevents a default instance of the class from being created"; diff --git a/CodeDocumentor/Helper/Translator.cs b/CodeDocumentor/Helper/Translator.cs index cbd80ea..2cc2715 100644 --- a/CodeDocumentor/Helper/Translator.cs +++ b/CodeDocumentor/Helper/Translator.cs @@ -34,6 +34,15 @@ public static void Initialize(IOptionsService optionsService) _optionsService = optionsService; } + private static IOptionsService EnsureOptionsService() + { + if (_optionsService == null) + { + _optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + } + return _optionsService; + } + /// /// Translates text replacing words from the WordMap settings /// @@ -41,6 +50,7 @@ public static void Initialize(IOptionsService optionsService) /// A string internal static string TranslateText(string text) { + EnsureOptionsService(); var converted = text; if (_optionsService.WordMaps == null) { diff --git a/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs b/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs index 9ffcca6..e605160 100644 --- a/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs +++ b/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs @@ -1,3 +1,4 @@ + namespace CodeDocumentor.Helper { public class ReturnTypeBuilderOptions From f202ff7f0130ad84fe526727c9681191b0a566dd Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 9 Aug 2025 15:09:05 -0600 Subject: [PATCH 06/32] checkpoint --- .../Builders/DocumentationBuilderTests.cs | 8 +- CodeDocumentor.Test/Classes/ClassUnitTests.cs | 1 + .../TestFiles/ClassConstructorTester.cs | 6 ++ .../TestFiles/ClassConstructorTesterFix.cs | 11 +++ .../CodeDocumentor.Test.csproj | 18 ++++ .../Helper/CommentHelperTests.cs | 27 +++--- .../Methods/MethodUnitTests.cs | 1 + .../TestFiles/InterfacePrivateMethods.cs | 11 +++ .../TestFiles/InterfacePrivateMethodsFix.cs | 16 ++++ .../Analyzers/BaseAnalyzerSettings.cs | 15 +++- .../{Files => }/BaseCodeFixProvider.cs | 19 ++++- .../Analyzers/Classes/ClassAnalyzer.cs | 2 +- .../Classes/ClassAnalyzerSettings.cs | 4 +- .../Analyzers/Classes/ClassCodeFixProvider.cs | 15 ++-- .../Classes/NonPublicClassAnalyzer.cs | 6 +- .../Constructors/ConstructorAnalyzer.cs | 4 +- .../ConstructorAnalyzerSettings.cs | 4 +- .../ConstructorCodeFixProvider.cs | 12 +-- .../NonPublicConstructorAnalyzer.cs | 6 +- .../Analyzers/Enums/EnumAnalyzer.cs | 2 +- .../Analyzers/Enums/EnumAnalyzerSettings.cs | 4 +- .../Analyzers/Enums/EnumCodeFixProvider.cs | 6 +- .../Analyzers/Fields/FieldAnalyzer.cs | 4 +- .../Analyzers/Fields/FieldAnalyzerSettings.cs | 4 +- .../Analyzers/Fields/FieldCodeFixProvider.cs | 10 +-- .../Fields/NonPublicFieldAnalyzer.cs | 6 +- .../Analyzers/Interfaces/InterfaceAnalyzer.cs | 4 +- .../Interfaces/InterfaceAnalyzerSettings.cs | 4 +- .../Interfaces/InterfaceCodeFixProvider.cs | 8 +- .../Analyzers/Methods/MethodAnalyzer.cs | 2 +- .../Methods/MethodAnalyzerSettings.cs | 4 +- .../Methods/MethodCodeFixProvider.cs | 16 ++-- .../Methods/NonPublicMethodAnalyzer.cs | 9 +- .../Properties/NonPublicPropertyAnalyzer.cs | 6 +- .../Analyzers/Properties/PropertyAnalyzer.cs | 2 +- .../Properties/PropertyAnalyzerSettings.cs | 4 +- .../Properties/PropertyCodeFixProvider.cs | 12 +-- .../Records/NonPublicRecordAnalyzer.cs | 6 +- .../Analyzers/Records/RecordAnalyzer.cs | 2 +- .../Records/RecordAnalyzerSettings.cs | 4 +- .../Records/RecordCodeFixProvider.cs | 12 +-- CodeDocumentor/Builders/DiagnosticBuilder.cs | 1 + .../Builders/DocumentationBuilder.cs | 13 +-- CodeDocumentor/CodeDocumentor.Package.cs | 5 ++ CodeDocumentor/CodeDocumentor.csproj | 20 +++-- .../Constructors/ReturnCommentConstruction.cs | 3 +- CodeDocumentor/Helper/CommentHelper.cs | 62 +++++++------- .../Helper/DocumentationHeaderHelper.cs | 8 +- CodeDocumentor/Helper/Translator.cs | 14 +--- CodeDocumentor/Helper/TryHelper.cs | 12 +-- CodeDocumentor/Helper/WordExtensions.cs | 10 +-- CodeDocumentor/Models/Log.cs | 19 ++++- CodeDocumentor/Services/OptionsService.cs | 3 + .../vs2022/source.extension.vsixmanifest | 82 ++++++++++--------- .../CodeDocumentor/ClassConstructors.cs | 4 +- .../ITestPublicInteraceMethods.cs | 9 ++ 56 files changed, 357 insertions(+), 225 deletions(-) create mode 100644 CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTester.cs create mode 100644 CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTesterFix.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethods.cs create mode 100644 CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs rename CodeDocumentor/Analyzers/{Files => }/BaseCodeFixProvider.cs (85%) create mode 100644 TestProject/Sample/Sample/CodeDocumentor/ITestPublicInteraceMethods.cs diff --git a/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs b/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs index 5c8bd65..c3363ac 100644 --- a/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs +++ b/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs @@ -10,6 +10,7 @@ using CodeDocumentor.Vsix2022; using FluentAssertions; using Microsoft.VisualStudio.TestPlatform.Utilities; +using Moq; using Xunit; using Xunit.Abstractions; @@ -35,7 +36,12 @@ public DocumentationBuilderTests(TestFixture fixture, ITestOutputHelper output) public void CreateReturnComment__ReturnsValidNameWithStartingWord_WhenUseNaturalLanguageForReturnNodeIsTrue() { var method = TestFixture.BuildMethodDeclarationSyntax("TResult", "Tester"); - var comment = _builder.WithReturnType(method).Build(); + var mockOptionService = new Mock(); + mockOptionService.Setup(s=>s.UseNaturalLanguageForReturnNode) + .Returns(true); + mockOptionService.Setup(s => s.TryToIncludeCrefsForReturnTypes) + .Returns(false); + var comment = _builder.WithReturnType(method, mockOptionService.Object).Build(); comment.Count.Should().Be(3); comment[1].ToFullString().Should().Be(@"A "); } diff --git a/CodeDocumentor.Test/Classes/ClassUnitTests.cs b/CodeDocumentor.Test/Classes/ClassUnitTests.cs index 10cde00..8d75d5c 100644 --- a/CodeDocumentor.Test/Classes/ClassUnitTests.cs +++ b/CodeDocumentor.Test/Classes/ClassUnitTests.cs @@ -50,6 +50,7 @@ public async Task NoDiagnosticsShow(string testCode) [Theory] [InlineData("ClassTester.cs", "ClassTesterFix.cs", 3, 19, TestFixture.DIAG_TYPE_PRIVATE)] [InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 3, 26, TestFixture.DIAG_TYPE_PUBLIC_ONLY)] + [InlineData("ClassConstructorTester.cs", "ClassConstructorTesterFix.cs", 3, 18, TestFixture.DIAG_TYPE_PUBLIC_ONLY)] public async Task ShowClassDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType) { var fix = _fixture.LoadTestFile($"./Classes/TestFiles/{fixCode}"); diff --git a/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTester.cs b/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTester.cs new file mode 100644 index 0000000..4e94b09 --- /dev/null +++ b/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTester.cs @@ -0,0 +1,6 @@ +namespace ConsoleApp4 +{ + public class ClassConstructorTester(string name, int age) + { + } +} diff --git a/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTesterFix.cs b/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTesterFix.cs new file mode 100644 index 0000000..406f7b4 --- /dev/null +++ b/CodeDocumentor.Test/Classes/TestFiles/ClassConstructorTesterFix.cs @@ -0,0 +1,11 @@ +namespace ConsoleApp4 +{ + /// + /// The class constructor tester. + /// + /// The name. + /// The age. + public class ClassConstructorTester(string name, int age) + { + } +} diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index 555b579..550304e 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -10,6 +10,8 @@ + + @@ -22,6 +24,8 @@ + + @@ -51,6 +55,8 @@ + + @@ -124,9 +130,15 @@ + + Always + Always + + Always + Always @@ -328,6 +340,12 @@ + + Always + + + Always + Always diff --git a/CodeDocumentor.Test/Helper/CommentHelperTests.cs b/CodeDocumentor.Test/Helper/CommentHelperTests.cs index 98f72a8..69f8139 100644 --- a/CodeDocumentor.Test/Helper/CommentHelperTests.cs +++ b/CodeDocumentor.Test/Helper/CommentHelperTests.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Moq; using Xunit; using Xunit.Abstractions; @@ -17,12 +18,14 @@ public class CommentHelperTests : IClassFixture { private readonly TestFixture _fixture; private readonly ITestOutputHelper _output; + private Mock _mockOptionsService; public CommentHelperTests(TestFixture fixture, ITestOutputHelper output) { _fixture = fixture; _output = output; _fixture.Initialize(output); + _mockOptionsService = new Mock(); Translator.Initialize(CodeDocumentorPackage.DIContainer().GetInstance()); } @@ -33,7 +36,7 @@ public CommentHelperTests(TestFixture fixture, ITestOutputHelper output) [InlineData("_hasErrors", "Has errors.")] public void CreateFieldComment_ReturnsValidName(string name, string expected) { - var comment = CommentHelper.CreateFieldComment(name); + var comment = CommentHelper.CreateFieldComment(name, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -86,7 +89,7 @@ public void CreateMethodComment_ReturnsValidName(string name, string returnType, typeSyntax = SyntaxFactory.ParseTypeName(returnType); } - var comment = CommentHelper.CreateMethodComment(name, typeSyntax); + var comment = CommentHelper.CreateMethodComment(name, typeSyntax, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -104,7 +107,7 @@ public void CreateMethodComment_ReturnsValidCommentWhenOneWordMethodAndLayeredLi TypeSyntax typeSyntax = SyntaxFactory.ParseTypeName("Task>>"); - var comment = CommentHelper.CreateMethodComment("Work", typeSyntax); + var comment = CommentHelper.CreateMethodComment("Work", typeSyntax, _mockOptionsService.Object); comment.Should().Be("Work and return a of a list of a list of strings."); } @@ -122,7 +125,7 @@ public void CreateMethodComment_ReturnsValidCommentWhenReturnIsTask_ActionResult TypeSyntax typeSyntax = SyntaxFactory.ParseTypeName("Task>"); - var comment = CommentHelper.CreateMethodComment("CreateAsync", typeSyntax); + var comment = CommentHelper.CreateMethodComment("CreateAsync", typeSyntax, _mockOptionsService.Object); comment.Should().Be("Creates and return a task of type actionresult of type clientdto asynchronously."); } @@ -157,7 +160,7 @@ public void CreateMethodComment_ReturnsValidNaturalLanguage(string name, string typeSyntax = SyntaxFactory.ParseTypeName(returnType); } - var comment = CommentHelper.CreateMethodComment(name, typeSyntax); + var comment = CommentHelper.CreateMethodComment(name, typeSyntax, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -167,7 +170,7 @@ public void CreateMethodComment_ReturnsValidNaturalLanguage(string name, string [InlineData("INotifier", "The notifier interface.")] public void CreateInterfaceComment_ReturnsValidName(string name, string expected) { - var comment = CommentHelper.CreateInterfaceComment(name); + var comment = CommentHelper.CreateInterfaceComment(name, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -179,7 +182,7 @@ public void CreateInterfaceComment_ReturnsValidName(string name, string expected [InlineData("ClientDto", "The client data transfer object.")] public void CreateClassComment_ReturnsValidName(string name, string expected) { - var comment = CommentHelper.CreateClassComment(name); + var comment = CommentHelper.CreateClassComment(name, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -188,7 +191,7 @@ public void CreateClassComment_ReturnsValidName(string name, string expected) [InlineData("ClientDto", "The client data transfer object.")] public void CreateRecordComment_ReturnsValidName(string name, string expected) { - var comment = CommentHelper.CreateRecordComment(name); + var comment = CommentHelper.CreateRecordComment(name, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -198,7 +201,7 @@ public void CreateRecordComment_ReturnsValidName(string name, string expected) [InlineData("HasError", "Gets a value indicating whether has error.", true, false)] public void CreatePropertyComment_ReturnsValidName(string name, string expected, bool isBool, bool hasSetter) { - var comment = CommentHelper.CreatePropertyComment(name, isBool, hasSetter); + var comment = CommentHelper.CreatePropertyComment(name, isBool, hasSetter, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -208,7 +211,7 @@ public void CreatePropertyComment_ReturnsValidName(string name, string expected, [InlineData("ClientRole", "The clients roles.")] public void CreateEnumComment_ReturnsValidName(string name, string expected) { - var comment = CommentHelper.CreateEnumComment(name); + var comment = CommentHelper.CreateEnumComment(name, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -233,7 +236,7 @@ public void CreateParameterComment_ReturnsValidName(string name, string paramTyp } var parameter = SyntaxFactory.Parameter(attributeLists, modifiers, typeSyntax, SyntaxFactory.Identifier(name), null); - var comment = CommentHelper.CreateParameterComment(parameter); + var comment = CommentHelper.CreateParameterComment(parameter, _mockOptionsService.Object); comment.Should().Be(expected); } @@ -246,7 +249,7 @@ public void CreateParameterComment_ReturnsValidName(string name, string paramTyp public void InternalTranslate_ConvertsCorrectly(string word, string converted) { Translator.Initialize(CodeDocumentorPackage.DIContainer().GetInstance()); - var result = CommentHelper.TranslateParts(new List { word }); + var result = CommentHelper.TranslateParts(new List { word }, _mockOptionsService.Object); result.Should().Contain(converted); } } diff --git a/CodeDocumentor.Test/Methods/MethodUnitTests.cs b/CodeDocumentor.Test/Methods/MethodUnitTests.cs index 1feec9e..b2bbc81 100644 --- a/CodeDocumentor.Test/Methods/MethodUnitTests.cs +++ b/CodeDocumentor.Test/Methods/MethodUnitTests.cs @@ -48,6 +48,7 @@ public async Task NoDiagnosticsShow(string testCode) [Theory] [InlineData("BasicTestCode", "BasicTestFixCode", 9, 21)] + [InlineData("InterfacePrivateMethods", "InterfacePrivateMethodsFix", 9, 21)] [InlineData("MethodWithParameterTestCode", "MethodWithParameterTestFixCode", 9, 21)] [InlineData("MethodWithBooleanParameterTestCode", "MethodWithBooleanParameterTestFixCode", 9, 21)] [InlineData("MethodWithNullableStructParameterTestCode", "MethodWithNullableStructParameterTestFixCode", 9, 21)] diff --git a/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethods.cs b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethods.cs new file mode 100644 index 0000000..8dba277 --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethods.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp4 +{ + public interface IInterfaceTesterPrivateMethod + { + Task GetNamesAsync(string name); + } +} diff --git a/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs new file mode 100644 index 0000000..fc71cb4 --- /dev/null +++ b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp4 +{ + public interface IInterfaceTesterPrivateMethod + { + /// + /// Gets the names asynchronously. + /// + /// + /// + Task GetNamesAsync(string name); + } +} diff --git a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs b/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs index 3e060cb..b669414 100644 --- a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs @@ -12,12 +12,23 @@ internal class BaseAnalyzerSettings /// internal const string Category = Constants.CATEGORY; + protected static IOptionsService OptionsService; + + public static void SetOptionsService(IOptionsService optionsService) + { + OptionsService = optionsService; + } + internal static DiagnosticSeverity LookupSeverity(string diagnosticId) { + if (OptionsService == null) + { + return Constants.DefaultDiagnosticSeverityOnError; + } return TryHelper.Try(() => { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; switch (diagnosticId) { case Constants.DiagnosticIds.CLASS_DIAGNOSTIC_ID: @@ -38,7 +49,7 @@ internal static DiagnosticSeverity LookupSeverity(string diagnosticId) return optionsService.RecordDiagnosticSeverity ?? optionsService.DefaultDiagnosticSeverity; } return Constants.DefaultDiagnosticSeverityOnError; - }, (_) => Constants.DefaultDiagnosticSeverityOnError, eventId: Constants.EventIds.ANALYZER); + }, diagnosticId, (_) => Constants.DefaultDiagnosticSeverityOnError, eventId: Constants.EventIds.ANALYZER); } } } diff --git a/CodeDocumentor/Analyzers/Files/BaseCodeFixProvider.cs b/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs similarity index 85% rename from CodeDocumentor/Analyzers/Files/BaseCodeFixProvider.cs rename to CodeDocumentor/Analyzers/BaseCodeFixProvider.cs index cc92d49..79f8b19 100644 --- a/CodeDocumentor/Analyzers/Files/BaseCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs @@ -3,16 +3,33 @@ using System.Diagnostics; using System.Threading.Tasks; using CodeDocumentor.Helper; +using CodeDocumentor.Services; using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Diagnostics; namespace CodeDocumentor { + public abstract class BaseDiagnosticAnalyzer : DiagnosticAnalyzer { + protected static IOptionsService OptionsService; + + public static void SetOptionsService(IOptionsService optionsService) + { + OptionsService = optionsService; + } + } + public abstract class BaseCodeFixProvider : CodeFixProvider { + protected static IOptionsService OptionsService; + + public static void SetOptionsService(IOptionsService optionsService) + { + OptionsService = optionsService; + } /// /// The title. /// @@ -83,7 +100,7 @@ protected async Task RegisterFileCodeFixesAsync(CodeFixContext context, Diagnost createChangedDocument: (c) => Task.Run(() => context.Document.WithSyntaxRoot(newRoot), c), equivalenceKey: FILE_FIX_TITLE), diagnostic); - }, eventId: Constants.EventIds.FILE_FIXER, category: Constants.EventIds.Categories.BUILD_COMMENTS); + }, diagnostic.Id, eventId: Constants.EventIds.FILE_FIXER, category: Constants.EventIds.Categories.BUILD_COMMENTS); } } } diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs index 5d560c8..58e3038 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor /// The class analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class ClassAnalyzer : DiagnosticAnalyzer + public class ClassAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs index c5099a7..a3ba402 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs @@ -23,8 +23,8 @@ internal class ClassAnalyzerSettings: BaseAnalyzerSettings internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(ClassAnalyzerSettings.DiagnosticId, ClassAnalyzerSettings.Title, - ClassAnalyzerSettings.MessageFormat, ClassAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs b/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs index fd756be..e860817 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs @@ -57,7 +57,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { @@ -89,7 +90,7 @@ internal static Task AddDocumentationHeaderAsync(Document document, Sy var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, ClassAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } /// @@ -103,7 +104,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly @@ -119,18 +120,18 @@ internal static int BuildComments(SyntaxNode root, Dictionary(); - var comment = CommentHelper.CreateClassComment(declarationSyntax.Identifier.ValueText); + var optionsService = OptionsService; + var comment = CommentHelper.CreateClassComment(declarationSyntax.Identifier.ValueText, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var list = builder.WithSummary(declarationSyntax, comment, optionsService.PreserveExistingSummaryText) .WithTypeParamters(declarationSyntax) - .WithParameters(declarationSyntax) + .WithParameters(declarationSyntax, OptionsService) .WithExisting(declarationSyntax, Constants.REMARKS) .WithExisting(declarationSyntax, Constants.EXAMPLE) .Build(); diff --git a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs b/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs index 2a6cf03..3ce2164 100644 --- a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs @@ -15,7 +15,7 @@ namespace CodeDocumentor /// The class analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicClassAnalyzer : DiagnosticAnalyzer + public class NonPublicClassAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -24,7 +24,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(ClassAnalyzerSettings.GetRule()); @@ -53,7 +53,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly) { diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs index 23da02a..352134e 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs @@ -14,7 +14,7 @@ namespace CodeDocumentor /// The constructor analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class ConstructorAnalyzer : DiagnosticAnalyzer + public class ConstructorAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -52,7 +52,7 @@ internal static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(node)) { return; diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs index 91cf70e..33562b3 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs @@ -23,8 +23,8 @@ internal class ConstructorAnalyzerSettings: BaseAnalyzerSettings internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(ConstructorAnalyzerSettings.DiagnosticId, ConstructorAnalyzerSettings.Title, - ConstructorAnalyzerSettings.MessageFormat, ConstructorAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs b/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs index 110d1fc..f236085 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs @@ -57,7 +57,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { return; @@ -85,7 +85,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declarationSyntax)) @@ -100,7 +100,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary A DocumentationCommentTriviaSyntax. private static DocumentationCommentTriviaSyntax CreateDocumentationCommentTriviaSyntax(ConstructorDeclarationSyntax declarationSyntax) { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; var comment = CommentHelper.CreateConstructorComment(declarationSyntax.Identifier.ValueText, declarationSyntax.IsPrivate()); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var list = builder.WithSummary(declarationSyntax, comment, optionsService.PreserveExistingSummaryText) - .WithParameters(declarationSyntax) + .WithParameters(declarationSyntax, OptionsService) .WithExisting(declarationSyntax, Constants.REMARKS) .WithExisting(declarationSyntax, Constants.EXAMPLE) .Build(); @@ -146,7 +146,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, ConstructorAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs b/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs index c0fb4ad..f11d353 100644 --- a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor { [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicConstructorAnalyzer : DiagnosticAnalyzer + public class NonPublicConstructorAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -21,7 +21,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(ConstructorAnalyzerSettings.GetRule()); @@ -50,7 +50,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly) { return; diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs b/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs index ccee19e..fca0de6 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor /// The enum analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class EnumAnalyzer : DiagnosticAnalyzer + public class EnumAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs index 2a70561..9c8e6ec 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs @@ -26,8 +26,8 @@ internal class EnumAnalyzerSettings : BaseAnalyzerSettings /// internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(EnumAnalyzerSettings.DiagnosticId, EnumAnalyzerSettings.Title, - EnumAnalyzerSettings.MessageFormat, EnumAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs b/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs index a369a0b..35bd256 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs @@ -88,7 +88,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary(); @@ -121,7 +121,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, EnumAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs b/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs index 87eb1b7..6f7ce84 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs @@ -15,7 +15,7 @@ namespace CodeDocumentor /// The field analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class FieldAnalyzer : DiagnosticAnalyzer + public class FieldAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -49,7 +49,7 @@ internal static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (!optionsService.IsEnabledForNonPublicFields && PrivateMemberVerifier.IsPrivateMember(node)) { return; diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs index 68f1f3f..81bfef7 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs @@ -26,8 +26,8 @@ internal class FieldAnalyzerSettings:BaseAnalyzerSettings /// internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(FieldAnalyzerSettings.DiagnosticId, FieldAnalyzerSettings.Title, FieldAnalyzerSettings.MessageFormat, - FieldAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, + Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs b/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs index c80d82f..51ddea5 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs @@ -57,7 +57,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { return; @@ -84,7 +84,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declarationSyntax)) @@ -99,7 +99,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary().FirstOrDefault(); - var comment = CommentHelper.CreateFieldComment(field?.Identifier.ValueText); + var comment = CommentHelper.CreateFieldComment(field?.Identifier.ValueText, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); @@ -133,7 +133,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, FieldAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs b/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs index c59a354..5a1666b 100644 --- a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs @@ -13,7 +13,7 @@ namespace CodeDocumentor { [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicFieldAnalyzer : DiagnosticAnalyzer + public class NonPublicFieldAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -22,7 +22,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(FieldAnalyzerSettings.GetRule()); @@ -57,7 +57,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly) { return; diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs index ec38241..b5b857a 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs @@ -14,7 +14,7 @@ namespace CodeDocumentor /// The interface analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class InterfaceAnalyzer : DiagnosticAnalyzer + public class InterfaceAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -42,7 +42,7 @@ internal static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(node)) { return; diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs index 18d5168..f80abb4 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs @@ -27,8 +27,8 @@ internal class InterfaceAnalyzerSettings:BaseAnalyzerSettings /// internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(InterfaceAnalyzerSettings.DiagnosticId, InterfaceAnalyzerSettings.Title, - InterfaceAnalyzerSettings.MessageFormat, InterfaceAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs index 827e1e9..f95c241 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs @@ -89,14 +89,14 @@ internal static int BuildComments(SyntaxNode root, Dictionary(); - var comment = CommentHelper.CreateInterfaceComment(declarationSyntax.Identifier.ValueText); + var optionsService = OptionsService; + var comment = CommentHelper.CreateInterfaceComment(declarationSyntax.Identifier.ValueText, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var list = builder.WithSummary(declarationSyntax, comment, optionsService.PreserveExistingSummaryText) .WithTypeParamters(declarationSyntax) @@ -124,7 +124,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, InterfaceAnalyzerSettings.DiagnosticId , (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs index 67c3b19..3623a49 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor /// The method analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class MethodAnalyzer : DiagnosticAnalyzer + public class MethodAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs index 0d2eecd..63dabe0 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs @@ -26,8 +26,8 @@ internal class MethodAnalyzerSettings : BaseAnalyzerSettings /// internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(MethodAnalyzerSettings.DiagnosticId, MethodAnalyzerSettings.Title, - MethodAnalyzerSettings.MessageFormat, MethodAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs index 516e6ea..2f0e107 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs @@ -57,7 +57,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { return; @@ -84,7 +84,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declarationSyntax)) @@ -100,7 +100,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary A DocumentationCommentTriviaSyntax. private static DocumentationCommentTriviaSyntax CreateDocumentationCommentTriviaSyntax(MethodDeclarationSyntax declarationSyntax) { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); - var summaryText = CommentHelper.CreateMethodComment(declarationSyntax.Identifier.ValueText, declarationSyntax.ReturnType); + var optionsService = OptionsService; + var summaryText = CommentHelper.CreateMethodComment(declarationSyntax.Identifier.ValueText, declarationSyntax.ReturnType, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var list = builder.WithSummary(declarationSyntax, summaryText, optionsService.PreserveExistingSummaryText) .WithTypeParamters(declarationSyntax) - .WithParameters(declarationSyntax) + .WithParameters(declarationSyntax, optionsService) .WithExceptionTypes(declarationSyntax) .WithExisting(declarationSyntax, Constants.REMARKS) .WithExisting(declarationSyntax, Constants.EXAMPLE) - .WithReturnType(declarationSyntax) + .WithReturnType(declarationSyntax, OptionsService) .Build(); return SyntaxFactory.DocumentationCommentTrivia(SyntaxKind.SingleLineDocumentationCommentTrivia, list); @@ -149,7 +149,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, MethodAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs b/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs index 014c6fa..44bb7fc 100644 --- a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor { [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicMethodAnalyzer : DiagnosticAnalyzer + public class NonPublicMethodAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -21,7 +21,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(MethodAnalyzerSettings.GetRule()); @@ -51,8 +51,9 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); - if (optionsService.IsEnabledForPublicMembersOnly) + //NOTE [dturco 8.9.2025]:Since interfaces declarations do not have accessors, we do not need to check for public members only. + var optionsService = OptionsService; + if (node?.Parent.GetType() != typeof(InterfaceDeclarationSyntax) && optionsService.IsEnabledForPublicMembersOnly) { return; } diff --git a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs b/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs index 1991ab6..aeb70d5 100644 --- a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs @@ -15,7 +15,7 @@ namespace CodeDocumentor /// The property analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicPropertyAnalyzer : DiagnosticAnalyzer + public class NonPublicPropertyAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -24,7 +24,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(PropertyAnalyzerSettings.GetRule()); @@ -56,7 +56,7 @@ internal static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly) { return; diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs index ed7e911..b9c3db9 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor /// The property analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class PropertyAnalyzer : DiagnosticAnalyzer + public class PropertyAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs index 8ccf59a..c32dbc6 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs @@ -26,8 +26,8 @@ internal class PropertyAnalyzerSettings: BaseAnalyzerSettings /// internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(PropertyAnalyzerSettings.DiagnosticId, PropertyAnalyzerSettings.Title, - PropertyAnalyzerSettings.MessageFormat, PropertyAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs b/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs index 31bdc63..99e05c8 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs @@ -57,7 +57,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { return; @@ -84,7 +84,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declarationSyntax)) @@ -99,7 +99,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary(); - var propertyComment = CommentHelper.CreatePropertyComment(declarationSyntax.Identifier.ValueText, isBoolean, hasSetter); + var optionsService = OptionsService; + var propertyComment = CommentHelper.CreatePropertyComment(declarationSyntax.Identifier.ValueText, isBoolean, hasSetter, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var returnOptions = new ReturnTypeBuilderOptions @@ -148,7 +148,7 @@ private Task AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, PropertyAnalyzerSettings.DiagnosticId , (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs b/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs index 62f431a..e5ca8af 100644 --- a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs @@ -15,7 +15,7 @@ namespace CodeDocumentor /// The class analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class NonPublicRecordAnalyzer : DiagnosticAnalyzer + public class NonPublicRecordAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. @@ -24,7 +24,7 @@ public override ImmutableArray SupportedDiagnostics { get { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; return optionsService.IsEnabledForPublicMembersOnly ? new List().ToImmutableArray() : ImmutableArray.Create(RecordAnalyzerSettings.GetRule()); @@ -53,7 +53,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly) { return; diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs b/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs index 25e2d86..d237b9a 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs @@ -12,7 +12,7 @@ namespace CodeDocumentor /// The class analyzer. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] - public class RecordAnalyzer : DiagnosticAnalyzer + public class RecordAnalyzer : BaseDiagnosticAnalyzer { /// /// Gets the supported diagnostics. diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs index 5433fcf..b096a10 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs @@ -23,8 +23,8 @@ internal class RecordAnalyzerSettings: BaseAnalyzerSettings internal static DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity = false) { - return new DiagnosticDescriptor(RecordAnalyzerSettings.DiagnosticId, RecordAnalyzerSettings.Title, - RecordAnalyzerSettings.MessageFormat, RecordAnalyzerSettings.Category, + return new DiagnosticDescriptor(DiagnosticId, Title, + MessageFormat, Category, hideDiagnosticSeverity ? DiagnosticSeverity.Hidden : LookupSeverity(DiagnosticId), true); } } diff --git a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs b/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs index 72ba155..3d116a6 100644 --- a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs @@ -57,7 +57,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) { return; @@ -88,7 +88,7 @@ internal Task AddDocumentationHeaderAsync(Document document, SyntaxNod var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, RecordAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } /// @@ -102,7 +102,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary { - var optionsService = CodeDocumentorPackage.DIContainer().GetInstance(); + var optionsService = OptionsService; foreach (var declarationSyntax in declarations) { if (optionsService.IsEnabledForPublicMembersOnly @@ -118,14 +118,14 @@ internal static int BuildComments(SyntaxNode root, Dictionary(); - var comment = CommentHelper.CreateRecordComment(declarationSyntax.Identifier.ValueText); + var optionsService = OptionsService; + var comment = CommentHelper.CreateRecordComment(declarationSyntax.Identifier.ValueText, OptionsService); var builder = CodeDocumentorPackage.DIContainer().GetInstance(); var list = builder.WithSummary(declarationSyntax, comment, optionsService.PreserveExistingSummaryText) diff --git a/CodeDocumentor/Builders/DiagnosticBuilder.cs b/CodeDocumentor/Builders/DiagnosticBuilder.cs index 522bf3c..5b497d6 100644 --- a/CodeDocumentor/Builders/DiagnosticBuilder.cs +++ b/CodeDocumentor/Builders/DiagnosticBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using CodeDocumentor.Helper; +using CodeDocumentor.Services; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/CodeDocumentor/Builders/DocumentationBuilder.cs b/CodeDocumentor/Builders/DocumentationBuilder.cs index db04501..d7c45de 100644 --- a/CodeDocumentor/Builders/DocumentationBuilder.cs +++ b/CodeDocumentor/Builders/DocumentationBuilder.cs @@ -2,6 +2,7 @@ using System.Linq; using CodeDocumentor.Constructors; using CodeDocumentor.Helper; +using CodeDocumentor.Services; using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -56,13 +57,13 @@ internal DocumentationBuilder WithExisting(CSharpSyntaxNode declarationSyntax, s return this; } - internal DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declarationSyntax) + internal DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declarationSyntax, IOptionsService optionsService) { if (declarationSyntax?.ParameterList?.Parameters.Any() == true) { foreach (var parameter in declarationSyntax.ParameterList.Parameters) { - var parameterComment = CommentHelper.CreateParameterComment(parameter); + var parameterComment = CommentHelper.CreateParameterComment(parameter, optionsService); var parameterElement = DocumentationHeaderHelper.CreateParameterElementSyntax(parameter.Identifier.ValueText, parameterComment); Reset().WithTripleSlashSpace() @@ -73,13 +74,13 @@ internal DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declara return this; } - internal DocumentationBuilder WithParameters(TypeDeclarationSyntax declarationSyntax) + internal DocumentationBuilder WithParameters(TypeDeclarationSyntax declarationSyntax, IOptionsService optionsService) { if (declarationSyntax?.ParameterList?.Parameters.Any() == true) { foreach (var parameter in declarationSyntax.ParameterList.Parameters) { - var parameterComment = CommentHelper.CreateParameterComment(parameter); + var parameterComment = CommentHelper.CreateParameterComment(parameter, optionsService); var parameterElement = DocumentationHeaderHelper.CreateParameterElementSyntax(parameter.Identifier.ValueText, parameterComment); @@ -106,12 +107,12 @@ internal DocumentationBuilder WithPropertyValueTypes(BasePropertyDeclarationSynt return this; } - internal DocumentationBuilder WithReturnType(MethodDeclarationSyntax declarationSyntax) + internal DocumentationBuilder WithReturnType(MethodDeclarationSyntax declarationSyntax, IOptionsService optionsService) { var returnType = declarationSyntax.ReturnType.ToString().Replace("?",string.Empty); if (returnType != "void") { - var commentConstructor = new ReturnCommentConstruction(declarationSyntax.ReturnType); + var commentConstructor = new ReturnCommentConstruction(declarationSyntax.ReturnType, optionsService); var returnComment = commentConstructor.Comment; var returnElement = DocumentationHeaderHelper.CreateReturnElementSyntax(returnComment); diff --git a/CodeDocumentor/CodeDocumentor.Package.cs b/CodeDocumentor/CodeDocumentor.Package.cs index c709d33..c91fa67 100644 --- a/CodeDocumentor/CodeDocumentor.Package.cs +++ b/CodeDocumentor/CodeDocumentor.Package.cs @@ -2,6 +2,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Builders; using CodeDocumentor.Helper; using CodeDocumentor.Services; using CodeDocumentor.Settings; @@ -122,6 +124,9 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke var optService = DIContainer().GetInstance(); optService.SetDefaults(_options); + BaseCodeFixProvider.SetOptionsService(optService); + BaseDiagnosticAnalyzer.SetOptionsService(optService); + BaseAnalyzerSettings.SetOptionsService(optService); Translator.Initialize(optService); } diff --git a/CodeDocumentor/CodeDocumentor.csproj b/CodeDocumentor/CodeDocumentor.csproj index 3cc87c7..41b1261 100644 --- a/CodeDocumentor/CodeDocumentor.csproj +++ b/CodeDocumentor/CodeDocumentor.csproj @@ -1,4 +1,4 @@ - + 17.0 @@ -54,7 +54,7 @@ - + @@ -124,10 +124,10 @@ - + compile; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -135,14 +135,14 @@ 13.0.3 - 5.5.0 + 5.4.4 8.0.0 - - - + + + @@ -162,7 +162,9 @@ true - + + + - \ No newline at end of file + diff --git a/Manifests/vs2022/source.extension.vsixmanifest b/Manifests/vs2022/source.extension.vsixmanifest index 5c484f0..66374b2 100644 --- a/Manifests/vs2022/source.extension.vsixmanifest +++ b/Manifests/vs2022/source.extension.vsixmanifest @@ -32,9 +32,7 @@ - - From 274330608d92c1a222f23889fd80164be794ec9d Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sun, 17 Aug 2025 09:57:19 -0600 Subject: [PATCH 12/32] fixed private methods in interfaces tests --- .../Methods/MethodUnitTests.cs | 29 ++++++++++++++++++- .../TestFiles/InterfacePrivateMethodsFix.cs | 6 ++-- .../Analyzers/Methods/MethodAnalyzer.cs | 6 +++- .../Methods/MethodCodeFixProvider.cs | 7 ++++- .../Methods/NonPublicMethodAnalyzer.cs | 4 +-- CodeDocumentor/CodeDocumentor.csproj | 3 +- CodeDocumentor/Helper/SyntaxNodeExtensions.cs | 12 ++++++++ 7 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 CodeDocumentor/Helper/SyntaxNodeExtensions.cs diff --git a/CodeDocumentor.Test/Methods/MethodUnitTests.cs b/CodeDocumentor.Test/Methods/MethodUnitTests.cs index 482506f..3779cb4 100644 --- a/CodeDocumentor.Test/Methods/MethodUnitTests.cs +++ b/CodeDocumentor.Test/Methods/MethodUnitTests.cs @@ -48,7 +48,7 @@ public async Task NoDiagnosticsShow(string testCode) [Theory] [InlineData("BasicTestCode", "BasicTestFixCode", 9, 21)] - [InlineData("InterfacePrivateMethods", "InterfacePrivateMethodsFix", 9, 21)] + [InlineData("InterfacePrivateMethods", "InterfacePrivateMethodsFix", 9, 22)] [InlineData("MethodWithParameterTestCode", "MethodWithParameterTestFixCode", 9, 21)] [InlineData("MethodWithBooleanParameterTestCode", "MethodWithBooleanParameterTestFixCode", 9, 21)] [InlineData("MethodWithNullableStructParameterTestCode", "MethodWithNullableStructParameterTestFixCode", 9, 21)] @@ -88,6 +88,33 @@ public async Task ShowMethodDiagnosticAndFix(string testCode, string fixCode, in await VerifyCSharpFixAsync(test, fix, TestFixture.DIAG_TYPE_PUBLIC_ONLY); } + [Theory] + [InlineData("InterfacePrivateMethods", "InterfacePrivateMethodsFix", 9, 22)] + public async Task ShowMethodDiagnosticAndFixForPrivate(string testCode, string fixCode, int line, int column) + { + var fix = _fixture.LoadTestFile($"./Methods/TestFiles/{fixCode}.cs"); + var test = _fixture.LoadTestFile($"./Methods/TestFiles/{testCode}.cs"); + _fixture.MockOptionsService.SetClone(new TestOptionsService + { + UseNaturalLanguageForReturnNode = false, + TryToIncludeCrefsForReturnTypes = false + }); + var expected = new DiagnosticResult + { + Id = MethodAnalyzerSettings.DiagnosticId, + Message = MethodAnalyzerSettings.MessageFormat, + Severity = DiagnosticSeverity.Warning, + Locations = + new[] { + new DiagnosticResultLocation("Test0.cs", line, column) + } + }; + + await VerifyCSharpDiagnosticAsync(test, TestFixture.DIAG_TYPE_PRIVATE, expected); + + await VerifyCSharpFixAsync(test, fix, TestFixture.DIAG_TYPE_PRIVATE); + } + [Theory] [InlineData("MethodWithNullableReturnTestCode", "MethodWithNullableReturnTestFixCode", 9, 30)] diff --git a/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs index fc71cb4..a44fc63 100644 --- a/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs +++ b/CodeDocumentor.Test/Methods/TestFiles/InterfacePrivateMethodsFix.cs @@ -7,10 +7,10 @@ namespace ConsoleApp4 public interface IInterfaceTesterPrivateMethod { /// - /// Gets the names asynchronously. + /// Get the names asynchronously. /// - /// - /// + /// The name. + /// ]]> Task GetNamesAsync(string name); } } diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs index 260c6c7..2f11dec 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs @@ -53,7 +53,11 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - if (PrivateMemberVerifier.IsPrivateMember(node)) + + //NOTE: Since interfaces declarations do not have accessors, we allow documenting all the time. + var isPrivate = PrivateMemberVerifier.IsPrivateMember(node); + var isOwnedByInterface = node.IsOwnedByInterface(); + if (isPrivate && !isOwnedByInterface) { return; } diff --git a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs index a6a6350..7390e0d 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs @@ -57,7 +57,12 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } var optionsService = OptionsService; - if (optionsService.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(declaration)) + if ( + //NOTE: Since interfaces declarations do not have accessors, we allow documenting all the time. + !declaration.IsOwnedByInterface() && + optionsService.IsEnabledForPublicMembersOnly && + PrivateMemberVerifier.IsPrivateMember(declaration) + ) { return; } diff --git a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs b/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs index 649cdad..3c88d8a 100644 --- a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs @@ -56,9 +56,9 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - //NOTE [dturco 8.9.2025]:Since interfaces declarations do not have accessors, we do not need to check for public members only. + //NOTE: Since interfaces declarations do not have accessors, we allow documenting all the time. var optionsService = OptionsService; - if (node?.Parent.GetType() != typeof(InterfaceDeclarationSyntax) && optionsService.IsEnabledForPublicMembersOnly) + if (!node.IsOwnedByInterface() && optionsService.IsEnabledForPublicMembersOnly) { return; } diff --git a/CodeDocumentor/CodeDocumentor.csproj b/CodeDocumentor/CodeDocumentor.csproj index 024eec5..fb7cb8d 100644 --- a/CodeDocumentor/CodeDocumentor.csproj +++ b/CodeDocumentor/CodeDocumentor.csproj @@ -75,6 +75,7 @@ + @@ -172,4 +173,4 @@ --> - + \ No newline at end of file diff --git a/CodeDocumentor/Helper/SyntaxNodeExtensions.cs b/CodeDocumentor/Helper/SyntaxNodeExtensions.cs new file mode 100644 index 0000000..9fab189 --- /dev/null +++ b/CodeDocumentor/Helper/SyntaxNodeExtensions.cs @@ -0,0 +1,12 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace CodeDocumentor.Helper +{ + public static class SyntaxNodeExtensions + { + public static bool IsOwnedByInterface(this SyntaxNode node) { + return node?.Parent.GetType() == typeof(InterfaceDeclarationSyntax); + } + } +} From 0ec58fa313423a383ec673cbc8e4ee532405c66f Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Mon, 18 Aug 2025 19:16:45 -0600 Subject: [PATCH 13/32] cleanup added support to convert settings to editorconfig settings --- .../TestHelpers/TestOptionsService.cs | 1 + .../Analyzers/Classes/ClassAnalyzer.cs | 5 +- .../Classes/NonPublicClassAnalyzer.cs | 3 +- .../Constructors/ConstructorAnalyzer.cs | 3 +- .../NonPublicConstructorAnalyzer.cs | 3 +- .../Analyzers/Enums/EnumAnalyzer.cs | 3 +- .../Analyzers/Fields/FieldAnalyzer.cs | 3 +- .../Fields/NonPublicFieldAnalyzer.cs | 3 +- .../Analyzers/Interfaces/InterfaceAnalyzer.cs | 3 +- .../Analyzers/Methods/MethodAnalyzer.cs | 3 +- .../Methods/MethodCodeFixProvider.cs | 7 +- .../Methods/NonPublicMethodAnalyzer.cs | 3 +- .../Properties/NonPublicPropertyAnalyzer.cs | 3 +- .../Analyzers/Properties/PropertyAnalyzer.cs | 3 +- .../Records/NonPublicRecordAnalyzer.cs | 3 +- .../Analyzers/Records/RecordAnalyzer.cs | 2 +- CodeDocumentor/GlobalSuppressions.cs | 6 + CodeDocumentor/Interfaces/IOptionPageGrid.cs | 8 ++ CodeDocumentor/Models/OptionPageGrid.cs | 38 +++++- CodeDocumentor/Models/Settings.cs | 109 +++++++++++++++--- CodeDocumentor/Services/OptionsService.cs | 2 + .../vs2022/source.extension.vsixmanifest | 80 ++++++------- 22 files changed, 205 insertions(+), 89 deletions(-) diff --git a/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs b/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs index d4e290e..2b894c6 100644 --- a/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs +++ b/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs @@ -37,6 +37,7 @@ public class TestOptionsService : IOptionsService public DiagnosticSeverity? PropertyDiagnosticSeverity { get; set; } public DiagnosticSeverity? RecordDiagnosticSeverity { get; set; } public bool IsEnabledForNonPublicFields { get; set; } + public bool UseEditorConfigForSettings { get; set; } public void SetClone(IOptionsService optionsService) { diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs index 8b26704..a236398 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs @@ -41,15 +41,13 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.ClassDeclaration); - - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is ClassDeclarationSyntax node)) { @@ -59,6 +57,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs b/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs index 232758f..b494e62 100644 --- a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs @@ -44,7 +44,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.ClassDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -64,7 +63,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs index b9803cf..5946ec7 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs @@ -40,7 +40,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.ConstructorDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -62,7 +61,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs b/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs index 5e435bb..9aff4f4 100644 --- a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs @@ -41,7 +41,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.ConstructorDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -60,7 +59,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs b/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs index 3203d2e..aeca4b4 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs @@ -34,7 +34,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.EnumDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -47,7 +46,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs b/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs index 190ad82..3ea3aa0 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs @@ -41,7 +41,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.FieldDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -65,7 +64,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs b/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs index 112c5fc..e179bb0 100644 --- a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs @@ -42,7 +42,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.FieldDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -67,7 +66,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs index f7275b6..0f70ffb 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs @@ -34,7 +34,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InterfaceDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -52,7 +51,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs index 2f11dec..a5d73d4 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs @@ -40,7 +40,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.MethodDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -61,7 +60,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs index 7390e0d..f05b8ee 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs @@ -91,11 +91,14 @@ internal static int BuildComments(SyntaxNode root, Dictionary @@ -62,7 +61,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs b/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs index 2d1d37f..7bfade5 100644 --- a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs @@ -44,7 +44,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -66,7 +65,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs index ee8b7f2..e3cbcaf 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs @@ -40,7 +40,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -57,7 +56,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs b/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs index 73419f5..6de626d 100644 --- a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs @@ -44,7 +44,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.RecordDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -63,7 +62,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs b/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs index ce29398..dd803cf 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs @@ -40,7 +40,6 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.RecordDeclaration); - DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); } /// @@ -57,6 +56,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) { diff --git a/CodeDocumentor/GlobalSuppressions.cs b/CodeDocumentor/GlobalSuppressions.cs index 80c28b0..2ed3ae9 100644 --- a/CodeDocumentor/GlobalSuppressions.cs +++ b/CodeDocumentor/GlobalSuppressions.cs @@ -10,3 +10,9 @@ [assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~F:CodeDocumentor.Vsix2022.Settings._programDataFolder")] [assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.SaveToFile(System.String)")] [assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.GetSettingsFilePath~System.String")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~F:CodeDocumentor.Vsix2022.Settings._userProfileFolder")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.CodeDocumentorDefinedInEditorconfig~System.Boolean")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.IsCodeDocumentorDefinedInEditorconfig~System.Boolean")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.OptionPageGrid.SaveSettingsToStorage")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.SaveToEditorConfig")] +[assembly: SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers", Justification = "", Scope = "member", Target = "~M:CodeDocumentor.Vsix2022.Settings.IsCodeDocumentorDefinedInEditorConfig~System.Boolean")] diff --git a/CodeDocumentor/Interfaces/IOptionPageGrid.cs b/CodeDocumentor/Interfaces/IOptionPageGrid.cs index e1187e6..c51eebd 100644 --- a/CodeDocumentor/Interfaces/IOptionPageGrid.cs +++ b/CodeDocumentor/Interfaces/IOptionPageGrid.cs @@ -80,5 +80,13 @@ public interface IOptionPageGrid /// /// A list of wordmaps. WordMap[] WordMaps { get; set; } + + /// + /// Gets or Sets a value indicating whether to use the .editorconfig file for settings. + /// + /// + /// This will convert the existing settings to a %USERPROFILE% .editorconfig file + /// + bool UseEditorConfigForSettings { get; set; } } } diff --git a/CodeDocumentor/Models/OptionPageGrid.cs b/CodeDocumentor/Models/OptionPageGrid.cs index 7210ffa..42ad7d8 100644 --- a/CodeDocumentor/Models/OptionPageGrid.cs +++ b/CodeDocumentor/Models/OptionPageGrid.cs @@ -1,5 +1,7 @@ +using System; using System.ComponentModel; using System.Runtime.InteropServices; +using System.Windows.Forms; using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.Shell; @@ -191,17 +193,26 @@ public class OptionPageGrid : DialogPage, IOptionPageGrid /// /// Gets or Sets the word maps. /// - /// Aa array of wordmaps. + /// An array of wordmaps. [Category(TranslationSubCategory)] [DisplayName("Word mappings for creating comments")] [Description("When documenting if certain word are matched it will swap out to the translated mapping.")] public WordMap[] WordMaps { get; set; } + [Category(AnalyzerSubCategory)] + [DisplayName("Use .editorconfig for extension settings")] + [Description("This will convert existing extension settings to .editorconfig values stored in %USERPROFILE%. This allows CodeDocumentor to run out of process.")] + public bool UseEditorConfigForSettings { get; set; } + /// /// Load settings from storage. /// public override void LoadSettingsFromStorage() { + if (Settings.IsCodeDocumentorDefinedInEditorConfig()) { + UseEditorConfigForSettings = true; + return; + } var settings = Settings.Load(); IsEnabledForPublicMembersOnly = settings.IsEnabledForPublicMembersOnly; UseNaturalLanguageForReturnNode = settings.UseNaturalLanguageForReturnNode; @@ -221,6 +232,7 @@ public override void LoadSettingsFromStorage() PropertyDiagnosticSeverity = settings.PropertyDiagnosticSeverity; RecordDiagnosticSeverity = settings.RecordDiagnosticSeverity; IsEnabledForNonPublicFields = settings.IsEnabledForNonPublicFields; + UseEditorConfigForSettings = settings.UseEditorConfigForSettings; } /// @@ -247,8 +259,30 @@ public override void SaveSettingsToStorage() MethodDiagnosticSeverity = MethodDiagnosticSeverity, PropertyDiagnosticSeverity = PropertyDiagnosticSeverity, RecordDiagnosticSeverity = RecordDiagnosticSeverity, - IsEnabledForNonPublicFields = IsEnabledForNonPublicFields + IsEnabledForNonPublicFields = IsEnabledForNonPublicFields, + UseEditorConfigForSettings = UseEditorConfigForSettings }; + var response = DialogResult.No; + if (settings.UseEditorConfigForSettings) + { + response = MessageBox.Show( + $"This will convert existing extension settings to .editorconfig values. " + + $"This allows CodeDocumentor to run out of process. " + + $"Do you want to continue?{Environment.NewLine}" + + $"You will need to paste these settings into your %USERPROFILE% .editorconfig and restart Visual Studio.", + "Use .editorconfig for settings", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + } + if (response == DialogResult.Yes) + { + settings.SaveToEditorConfig(); + MessageBox.Show("Settings have been copied to the clipboard. Update your .editorconfig file in %USERPROFILE% with the contents to use the new settings. You will need to restart Visual Studio.", + "Settings copied to clipboard", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + + } settings.Save(); var optionsService = CodeDocumentorPackage._optService; optionsService.Update(settings); diff --git a/CodeDocumentor/Models/Settings.cs b/CodeDocumentor/Models/Settings.cs index 72cd0e2..b8e6835 100644 --- a/CodeDocumentor/Models/Settings.cs +++ b/CodeDocumentor/Models/Settings.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Windows.Forms; using Microsoft.CodeAnalysis; // For definitions of XML nodes see: @@ -9,59 +12,60 @@ namespace CodeDocumentor.Vsix2022 { public class Settings : IOptionPageGrid { + const string PREFIX = "codedocumentor_"; + //This impl was adopted from https://github.com/mike-ward/VSColorOutput64/tree/db549b54709ca77ae5538c4046c332f1e51f90e7 private static readonly string _programDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CodeDocumentor"); + private static readonly string _userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + public DiagnosticSeverity? ClassDiagnosticSeverity { get; set; } public DiagnosticSeverity? ConstructorDiagnosticSeverity { get; set; } - /// - /// Gets or Sets the default diagnostic severity. - /// public DiagnosticSeverity DefaultDiagnosticSeverity { get; set; } = DiagnosticSeverity.Warning; public DiagnosticSeverity? EnumDiagnosticSeverity { get; set; } + public DiagnosticSeverity? FieldDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? InterfaceDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? MethodDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? PropertyDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? RecordDiagnosticSeverity { get; set; } + /// /// Gets or Sets a value indicating whether exclude asynchronously suffix. /// /// A bool. public bool ExcludeAsyncSuffix { get; set; } - public DiagnosticSeverity? FieldDiagnosticSeverity { get; set; } - /// /// Gets or Sets a value indicating whether include value node in properties. /// /// A bool. public bool IncludeValueNodeInProperties { get; set; } - public DiagnosticSeverity? InterfaceDiagnosticSeverity { get; set; } - - /// - /// Gets or Sets a value indicating whether enabled for non public is fields. - /// - public bool IsEnabledForNonPublicFields { get; set; } - /// /// Gets or Sets a value indicating whether enabled for publish members is only. /// /// A bool. public bool IsEnabledForPublicMembersOnly { get; set; } - public DiagnosticSeverity? MethodDiagnosticSeverity { get; set; } + /// + /// Gets or Sets a value indicating whether enabled for non public is fields. + /// + public bool IsEnabledForNonPublicFields { get; set; } /// /// Gets or Sets a value indicating whether preserve existing summary text. /// public bool PreserveExistingSummaryText { get; set; } = true; - public DiagnosticSeverity? PropertyDiagnosticSeverity { get; set; } - - public DiagnosticSeverity? RecordDiagnosticSeverity { get; set; } - /// /// Gets or Sets a value indicating whether use try and include crefs in method comments. /// @@ -86,6 +90,14 @@ public class Settings : IOptionPageGrid /// An array of wordmaps. public WordMap[] WordMaps { get; set; } = Constants.DEFAULT_WORD_MAPS; + /// + /// Gets or Sets a value indicating whether to use the .editorconfig file for settings. + /// + /// + /// This will convert the existing settings to a %USERPROFILE% .editorconfig file + /// + public bool UseEditorConfigForSettings { get; set; } + public static event EventHandler SettingsUpdated; /// @@ -105,6 +117,17 @@ public static Settings Load() return settings; } + public static bool IsCodeDocumentorDefinedInEditorConfig() + { + var editorConfigPath = Path.Combine(_userProfileFolder, ".editorconfig"); + if (!File.Exists(editorConfigPath)) + { + return false; + } + var lines = File.ReadAllLines(editorConfigPath); + return lines.Any(line => line.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase)); + } + /// /// Saves the settings /// @@ -115,11 +138,63 @@ public void Save() return; } + Directory.CreateDirectory(_programDataFolder); SaveToFile(GetSettingsFilePath()); OnSettingsUpdated(this, EventArgs.Empty); } + public void SaveToEditorConfig() + { + if (Runtime.RunningUnitTests) + { + return; + } + + var editorConfigPath = Path.Combine(_userProfileFolder, ".editorconfig"); + var lines = File.ReadAllLines(editorConfigPath).ToList(); + + var clipboardLInes = new List(); + + if (!lines.Any(line => line.StartsWith("[*.cs]", StringComparison.OrdinalIgnoreCase))) + { + clipboardLInes.Add("[*.cs]"); + } + if (!lines.Any(line => line.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase))) + { + clipboardLInes.Add("# CodeDocumentor settings"); + } + + clipboardLInes.Add($"{PREFIX}class_diagram_severity = {ClassDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}constructor_diagram_severity = {ConstructorDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}default_diagram_severity = {DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}enum_diagram_severity = {EnumDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}field_diagram_severity = {FieldDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}interface_diagram_severity = {InterfaceDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}method_diagram_severity = {MethodDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}property_diagram_severity = {PropertyDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}record_diagram_severity = {RecordDiagnosticSeverity ?? DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}exclude_async_suffix = {ExcludeAsyncSuffix}"); + clipboardLInes.Add($"{PREFIX}include_value_node_in_properties = {IncludeValueNodeInProperties}"); + clipboardLInes.Add($"{PREFIX}is_enabled_for_public_members_only = {IsEnabledForPublicMembersOnly}"); + clipboardLInes.Add($"{PREFIX}is_enabled_for_non_public_fields = {IsEnabledForNonPublicFields}"); + clipboardLInes.Add($"{PREFIX}preserve_existing_summary_text = {PreserveExistingSummaryText}"); + clipboardLInes.Add($"{PREFIX}try_to_include_crefs_for_return_types = {TryToIncludeCrefsForReturnTypes}"); + clipboardLInes.Add($"{PREFIX}use_natural_language_for_return_node = {UseNaturalLanguageForReturnNode}"); + clipboardLInes.Add($"{PREFIX}use_todo_comments_on_summary_error = {UseToDoCommentsOnSummaryError}"); + + if (WordMaps != null && WordMaps.Length > 0) + { + for (var i = 0; i < WordMaps.Length; i++) + { + var word = WordMaps[i]?.Word ?? string.Empty; + var translation = WordMaps[i]?.Translation ?? string.Empty; + clipboardLInes.Add($"{PREFIX}wordmap_{i} = {word}:{translation}"); + } + } + Clipboard.SetText(string.Join(Environment.NewLine, lines)); + } + /// /// Saves the settings to file. /// diff --git a/CodeDocumentor/Services/OptionsService.cs b/CodeDocumentor/Services/OptionsService.cs index a9a64f1..30c479f 100644 --- a/CodeDocumentor/Services/OptionsService.cs +++ b/CodeDocumentor/Services/OptionsService.cs @@ -52,6 +52,8 @@ public class OptionsService : IOptionsService public WordMap[] WordMaps { get; set; } + public bool UseEditorConfigForSettings { get; set; } + public IOptionsService Clone() { var newService = new OptionsService diff --git a/Manifests/vs2022/source.extension.vsixmanifest b/Manifests/vs2022/source.extension.vsixmanifest index 66374b2..c55aff2 100644 --- a/Manifests/vs2022/source.extension.vsixmanifest +++ b/Manifests/vs2022/source.extension.vsixmanifest @@ -1,44 +1,44 @@ - - - CodeDocumentor - An Extension to generate XML documentation automatically using IntelliSense for interface,class,enum, field, constructor, property and method. - logo.png - - + + + CodeDocumentor + An Extension to generate XML documentation automatically using IntelliSense for interface,class,enum, field, constructor, property and method. + logo.png + + - - amd64 - - - amd64 - - - amd64 - - - arm64 - - - arm64 - - - arm64 - - - - - - - - - - - - - - - - + + amd64 + + + amd64 + + + amd64 + + + arm64 + + + arm64 + + + arm64 + + + + + + + + + + + + + + + + From c4210dab3e4b29ca8a4ef8c94dab0c04dbe1599c Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sun, 24 Aug 2025 14:04:01 -0600 Subject: [PATCH 14/32] split out common to netstandard2.0 --- .../CodeDocumentor.Common.csproj | 13 + .../Constants.cs | 5 +- .../Extensions/SettingsExtensions.cs | 134 ++++++++++ .../Extensions/WordExtensions.cs | 142 +++++++++++ .../Helpers}/DictionaryExtensions.cs | 4 +- .../Helpers}/NameSplitter.cs | 3 +- .../Helpers}/Pluralizer.cs | 5 +- .../Helpers}/TokenHelper.cs | 11 +- .../Helpers}/TryHelper.cs | 18 +- .../Interfaces/IEventLogger.cs | 11 + .../Interfaces/IOptionPageGrid.cs | 17 +- .../Models/ReturnTypeBuilderOptions.cs | 3 +- .../Models/Runtime.cs | 2 +- CodeDocumentor.Common/Models/Settings.cs | 90 +++++++ .../Models/WordMap.cs | 2 +- .../Models/XmlInformation.cs | 2 +- .../CodeDocumentor.Test.csproj | 1 - .../Helper/NameSplitterTests.cs | 1 + .../Helper/ReturnCommentConstructionTests.cs | 1 + CodeDocumentor.Test/Helper/TranslatorTests.cs | 2 + .../Helper/WordExtensionsTests.cs | 2 + CodeDocumentor.Test/TestFixture.cs | 1 + .../TestHelpers/TestOptionsService.cs | 5 +- CodeDocumentor.sln | 14 ++ .../Analyzers/BaseAnalyzerSettings.cs | 8 +- .../Analyzers/BaseCodeFixProvider.cs | 7 +- .../Analyzers/BaseDiagnosticAnalyzer.cs | 5 + .../Analyzers/Classes/ClassAnalyzer.cs | 5 + .../Classes/ClassAnalyzerSettings.cs | 2 +- .../Analyzers/Classes/ClassCodeFixProvider.cs | 10 +- .../ConstructorAnalyzerSettings.cs | 2 +- .../ConstructorCodeFixProvider.cs | 6 +- .../Analyzers/Enums/EnumAnalyzerSettings.cs | 2 +- .../Analyzers/Enums/EnumCodeFixProvider.cs | 6 +- .../Analyzers/Fields/FieldAnalyzerSettings.cs | 2 +- .../Analyzers/Fields/FieldCodeFixProvider.cs | 6 +- .../Interfaces/InterfaceAnalyzerSettings.cs | 2 +- .../Interfaces/InterfaceCodeFixProvider.cs | 6 +- .../Methods/MethodAnalyzerSettings.cs | 2 +- .../Methods/MethodCodeFixProvider.cs | 6 +- .../Properties/PropertyAnalyzerSettings.cs | 2 +- .../Properties/PropertyCodeFixProvider.cs | 7 +- .../Records/RecordAnalyzerSettings.cs | 2 +- .../Records/RecordCodeFixProvider.cs | 6 +- .../Builders/DocumentationBuilder.cs | 3 +- CodeDocumentor/CodeDocumentor.Package.cs | 4 +- CodeDocumentor/CodeDocumentor.csproj | 27 +- .../BaseReturnTypeCommentConstruction.cs | 1 + .../Constructors/ReturnCommentConstruction.cs | 1 + .../SingleWordCommentSummaryConstruction.cs | 1 + CodeDocumentor/Helper/CommentHelper.cs | 15 +- .../Helper/DocumentationHeaderHelper.cs | 14 +- .../{Models/Log.cs => Helper/Logger.cs} | 13 +- CodeDocumentor/Helper/Translator.cs | 3 +- CodeDocumentor/Helper/WordExtensions.cs | 134 ---------- .../Managers/GenericCommentManager.cs | 1 + CodeDocumentor/Models/OptionPageGrid.cs | 13 +- CodeDocumentor/Models/Settings.cs | 231 ------------------ CodeDocumentor/Properties/AssemblyInfo.cs | 2 +- CodeDocumentor/Services/OptionsService.cs | 25 +- CodeDocumentor/Settings/VsixOptions.cs | 2 +- .../vs2022/source.extension.vsixmanifest | 2 +- 62 files changed, 571 insertions(+), 504 deletions(-) create mode 100644 CodeDocumentor.Common/CodeDocumentor.Common.csproj rename {CodeDocumentor/Models => CodeDocumentor.Common}/Constants.cs (99%) create mode 100644 CodeDocumentor.Common/Extensions/SettingsExtensions.cs create mode 100644 CodeDocumentor.Common/Extensions/WordExtensions.cs rename {CodeDocumentor/Helper => CodeDocumentor.Common/Helpers}/DictionaryExtensions.cs (84%) rename {CodeDocumentor/Helper => CodeDocumentor.Common/Helpers}/NameSplitter.cs (98%) rename {CodeDocumentor/Helper => CodeDocumentor.Common/Helpers}/Pluralizer.cs (93%) rename {CodeDocumentor/Helper => CodeDocumentor.Common/Helpers}/TokenHelper.cs (84%) rename {CodeDocumentor/Helper => CodeDocumentor.Common/Helpers}/TryHelper.cs (53%) create mode 100644 CodeDocumentor.Common/Interfaces/IEventLogger.cs rename {CodeDocumentor => CodeDocumentor.Common}/Interfaces/IOptionPageGrid.cs (91%) rename {CodeDocumentor => CodeDocumentor.Common}/Models/ReturnTypeBuilderOptions.cs (97%) rename {CodeDocumentor => CodeDocumentor.Common}/Models/Runtime.cs (92%) create mode 100644 CodeDocumentor.Common/Models/Settings.cs rename {CodeDocumentor => CodeDocumentor.Common}/Models/WordMap.cs (96%) rename {CodeDocumentor => CodeDocumentor.Common}/Models/XmlInformation.cs (96%) rename CodeDocumentor/{Models/Log.cs => Helper/Logger.cs} (83%) delete mode 100644 CodeDocumentor/Models/Settings.cs diff --git a/CodeDocumentor.Common/CodeDocumentor.Common.csproj b/CodeDocumentor.Common/CodeDocumentor.Common.csproj new file mode 100644 index 0000000..d670910 --- /dev/null +++ b/CodeDocumentor.Common/CodeDocumentor.Common.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + + + + + + + + + diff --git a/CodeDocumentor/Models/Constants.cs b/CodeDocumentor.Common/Constants.cs similarity index 99% rename from CodeDocumentor/Models/Constants.cs rename to CodeDocumentor.Common/Constants.cs index 5f9672b..7877683 100644 --- a/CodeDocumentor/Models/Constants.cs +++ b/CodeDocumentor.Common/Constants.cs @@ -1,11 +1,12 @@ // For definitions of XML nodes see: // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see // also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags +using System; using System.Collections.Generic; -using CodeDocumentor.Helper; +using CodeDocumentor.Common.Models; using Microsoft.CodeAnalysis; -namespace CodeDocumentor.Vsix2022 +namespace CodeDocumentor.Common { public static class Constants { diff --git a/CodeDocumentor.Common/Extensions/SettingsExtensions.cs b/CodeDocumentor.Common/Extensions/SettingsExtensions.cs new file mode 100644 index 0000000..0c25db0 --- /dev/null +++ b/CodeDocumentor.Common/Extensions/SettingsExtensions.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using CodeDocumentor.Common.Models; + +namespace CodeDocumentor.Common.Extensions +{ + public static class SettingsExtensions + { + public const string PREFIX = "codedocumentor_"; + //This impl was adopted from https://github.com/mike-ward/VSColorOutput64/tree/db549b54709ca77ae5538c4046c332f1e51f90e7 + + private static readonly string _programDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CodeDocumentor"); + + private static readonly string _userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + + + public static void Save(this Settings settings) + { + if (Runtime.RunningUnitTests) + { + return; + } + + + Directory.CreateDirectory(_programDataFolder); + settings.SaveToFile(GetSettingsFilePath()); + } + + + /// + /// Loads the . + /// + /// A Settings. + public static Settings Load(this Settings settings) + { + if (Runtime.RunningUnitTests) + { + return new Settings(); + } + + Directory.CreateDirectory(_programDataFolder); + var json = File.ReadAllText(GetSettingsFilePath()); + settings = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + return settings; + } + + public static bool IsCodeDocumentorDefinedInEditorConfig(this Settings settings) + { + var editorConfigPath = Path.Combine(_userProfileFolder, ".editorconfig"); + if (!File.Exists(editorConfigPath)) + { + return false; + } + var lines = File.ReadAllLines(editorConfigPath); + return lines.Any(line => line.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase)); + } + + public static void SaveToEditorConfig(this Settings settings, Action setToClipboardAction) + { + if (Runtime.RunningUnitTests) + { + return; + } + + var editorConfigPath = Path.Combine(_userProfileFolder, ".editorconfig"); + var lines = File.ReadAllLines(editorConfigPath).ToList(); + + var clipboardLInes = new List(); + + if (!lines.Any(line => line.StartsWith("[*.cs]", StringComparison.OrdinalIgnoreCase))) + { + clipboardLInes.Add("[*.cs]"); + } + if (!lines.Any(line => line.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase))) + { + clipboardLInes.Add("# CodeDocumentor settings"); + } + + clipboardLInes.Add($"{PREFIX}class_diagram_severity = {settings.ClassDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}constructor_diagram_severity = {settings.ConstructorDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}default_diagram_severity = {settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}enum_diagram_severity = {settings.EnumDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}field_diagram_severity = {settings.FieldDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}interface_diagram_severity = {settings.InterfaceDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}method_diagram_severity = {settings.MethodDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}property_diagram_severity = {settings.PropertyDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}record_diagram_severity = {settings.RecordDiagnosticSeverity ?? settings.DefaultDiagnosticSeverity}"); + clipboardLInes.Add($"{PREFIX}exclude_async_suffix = {settings.ExcludeAsyncSuffix}"); + clipboardLInes.Add($"{PREFIX}include_value_node_in_properties = {settings.IncludeValueNodeInProperties}"); + clipboardLInes.Add($"{PREFIX}is_enabled_for_public_members_only = {settings.IsEnabledForPublicMembersOnly}"); + clipboardLInes.Add($"{PREFIX}is_enabled_for_non_public_fields = {settings.IsEnabledForNonPublicFields}"); + clipboardLInes.Add($"{PREFIX}preserve_existing_summary_text = {settings.PreserveExistingSummaryText}"); + clipboardLInes.Add($"{PREFIX}try_to_include_crefs_for_return_types = {settings.TryToIncludeCrefsForReturnTypes}"); + clipboardLInes.Add($"{PREFIX}use_natural_language_for_return_node = {settings.UseNaturalLanguageForReturnNode}"); + clipboardLInes.Add($"{PREFIX}use_todo_comments_on_summary_error = {settings.UseToDoCommentsOnSummaryError}"); + + if (settings.WordMaps != null && settings.WordMaps.Length > 0) + { + var maps = settings.WordMaps.Where(wm => !string.IsNullOrWhiteSpace(wm?.Word) || !string.IsNullOrWhiteSpace(wm?.Translation)) + .Select(s => $"{s.Word}:{s.Translation}").ToList(); + clipboardLInes.Add($"{PREFIX}wordmap = {string.Join("|", maps)}"); + } + setToClipboardAction.Invoke(string.Join(Environment.NewLine, clipboardLInes)); + } + + /// + /// Saves the settings to file. + /// + /// The path. + public static void SaveToFile(this Settings settings, string path) + { + File.WriteAllText(path, Newtonsoft.Json.JsonConvert.SerializeObject(settings)); + } + + /// + /// Gets the settings file path. + /// + /// A string. + private static string GetSettingsFilePath() + { + const string name = "codedocumentor.json"; + var settingsPath = Path.Combine(_programDataFolder, name); + + if (!File.Exists(settingsPath)) + { + new Settings().SaveToFile(settingsPath); + } + + return settingsPath; + } + } +} diff --git a/CodeDocumentor.Common/Extensions/WordExtensions.cs b/CodeDocumentor.Common/Extensions/WordExtensions.cs new file mode 100644 index 0000000..c5fd5ff --- /dev/null +++ b/CodeDocumentor.Common/Extensions/WordExtensions.cs @@ -0,0 +1,142 @@ +#pragma warning disable IDE0130 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using CodeDocumentor.Common; + +namespace System +{ + public static class WordExtensions + { + private static readonly Regex _xmlElementRegEx = new Regex(Constants.XML_ELEMENT_ONLY_MATCH_REGEX_TEMPLATE); + + public static string Clean(this string word) + { + var pattern = "[^a-zA-Z0-9 ]"; + return Regex.Replace(word, pattern, ""); + } + + public static string GetWordFirstPart(this string word) + { + var checkWord = word; + if (word.Contains(" ")) //a translation already happened and swapped a word for a set of words. the first word is really what we are checking + { + checkWord = word.Split(' ').First(); + } + return checkWord; + } + + public static bool IsPastTense(this string word) + { + // Check if the word ends with "-ed" + return word.EndsWith("ed"); + } + + public static bool IsIngVerb(this string word) + { + // Check if the word ends with "-ed" + return word.EndsWith("ing") && !word.Equals("string", StringComparison.InvariantCultureIgnoreCase); + } + + public static bool IsTwoLetterPropertyExclusionVerb(this string word) + { + var checkWord = word.GetWordFirstPart().Clean(); + return Constants.TWO_LETTER_PROPERTY_WORD_EXCLUSION_LIST.Any(w => w.Equals(checkWord, StringComparison.InvariantCultureIgnoreCase)); + } + + public static bool IsTwoLetterVerb(this string word) + { + var checkWord = word.GetWordFirstPart().Clean(); + return Constants.TWO_LETTER_WORD_LIST.Any(w => w.Equals(checkWord, StringComparison.InvariantCultureIgnoreCase)); + } + + public static bool IsVerb(this string word) + { + var checkWord = word.GetWordFirstPart().Clean(); + var variations = new List(); + var baseWord = checkWord; + if (checkWord.IsIngVerb()) + { + return true; + } + else if (Constants.PAST_TENSE_WORDS_NOT_VERBS.Any(a => a.Equals(checkWord, StringComparison.InvariantCultureIgnoreCase))) + { + return false; + } + else if (baseWord.IsPastTense()) //remove "ed" + { + baseWord = baseWord.Substring(0, checkWord.Length - 2); + } + else if (baseWord.EndsWith("s") && !Constants.LETTER_S_SUFFIX_EXCLUSION_FOR_PLURALIZER.Any(a => a.Equals(baseWord, StringComparison.InvariantCultureIgnoreCase))) + { + baseWord = baseWord.Substring(0, checkWord.Length - 1); + } + + return Constants.GetInternalVerbCheckList().Any(w => + w.Equals(baseWord, StringComparison.InvariantCultureIgnoreCase) + || checkWord.Equals((w + "ed"), StringComparison.InvariantCultureIgnoreCase) + //|| checkWord.Equals((w + "ing"), System.StringComparison.InvariantCultureIgnoreCase) + || (checkWord.Equals((w + "s"), StringComparison.InvariantCultureIgnoreCase) + && !Constants.LETTER_S_SUFFIX_EXCLUSION_FOR_PLURALIZER.Any(a => a.Equals(w, StringComparison.InvariantCultureIgnoreCase))) + ); + } + + public static bool IsVerbCombo(this string word, string nextWord = null) + { + if (string.IsNullOrEmpty(word)) + { + return false; + } + var skipWord = word.IsVerb(); + var skipNextWord = false; + if (!string.IsNullOrEmpty(nextWord) && !skipWord) + { + skipNextWord = nextWord.IsVerb(); + } + return skipWord || skipNextWord; + } + + public static bool IsXml(this string str) + { + if (string.IsNullOrEmpty(str)) + { + return false; + } + return _xmlElementRegEx.IsMatch(str); + } + + public static bool StartsWith_A_An_And(this string str) + { + if (string.IsNullOrEmpty(str)) + { + return false; + } + return str.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) || + str.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) || + str.StartsWith("and ", StringComparison.InvariantCultureIgnoreCase); + } + + public static string ToTitleCase(this string txt) + { + if (string.IsNullOrEmpty(txt)) + { + return txt; + } + + return char.ToUpper(txt[0]) + txt.Substring(1); + } + + public static void TryAddSingleWord(this List words, List singleWord, bool clearSingleWord = false) + { + if (singleWord.Any()) + { + words.Add(new string(singleWord.ToArray())); + } + if (clearSingleWord) + { + singleWord.Clear(); + } + } + } +} diff --git a/CodeDocumentor/Helper/DictionaryExtensions.cs b/CodeDocumentor.Common/Helpers/DictionaryExtensions.cs similarity index 84% rename from CodeDocumentor/Helper/DictionaryExtensions.cs rename to CodeDocumentor.Common/Helpers/DictionaryExtensions.cs index d461a32..9c5e148 100644 --- a/CodeDocumentor/Helper/DictionaryExtensions.cs +++ b/CodeDocumentor.Common/Helpers/DictionaryExtensions.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +#pragma warning disable IDE0130 -namespace CodeDocumentor.Helper +namespace System.Collections.Generic { public static class DictionaryExtensions { diff --git a/CodeDocumentor/Helper/NameSplitter.cs b/CodeDocumentor.Common/Helpers/NameSplitter.cs similarity index 98% rename from CodeDocumentor/Helper/NameSplitter.cs rename to CodeDocumentor.Common/Helpers/NameSplitter.cs index 4d69cbf..2cccae1 100644 --- a/CodeDocumentor/Helper/NameSplitter.cs +++ b/CodeDocumentor.Common/Helpers/NameSplitter.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using CodeDocumentor.Common.Extensions; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common { /// /// The name splitter. diff --git a/CodeDocumentor/Helper/Pluralizer.cs b/CodeDocumentor.Common/Helpers/Pluralizer.cs similarity index 93% rename from CodeDocumentor/Helper/Pluralizer.cs rename to CodeDocumentor.Common/Helpers/Pluralizer.cs index b3e54b2..9d74f2e 100644 --- a/CodeDocumentor/Helper/Pluralizer.cs +++ b/CodeDocumentor.Common/Helpers/Pluralizer.cs @@ -1,4 +1,7 @@ -namespace CodeDocumentor.Helper +#pragma warning disable IDE0130 +using CodeDocumentor.Common.Extensions; + +namespace System { public static class Pluralizer { diff --git a/CodeDocumentor/Helper/TokenHelper.cs b/CodeDocumentor.Common/Helpers/TokenHelper.cs similarity index 84% rename from CodeDocumentor/Helper/TokenHelper.cs rename to CodeDocumentor.Common/Helpers/TokenHelper.cs index b6e9a1a..d4c4a1d 100644 --- a/CodeDocumentor/Helper/TokenHelper.cs +++ b/CodeDocumentor.Common/Helpers/TokenHelper.cs @@ -1,16 +1,15 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; -using CodeDocumentor.Vsix2022; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common { //This takes XML nodes in a string and swaps them to tokens for string manipulation, and then replaces them once complete. This keeps the validity of the XML - internal static class TokenHelper + public static class TokenHelper { private static readonly Regex _xmlElementRegEx = new Regex(Constants.XML_ELEMENT_MATCH_REGEX_TEMPLATE); - internal static void SwapXmlTokens(this List parts, Func swapLineCallback, int startingIndex = 0) + public static void SwapXmlTokens(this List parts, Func swapLineCallback, int startingIndex = 0) { var i = startingIndex; var swaps = new Dictionary(); @@ -34,7 +33,7 @@ internal static void SwapXmlTokens(this List parts, Func } } - internal static string SwapXmlTokens(this string content, Func swapLineCallback, int startingIndex = 0) + public static string SwapXmlTokens(this string content, Func swapLineCallback, int startingIndex = 0) { var i = startingIndex; var swaps = new Dictionary(); @@ -54,7 +53,7 @@ internal static string SwapXmlTokens(this string content, Func s return content; } - internal static (string replacedString, Dictionary tokens) SwapXmlTokens(this string content, int startingIndex = 0) + public static (string replacedString, Dictionary tokens) SwapXmlTokens(this string content, int startingIndex = 0) { var i = startingIndex; var swaps = new Dictionary(); diff --git a/CodeDocumentor/Helper/TryHelper.cs b/CodeDocumentor.Common/Helpers/TryHelper.cs similarity index 53% rename from CodeDocumentor/Helper/TryHelper.cs rename to CodeDocumentor.Common/Helpers/TryHelper.cs index 7b0053a..5a508ae 100644 --- a/CodeDocumentor/Helper/TryHelper.cs +++ b/CodeDocumentor.Common/Helpers/TryHelper.cs @@ -1,11 +1,11 @@ using System; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common.Interfaces; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common { - internal static class TryHelper + public static class TryHelper { - internal static void Try(Action action, string diagnosticId, Action exceptionCallback = null, bool reThrow = false, int eventId = 0, short category = 0) + public static void Try(Action action, string diagnosticId, IEventLogger logger, Action exceptionCallback = null, bool reThrow = false, int eventId = 0, short category = 0) { try { @@ -13,7 +13,7 @@ internal static void Try(Action action, string diagnosticId, Action e } catch (Exception ex) { - Log.LogError(ex.ToString(), eventId, category, diagnosticId); + logger.LogError(ex.ToString(), eventId, category, diagnosticId); exceptionCallback?.Invoke(ex); if (reThrow) { @@ -22,7 +22,7 @@ internal static void Try(Action action, string diagnosticId, Action e } } - internal static TResult Try(Func action, string diagnosticId, Func exceptionCallback, bool reThrow = false, int eventId = 0, short category = 0) + public static TResult Try(Func action, string diagnosticId, IEventLogger logger, Func exceptionCallback, bool reThrow = false, int eventId = 0, short category = 0) { try { @@ -30,7 +30,7 @@ internal static TResult Try(Func action, string diagnosticId, } catch (Exception ex) { - Log.LogError(ex.ToString(), eventId, category, diagnosticId); + logger.LogError(ex.ToString(), eventId, category, diagnosticId); if (reThrow) { throw; @@ -39,7 +39,7 @@ internal static TResult Try(Func action, string diagnosticId, } } - internal static TResult Try(Func action, string diagnosticId, Action exceptionCallback = null, bool reThrow = false, int eventId = 0, short category = 0) + public static TResult Try(Func action, string diagnosticId, IEventLogger logger, Action exceptionCallback = null, bool reThrow = false, int eventId = 0, short category = 0) { try { @@ -47,7 +47,7 @@ internal static TResult Try(Func action, string diagnosticId, } catch (Exception ex) { - Log.LogError(ex.ToString(), eventId, category, diagnosticId); + logger.LogError(ex.ToString(), eventId, category, diagnosticId); exceptionCallback?.Invoke(ex); if (reThrow) { diff --git a/CodeDocumentor.Common/Interfaces/IEventLogger.cs b/CodeDocumentor.Common/Interfaces/IEventLogger.cs new file mode 100644 index 0000000..a8c4fcf --- /dev/null +++ b/CodeDocumentor.Common/Interfaces/IEventLogger.cs @@ -0,0 +1,11 @@ +// For definitions of XML nodes see: +// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see +// also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags +namespace CodeDocumentor.Common.Interfaces +{ + public interface IEventLogger + { + void LogError(string message, int eventId, short category, string diagnosticId); + void LogInfo(string message, int eventId, short category, string diagnosticId); + } +} diff --git a/CodeDocumentor/Interfaces/IOptionPageGrid.cs b/CodeDocumentor.Common/Interfaces/IOptionPageGrid.cs similarity index 91% rename from CodeDocumentor/Interfaces/IOptionPageGrid.cs rename to CodeDocumentor.Common/Interfaces/IOptionPageGrid.cs index c51eebd..5c07499 100644 --- a/CodeDocumentor/Interfaces/IOptionPageGrid.cs +++ b/CodeDocumentor.Common/Interfaces/IOptionPageGrid.cs @@ -1,9 +1,10 @@ +using CodeDocumentor.Common.Models; using Microsoft.CodeAnalysis; // For definitions of XML nodes see: // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see // also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags -namespace CodeDocumentor.Vsix2022 +namespace CodeDocumentor.Common.Interfaces { public interface IOptionPageGrid { @@ -63,6 +64,12 @@ public interface IOptionPageGrid /// A bool. bool TryToIncludeCrefsForReturnTypes { get; set; } + /// + /// Gets or Sets a value indicating whether to use the .editorconfig file for settings. + /// + /// This will convert the existing settings to a %USERPROFILE% .editorconfig file + bool UseEditorConfigForSettings { get; set; } + /// /// Gets or Sets a value indicating whether use natural language for return node. /// @@ -80,13 +87,5 @@ public interface IOptionPageGrid /// /// A list of wordmaps. WordMap[] WordMaps { get; set; } - - /// - /// Gets or Sets a value indicating whether to use the .editorconfig file for settings. - /// - /// - /// This will convert the existing settings to a %USERPROFILE% .editorconfig file - /// - bool UseEditorConfigForSettings { get; set; } } } diff --git a/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs b/CodeDocumentor.Common/Models/ReturnTypeBuilderOptions.cs similarity index 97% rename from CodeDocumentor/Models/ReturnTypeBuilderOptions.cs rename to CodeDocumentor.Common/Models/ReturnTypeBuilderOptions.cs index e605160..1b1ad0c 100644 --- a/CodeDocumentor/Models/ReturnTypeBuilderOptions.cs +++ b/CodeDocumentor.Common/Models/ReturnTypeBuilderOptions.cs @@ -1,5 +1,4 @@ - -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common.Models { public class ReturnTypeBuilderOptions { diff --git a/CodeDocumentor/Models/Runtime.cs b/CodeDocumentor.Common/Models/Runtime.cs similarity index 92% rename from CodeDocumentor/Models/Runtime.cs rename to CodeDocumentor.Common/Models/Runtime.cs index f7abba6..1ff4c2a 100644 --- a/CodeDocumentor/Models/Runtime.cs +++ b/CodeDocumentor.Common/Models/Runtime.cs @@ -1,7 +1,7 @@ // For definitions of XML nodes see: // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see // also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags -namespace CodeDocumentor.Vsix2022 +namespace CodeDocumentor.Common.Models { public static class Runtime { diff --git a/CodeDocumentor.Common/Models/Settings.cs b/CodeDocumentor.Common/Models/Settings.cs new file mode 100644 index 0000000..4aea175 --- /dev/null +++ b/CodeDocumentor.Common/Models/Settings.cs @@ -0,0 +1,90 @@ + +using CodeDocumentor.Common.Interfaces; +using Microsoft.CodeAnalysis; + +// For definitions of XML nodes see: +// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see +// also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags +namespace CodeDocumentor.Common.Models +{ + public class Settings : IOptionPageGrid + { + public DiagnosticSeverity? ClassDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? ConstructorDiagnosticSeverity { get; set; } + + public DiagnosticSeverity DefaultDiagnosticSeverity { get; set; } = DiagnosticSeverity.Warning; + + public DiagnosticSeverity? EnumDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? FieldDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? InterfaceDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? MethodDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? PropertyDiagnosticSeverity { get; set; } + + public DiagnosticSeverity? RecordDiagnosticSeverity { get; set; } + + /// + /// Gets or Sets a value indicating whether exclude asynchronously suffix. + /// + /// A bool. + public bool ExcludeAsyncSuffix { get; set; } + + /// + /// Gets or Sets a value indicating whether include value node in properties. + /// + /// A bool. + public bool IncludeValueNodeInProperties { get; set; } + + /// + /// Gets or Sets a value indicating whether enabled for publish members is only. + /// + /// A bool. + public bool IsEnabledForPublicMembersOnly { get; set; } + + /// + /// Gets or Sets a value indicating whether enabled for non public is fields. + /// + public bool IsEnabledForNonPublicFields { get; set; } + + /// + /// Gets or Sets a value indicating whether preserve existing summary text. + /// + public bool PreserveExistingSummaryText { get; set; } = true; + + /// + /// Gets or Sets a value indicating whether use try and include crefs in method comments. + /// + /// A bool. + public bool TryToIncludeCrefsForReturnTypes { get; set; } + + /// + /// Gets or Sets a value indicating whether use natural language for return node. + /// + /// A bool. + public bool UseNaturalLanguageForReturnNode { get; set; } + + /// + /// Gets or Sets a value indicating whether use to do comments on summary error. + /// + /// A bool. + public bool UseToDoCommentsOnSummaryError { get; set; } + + /// + /// Gets or Sets the word maps. + /// + /// An array of wordmaps. + public WordMap[] WordMaps { get; set; } = Constants.DEFAULT_WORD_MAPS; + + /// + /// Gets or Sets a value indicating whether to use the .editorconfig file for settings. + /// + /// + /// This will convert the existing settings to a %USERPROFILE% .editorconfig file + /// + public bool UseEditorConfigForSettings { get; set; } + } +} diff --git a/CodeDocumentor/Models/WordMap.cs b/CodeDocumentor.Common/Models/WordMap.cs similarity index 96% rename from CodeDocumentor/Models/WordMap.cs rename to CodeDocumentor.Common/Models/WordMap.cs index 9f89762..5933bb8 100644 --- a/CodeDocumentor/Models/WordMap.cs +++ b/CodeDocumentor.Common/Models/WordMap.cs @@ -3,7 +3,7 @@ // also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags using System; -namespace CodeDocumentor.Vsix2022 +namespace CodeDocumentor.Common.Models { public class WordMap { diff --git a/CodeDocumentor/Models/XmlInformation.cs b/CodeDocumentor.Common/Models/XmlInformation.cs similarity index 96% rename from CodeDocumentor/Models/XmlInformation.cs rename to CodeDocumentor.Common/Models/XmlInformation.cs index cc16a4a..060662a 100644 --- a/CodeDocumentor/Models/XmlInformation.cs +++ b/CodeDocumentor.Common/Models/XmlInformation.cs @@ -3,7 +3,7 @@ // also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags using System.Text.RegularExpressions; -namespace CodeDocumentor.Vsix2022 +namespace CodeDocumentor.Common.Models { public class XmlInformation { diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index 550304e..2e133a4 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -501,7 +501,6 @@ - all diff --git a/CodeDocumentor.Test/Helper/NameSplitterTests.cs b/CodeDocumentor.Test/Helper/NameSplitterTests.cs index 8a36b6f..de8cc34 100644 --- a/CodeDocumentor.Test/Helper/NameSplitterTests.cs +++ b/CodeDocumentor.Test/Helper/NameSplitterTests.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using CodeDocumentor.Common; using CodeDocumentor.Helper; using FluentAssertions; using Xunit; diff --git a/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs b/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs index 2b518d5..b340cc2 100644 --- a/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs +++ b/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using CodeDocumentor.Common.Models; using CodeDocumentor.Constructors; using CodeDocumentor.Helper; using FluentAssertions; diff --git a/CodeDocumentor.Test/Helper/TranslatorTests.cs b/CodeDocumentor.Test/Helper/TranslatorTests.cs index 99a00be..5aa4822 100644 --- a/CodeDocumentor.Test/Helper/TranslatorTests.cs +++ b/CodeDocumentor.Test/Helper/TranslatorTests.cs @@ -1,5 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Models; using CodeDocumentor.Helper; using CodeDocumentor.Vsix2022; using FluentAssertions; diff --git a/CodeDocumentor.Test/Helper/WordExtensionsTests.cs b/CodeDocumentor.Test/Helper/WordExtensionsTests.cs index a2bbeaa..58895fc 100644 --- a/CodeDocumentor.Test/Helper/WordExtensionsTests.cs +++ b/CodeDocumentor.Test/Helper/WordExtensionsTests.cs @@ -2,6 +2,8 @@ using FluentAssertions; using Xunit; +using System; + namespace CodeDocumentor.Test.Helper { public class WordExtensionsTests diff --git a/CodeDocumentor.Test/TestFixture.cs b/CodeDocumentor.Test/TestFixture.cs index 4125b01..0312e3c 100644 --- a/CodeDocumentor.Test/TestFixture.cs +++ b/CodeDocumentor.Test/TestFixture.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using CodeDocumentor.Analyzers; +using CodeDocumentor.Common.Models; using CodeDocumentor.Services; using CodeDocumentor.Test.TestHelpers; using CodeDocumentor.Vsix2022; diff --git a/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs b/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs index 2b894c6..12ded91 100644 --- a/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs +++ b/CodeDocumentor.Test/TestHelpers/TestOptionsService.cs @@ -1,5 +1,8 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Common.Models; using CodeDocumentor.Services; using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; @@ -119,7 +122,7 @@ public void SetDefaults(IOptionPageGrid options) RecordDiagnosticSeverity = options.RecordDiagnosticSeverity; } - public void Update(Vsix2022.Settings settings) + public void Update(Settings settings) { IsEnabledForPublicMembersOnly = settings.IsEnabledForPublicMembersOnly; UseNaturalLanguageForReturnNode = settings.UseNaturalLanguageForReturnNode; diff --git a/CodeDocumentor.sln b/CodeDocumentor.sln index 7c2c405..3460881 100644 --- a/CodeDocumentor.sln +++ b/CodeDocumentor.sln @@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ .github\workflows\dotnet.yml = .github\workflows\dotnet.yml EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeDocumentor.Common", "CodeDocumentor.Common\CodeDocumentor.Common.csproj", "{7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +77,18 @@ Global {0D6E3633-F45F-4883-AC62-DEC9F714AA9B}.Release|x64.Build.0 = Release|Any CPU {0D6E3633-F45F-4883-AC62-DEC9F714AA9B}.Release|x86.ActiveCfg = Release|x86 {0D6E3633-F45F-4883-AC62-DEC9F714AA9B}.Release|x86.Build.0 = Release|x86 + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|x64.ActiveCfg = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|x64.Build.0 = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|x86.ActiveCfg = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Debug|x86.Build.0 = Debug|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|Any CPU.Build.0 = Release|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|x64.ActiveCfg = Release|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|x64.Build.0 = Release|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|x86.ActiveCfg = Release|Any CPU + {7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs b/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs index 431bdab..43377e3 100644 --- a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs @@ -1,6 +1,6 @@ -using CodeDocumentor.Helper; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Services; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; namespace CodeDocumentor.Analyzers @@ -14,6 +14,8 @@ internal class BaseAnalyzerSettings private static IOptionsService _optionsService; + protected IEventLogger EventLogger = new Logger(); + public static void SetOptionsService(IOptionsService optionsService) { _optionsService = optionsService; @@ -53,7 +55,7 @@ internal DiagnosticSeverity LookupSeverity(string diagnosticId) return optionsService.RecordDiagnosticSeverity ?? optionsService.DefaultDiagnosticSeverity; } return Constants.DefaultDiagnosticSeverityOnError; - }, diagnosticId, (_) => Constants.DefaultDiagnosticSeverityOnError, eventId: Constants.EventIds.ANALYZER); + }, diagnosticId, EventLogger, (_) => Constants.DefaultDiagnosticSeverityOnError, eventId: Constants.EventIds.ANALYZER); } } } diff --git a/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs b/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs index 6fb104d..4115dde 100644 --- a/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs @@ -1,9 +1,10 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Threading.Tasks; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Helper; using CodeDocumentor.Services; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -16,6 +17,8 @@ public abstract class BaseCodeFixProvider : CodeFixProvider { protected DocumentationHeaderHelper DocumentationHeaderHelper; + protected static IEventLogger EventLogger = new Logger(); + //expose this for some of the static helpers for producing ALl File comments private static IOptionsService _optionsService; @@ -98,7 +101,7 @@ protected async Task RegisterFileCodeFixesAsync(CodeFixContext context, Diagnost createChangedDocument: (c) => Task.Run(() => context.Document.WithSyntaxRoot(newRoot), c), equivalenceKey: FILE_FIX_TITLE), diagnostic); - }, diagnostic.Id, eventId: Constants.EventIds.FILE_FIXER, category: Constants.EventIds.Categories.BUILD_COMMENTS); + }, diagnostic.Id, EventLogger, eventId: Constants.EventIds.FILE_FIXER, category: Constants.EventIds.Categories.BUILD_COMMENTS); } } } diff --git a/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs b/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs index a97f190..66724f2 100644 --- a/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs +++ b/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs @@ -15,6 +15,11 @@ public static void SetOptionsService(IOptionsService optionsService) _optionsService = optionsService; } + protected IOptionsService GetOptionsService() + { + return OptionsService; + } + protected static IOptionsService OptionsService => //we serve up a fresh new instance from the static, and use that instead, keeps everything testable and decoupled from the static _optionsService.Clone(); diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs index a236398..2f68225 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs @@ -57,6 +57,11 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } + + //var options = context.Options.AnalyzerConfigOptionsProvider.GetOptions(node.SyntaxTree); + //options.TryGetValue(""); + + DocumentationHeaderHelper = new DocumentationHeaderHelper(OptionsService); var excludeAnanlyzer = DocumentationHeaderHelper.HasAnalyzerExclusion(node); if (excludeAnanlyzer) diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs index b11ce93..fd5d0ff 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs b/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs index 28763a8..2442d41 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -47,10 +47,10 @@ public sealed override FixAllProvider GetFixAllProvider() public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); - var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; - + //context.Document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(context.Document.?); + //var tree = await context.Document.GetSyntaxTreeAsync(context.CancellationToken); var declaration = root?.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType().FirstOrDefault(); if (declaration == null) { @@ -89,7 +89,7 @@ internal Task AddDocumentationHeaderAsync(Document document, SyntaxNod var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, ClassAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, ClassAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } /// @@ -119,7 +119,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, ConstructorAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, ConstructorAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs index 4cb3eb8..ce7137f 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs b/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs index 075f8b2..2579254 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -88,7 +88,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, EnumAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, EnumAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs index 3c5d74c..b6e649e 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs b/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs index bf1650c..313fdea 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -98,7 +98,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, FieldAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, FieldAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs index 2516f31..0fed410 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs b/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs index bb3563c..1cf8b3f 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -88,7 +88,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, InterfaceAnalyzerSettings.DiagnosticId , (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, InterfaceAnalyzerSettings.DiagnosticId , EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs index 6426489..b58914f 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs index f05b8ee..deb517e 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -107,7 +107,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, MethodAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, MethodAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs index db49c3a..28d2f06 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs b/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs index 39dd57f..7ead665 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs @@ -5,8 +5,9 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Models; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -98,7 +99,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary AddDocumentationHeaderAsync(Document document, SyntaxNode var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, PropertyAnalyzerSettings.DiagnosticId , (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, PropertyAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } } } diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs b/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs index 116c252..ee4bcb7 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs +++ b/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs @@ -1,5 +1,5 @@ using CodeDocumentor.Analyzers; -using CodeDocumentor.Vsix2022; +using CodeDocumentor.Common; using Microsoft.CodeAnalysis; namespace CodeDocumentor diff --git a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs b/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs index 4a7a979..82cb4a1 100644 --- a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs +++ b/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using CodeDocumentor.Builders; +using CodeDocumentor.Common; using CodeDocumentor.Helper; -using CodeDocumentor.Vsix2022; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -87,7 +87,7 @@ internal Task AddDocumentationHeaderAsync(Document document, SyntaxNod var newDeclaration = BuildNewDeclaration(declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, RecordAnalyzerSettings.DiagnosticId, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); + }, RecordAnalyzerSettings.DiagnosticId, EventLogger, (_) => document, eventId: Constants.EventIds.FIXER, category: Constants.EventIds.Categories.ADD_DOCUMENTATION_HEADER), cancellationToken); } /// @@ -117,7 +117,7 @@ internal static int BuildComments(SyntaxNode root, Dictionary - + - - - - @@ -91,41 +87,36 @@ - - - - Component - - - - + + 4.13.0 + compile; build; native; contentfiles; analyzers; buildtransitive @@ -133,16 +124,12 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - 13.0.3 - 8.0.0 - @@ -164,6 +151,12 @@ + + + {7cc64cdf-a7ff-463b-8f05-c37a6c0a820c} + CodeDocumentor.Common + + -- [CodeDocumentor](#codedocumentor) - - [Installation](#installation) - - [Table of Contents](#table-of-contents) - - [Instruction](#instruction) - - [Known Issues](#known-issues) - - [Comment Ordering](#comment-ordering) - - [Supported Comment Refactorings](#supported-comment-refactorings) - - [Settings](#settings) - - [Word Translations](#word-translations) - - [Recommended Settings](#recommended-settings) - - [Also Supports](#also-supports) - - [Excluding ErrorList Messages](#excluding-errorlist-messages) - - [Available DiagnosticId Codes](#available-diagnosticid-codes) - - [Supported Members](#supported-members) - - [Attribute](#attribute) +- [Instruction](#instruction) +- [Known Issues](#known-issues) +- [Comment Ordering](#comment-ordering) +- [Supported Comment Refactorings](#supported-comment-refactorings) +- [Settings](#settings) + - [Word Translations](#word-translations) + - [Recommended Settings](#recommended-settings) +- [Also Supports](#also-supports) + - [One Word Methods](#one-word-methods) - [Example](#example) - - [Usage Examples](#usage-examples) - - [Errors and Crashes](#errors-and-crashes) - - [Changelog](#changelog) - - [Example Cref Support](#example-cref-support) - - [Special Thanks](#special-thanks) +- [Excluding ErrorList Messages](#excluding-errorlist-messages) + - [Available DiagnosticId Codes](#available-diagnosticid-codes) + - [Supported Members](#supported-members) + - [Attribute](#attribute) + - [Example](#example-1) +- [Usage Examples](#usage-examples) + - [Example Cref Support](#example-cref-support) +- [Errors and Crashes](#errors-and-crashes) +- [Using .editorconfig for settings](#using-editorconfig-for-settings) +- [Changelog](#changelog) +- [Special Thanks](#special-thanks)