From af661ddbf98d3c957e8c4fe275c06e6328657113 Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sat, 11 Oct 2025 11:54:37 -0600 Subject: [PATCH 1/6] checkpoint --- .../Analyzers/BaseAnalyzerSettings.cs | 9 +- .../Analyzers/BaseDiagnosticAnalyzer.cs | 6 +- .../Analyzers/Classes/ClassAnalyzer.cs | 9 +- .../Classes/ClassAnalyzerSettings.cs | 15 ++- .../Classes/NonPublicClassAnalyzer.cs | 9 +- .../Constructors/ConstructorAnalyzer.cs | 13 ++- .../ConstructorAnalyzerSettings.cs | 17 ++- .../NonPublicConstructorAnalyzer.cs | 9 +- .../Analyzers/Enums/EnumAnalyzer.cs | 10 +- .../Analyzers/Enums/EnumAnalyzerSettings.cs | 15 ++- .../Analyzers/Fields/FieldAnalyzer.cs | 13 ++- .../Analyzers/Fields/FieldAnalyzerSettings.cs | 15 ++- .../Fields/NonPublicFieldAnalyzer.cs | 11 +- .../Analyzers/Files/FileAnalyzer.cs | 5 +- .../Analyzers/Files/FileAnalyzerSettings.cs | 13 +-- .../Analyzers/Interfaces/InterfaceAnalyzer.cs | 13 ++- .../Interfaces/InterfaceAnalyzerSettings.cs | 15 ++- .../Analyzers/Methods/MethodAnalyzer.cs | 13 ++- .../Methods/MethodAnalyzerSettings.cs | 15 ++- .../Methods/NonPublicMethodAnalyzer.cs | 11 +- .../Properties/NonPublicPropertyAnalyzer.cs | 13 ++- .../Analyzers/Properties/PropertyAnalyzer.cs | 13 ++- .../Properties/PropertyAnalyzerSettings.cs | 15 ++- .../Records/NonPublicRecordAnalyzer.cs | 11 +- .../Analyzers/Records/RecordAnalyzer.cs | 13 ++- .../Records/RecordAnalyzerSettings.cs | 15 ++- .../Builders/DiagnosticBuilder.cs | 7 +- .../Builders/DocumentationBuilder.cs | 36 +++--- .../CodeDocumentor.Analyzers.csproj | 17 +++ .../BaseReturnTypeCommentConstruction.cs | 10 +- .../Constructors/ReturnCommentConstruction.cs | 5 +- .../SingleWordCommentSummaryConstruction.cs | 3 +- .../Helper/CommentHelper.cs | 6 +- .../Helper/DocumentationHeaderHelper.cs | 23 ++-- .../Helper/ListExtensions.cs | 4 +- .../Helper/PrivateMemberVerifier.cs | 2 +- .../Helper/SyntaxExtensions.cs | 13 ++- .../Helper/WordExtensions.cs | 2 +- .../Locators/ServiceLocator.cs | 14 ++- .../Managers/GenericCommentManager.cs | 7 +- .../CodeDocumentor.Common.csproj | 2 +- .../Extensions/ListExtensions.cs | 3 +- .../Extensions/Translator.cs | 3 +- CodeDocumentor.Common/Helpers/NameSplitter.cs | 2 +- CodeDocumentor.Common/Helpers/TokenHelper.cs | 2 +- CodeDocumentor.Common/Helpers/TryHelper.cs | 2 +- .../Interfaces/ISettingService.cs | 10 ++ .../Builders/DocumentationBuilderTests.cs | 4 +- CodeDocumentor.Test/Classes/ClassUnitTests.cs | 2 + .../CodeDocumentor.Test.csproj | 11 +- .../Constructors/ConstructorUnitTests.cs | 2 + CodeDocumentor.Test/Enums/EnumUnitTests.cs | 2 + CodeDocumentor.Test/Fields/FieldUnitTests.cs | 4 +- .../Helper/CommentHelperTests.cs | 3 +- .../Helper/DocumentationHeaderHelperTests.cs | 2 +- .../Helper/NameSplitterTests.cs | 2 +- .../Helper/ReturnCommentConstructionTests.cs | 2 +- CodeDocumentor.Test/Helper/TranslatorTests.cs | 2 +- .../Interfaces/InterfaceUnitTests.cs | 4 +- .../Methods/MethodUnitTests.cs | 2 + .../Properties/PropertyUnitTests.cs | 2 + .../Records/RecordUnitTests.cs | 2 + CodeDocumentor.Test/TestFixture.cs | 4 + CodeDocumentor.sln | 18 ++- CodeDocumentor/CodeDocumentor.Package.cs | 56 +++++---- CodeDocumentor/CodeDocumentor.csproj | 83 ++++---------- .../Helper/EditorConfigExtensions.cs | 105 +---------------- CodeDocumentor/Helper/Logger.cs | 4 +- CodeDocumentor/Models/OptionPageGrid.cs | 1 + .../BaseCodeFixProvider.cs | 6 +- .../Classes/ClassCodeFixProvider.cs | 10 +- .../ConstructorCodeFixProvider.cs | 8 +- .../Enums/EnumCodeFixProvider.cs | 5 +- .../Fields/FieldCodeFixProvider.cs | 8 +- .../Files/FileCodeFixProvider.cs | 5 +- .../Interfaces/InterfaceCodeFixProvider.cs | 11 +- .../Methods/MethodCodeFixProvider.cs | 6 +- .../Properties/PropertyCodeFixProvider.cs | 8 +- .../Records/RecordCodeFixProvider.cs | 8 +- CodeDocumentor/Services/SettingService.cs | 107 ++++++++++++++++++ .../vs2022/source.extension.vsixmanifest | 83 +++++++------- 81 files changed, 575 insertions(+), 496 deletions(-) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/BaseAnalyzerSettings.cs (89%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/BaseDiagnosticAnalyzer.cs (85%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Classes/ClassAnalyzer.cs (88%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Classes/ClassAnalyzerSettings.cs (60%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Classes/NonPublicClassAnalyzer.cs (89%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Constructors/ConstructorAnalyzer.cs (84%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Constructors/ConstructorAnalyzerSettings.cs (59%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs (88%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Enums/EnumAnalyzer.cs (86%) rename CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs => CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzerSettings.cs (62%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Fields/FieldAnalyzer.cs (85%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Fields/FieldAnalyzerSettings.cs (63%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Fields/NonPublicFieldAnalyzer.cs (86%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Files/FileAnalyzer.cs (95%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Files/FileAnalyzerSettings.cs (60%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Interfaces/InterfaceAnalyzer.cs (82%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs (62%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Methods/MethodAnalyzer.cs (84%) rename CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs => CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzerSettings.cs (64%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Methods/NonPublicMethodAnalyzer.cs (86%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Properties/NonPublicPropertyAnalyzer.cs (83%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Properties/PropertyAnalyzer.cs (82%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Properties/PropertyAnalyzerSettings.cs (62%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Records/NonPublicRecordAnalyzer.cs (86%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Records/RecordAnalyzer.cs (82%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Analyzers/Records/RecordAnalyzerSettings.cs (60%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Builders/DiagnosticBuilder.cs (89%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Builders/DocumentationBuilder.cs (89%) create mode 100644 CodeDocumentor.Analyzers/CodeDocumentor.Analyzers.csproj rename {CodeDocumentor => CodeDocumentor.Analyzers}/Constructors/BaseReturnTypeCommentConstruction.cs (96%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Constructors/ReturnCommentConstruction.cs (95%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Constructors/SingleWordCommentSummaryConstruction.cs (96%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/CommentHelper.cs (98%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/DocumentationHeaderHelper.cs (92%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/ListExtensions.cs (96%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/PrivateMemberVerifier.cs (99%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/SyntaxExtensions.cs (94%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Helper/WordExtensions.cs (88%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Locators/ServiceLocator.cs (53%) rename {CodeDocumentor => CodeDocumentor.Analyzers}/Managers/GenericCommentManager.cs (98%) create mode 100644 CodeDocumentor.Common/Interfaces/ISettingService.cs rename CodeDocumentor/{Analyzers => Providers}/BaseCodeFixProvider.cs (96%) rename CodeDocumentor/{Analyzers => Providers}/Classes/ClassCodeFixProvider.cs (94%) rename CodeDocumentor/{Analyzers => Providers}/Constructors/ConstructorCodeFixProvider.cs (97%) rename CodeDocumentor/{Analyzers => Providers}/Enums/EnumCodeFixProvider.cs (98%) rename CodeDocumentor/{Analyzers => Providers}/Fields/FieldCodeFixProvider.cs (96%) rename CodeDocumentor/{Analyzers => Providers}/Files/FileCodeFixProvider.cs (97%) rename CodeDocumentor/{Analyzers => Providers}/Interfaces/InterfaceCodeFixProvider.cs (92%) rename CodeDocumentor/{Analyzers => Providers}/Methods/MethodCodeFixProvider.cs (98%) rename CodeDocumentor/{Analyzers => Providers}/Properties/PropertyCodeFixProvider.cs (97%) rename CodeDocumentor/{Analyzers => Providers}/Records/RecordCodeFixProvider.cs (96%) create mode 100644 CodeDocumentor/Services/SettingService.cs diff --git a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/BaseAnalyzerSettings.cs similarity index 89% rename from CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/BaseAnalyzerSettings.cs index e71ad46..00a06dd 100644 --- a/CodeDocumentor/Analyzers/BaseAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/BaseAnalyzerSettings.cs @@ -1,20 +1,21 @@ +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; namespace CodeDocumentor.Analyzers { - internal class BaseAnalyzerSettings + public class BaseAnalyzerSettings { /// /// The category. /// - internal const string Category = Constants.CATEGORY; + public const string Category = Constants.CATEGORY; protected IEventLogger EventLogger = ServiceLocator.Logger; - internal DiagnosticSeverity LookupSeverity(string diagnosticId, ISettings settings) + public DiagnosticSeverity LookupSeverity(string diagnosticId, ISettings settings) { if (settings == null) { diff --git a/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs similarity index 85% rename from CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs index df7df27..fcdcfc3 100644 --- a/CodeDocumentor/Analyzers/BaseDiagnosticAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs @@ -1,9 +1,9 @@ +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { public abstract class BaseDiagnosticAnalyzer : DiagnosticAnalyzer { diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzer.cs similarity index 88% rename from CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzer.cs index d6ee047..fd2e8ed 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Classes { /// /// The class analyzer. @@ -62,7 +63,7 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } diff --git a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzerSettings.cs similarity index 60% rename from CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzerSettings.cs index 26cf225..7ee046d 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Classes/ClassAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class ClassAnalyzerSettings: BaseAnalyzerSettings + public class ClassAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.CLASS_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.CLASS_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The class must have a documentation header."; + public const string Title = "The class must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -30,7 +29,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() true); } - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Classes/NonPublicClassAnalyzer.cs similarity index 89% rename from CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Classes/NonPublicClassAnalyzer.cs index 93d301d..ac02715 100644 --- a/CodeDocumentor/Analyzers/Classes/NonPublicClassAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Classes/NonPublicClassAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Classes { /// /// The class analyzer. @@ -53,7 +54,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly) { diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzer.cs similarity index 84% rename from CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzer.cs index 17b4853..a2805e6 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Constructors { /// /// The constructor analyzer. @@ -18,7 +19,7 @@ public class ConstructorAnalyzer : BaseDiagnosticAnalyzer public ConstructorAnalyzer() { - _analyzerSettings = new ConstructorAnalyzerSettings(); + _analyzerSettings = new ConstructorAnalyzerSettings(); } /// /// Gets the supported diagnostics. @@ -46,7 +47,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is ConstructorDeclarationSyntax node)) { @@ -56,7 +57,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(node)) { return; diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzerSettings.cs similarity index 59% rename from CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzerSettings.cs index d7704f8..514f34e 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Constructors/ConstructorAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class ConstructorAnalyzerSettings: BaseAnalyzerSettings + public class ConstructorAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.CONSTRUCTOR_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.CONSTRUCTOR_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The constructor must have a documentation header."; - - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public const string Title = "The constructor must have a documentation header."; + + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -31,7 +30,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() } - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs similarity index 88% rename from CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs index 1236ad7..5aaaf13 100644 --- a/CodeDocumentor/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Constructors/NonPublicConstructorAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Constructors { [DiagnosticAnalyzer(LanguageNames.CSharp)] public class NonPublicConstructorAnalyzer : BaseDiagnosticAnalyzer @@ -50,7 +51,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly) { return; diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzer.cs similarity index 86% rename from CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzer.cs index 4a11fde..9dd146c 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzer.cs @@ -1,12 +1,12 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Enums { /// /// The enum analyzer. @@ -40,7 +40,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is EnumDeclarationSyntax node)) { @@ -51,7 +51,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzerSettings.cs similarity index 62% rename from CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzerSettings.cs index 92ef6fd..a234e20 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Enums/EnumAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class MethodAnalyzerSettings : BaseAnalyzerSettings + public class EnumAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.METHOD_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.ENUM_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The method must have a documentation header."; + public const string Title = "The enum must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -33,7 +32,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() /// /// The diagnostic descriptor rule. /// - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzer.cs similarity index 85% rename from CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzer.cs index 0b24e4c..5a0b5f2 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzer.cs @@ -1,13 +1,14 @@ using System.Collections.Immutable; using System.Linq; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Fields { /// /// The field analyzer. @@ -47,13 +48,13 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is FieldDeclarationSyntax node)) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (!settings.IsEnabledForNonPublicFields && PrivateMemberVerifier.IsPrivateMember(node)) { return; @@ -71,7 +72,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) } var field = node.DescendantNodes().OfType().First(); - context.BuildDiagnostic(node, field.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, field.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzerSettings.cs similarity index 63% rename from CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzerSettings.cs index a0d21c9..01a9242 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Fields/FieldAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class FieldAnalyzerSettings:BaseAnalyzerSettings + public class FieldAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.FIELD_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.FIELD_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The field must have a documentation header."; + public const string Title = "The field must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -33,7 +32,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() /// /// The diagnostic descriptor rule. /// - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Fields/NonPublicFieldAnalyzer.cs similarity index 86% rename from CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Fields/NonPublicFieldAnalyzer.cs index 2bedf19..4d59383 100644 --- a/CodeDocumentor/Analyzers/Fields/NonPublicFieldAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Fields/NonPublicFieldAnalyzer.cs @@ -1,13 +1,14 @@ using System.Collections.Immutable; using System.Linq; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Fields { [DiagnosticAnalyzer(LanguageNames.CSharp)] public class NonPublicFieldAnalyzer : BaseDiagnosticAnalyzer @@ -57,7 +58,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly) { return; @@ -69,7 +70,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) } var field = node.DescendantNodes().OfType().First(); - context.BuildDiagnostic(node, field.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, field.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Files/FileAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs similarity index 95% rename from CodeDocumentor/Analyzers/Files/FileAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs index 5b708e9..f5fe125 100644 --- a/CodeDocumentor/Analyzers/Files/FileAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs @@ -1,11 +1,10 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Files { /// /// The class analyzer. @@ -53,7 +52,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { context.ReportDiagnostic(Diagnostic.Create(FileAnalyzerSettings.GetRule(), node.GetLocation())); } - catch (OperationCanceledException ex) + catch { //noop } diff --git a/CodeDocumentor/Analyzers/Files/FileAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzerSettings.cs similarity index 60% rename from CodeDocumentor/Analyzers/Files/FileAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzerSettings.cs index a25b4e4..56cfedf 100644 --- a/CodeDocumentor/Analyzers/Files/FileAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzerSettings.cs @@ -1,27 +1,26 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class FileAnalyzerSettings: BaseAnalyzerSettings + public class FileAnalyzerSettings : BaseAnalyzerSettings { /// /// The title. /// - internal const string Title = "The file needs documentation headers."; + public const string Title = "The file needs documentation headers."; /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.FILE_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.FILE_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; - internal static DiagnosticDescriptor GetRule() + public static DiagnosticDescriptor GetRule() { //we dont need to show this to still show the option to decorate the whole file. Setting DiagnosticSeverity.Hidden return new DiagnosticDescriptor(DiagnosticId, Title, diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzer.cs similarity index 82% rename from CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzer.cs index a9a6768..8546959 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Interfaces { /// /// The interface analyzer. @@ -40,13 +41,13 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is InterfaceDeclarationSyntax node)) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(node)) { return; @@ -56,7 +57,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs similarity index 62% rename from CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs index dc4e98d..2daf6c4 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Interfaces/InterfaceAnalyzerSettings.cs @@ -1,29 +1,28 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class InterfaceAnalyzerSettings:BaseAnalyzerSettings + public class InterfaceAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.INTERFACE_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.INTERFACE_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The interface must have a documentation header."; + public const string Title = "The interface must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -34,7 +33,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() /// /// The diagnostic descriptor rule. /// - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzer.cs similarity index 84% rename from CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzer.cs index 5fcdf17..4fa7259 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Methods { /// /// The method analyzer. @@ -46,7 +47,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is MethodDeclarationSyntax node)) { @@ -65,8 +66,8 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzerSettings.cs similarity index 64% rename from CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzerSettings.cs index ef5a325..f6b5457 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Methods/MethodAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class EnumAnalyzerSettings : BaseAnalyzerSettings + public class MethodAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.ENUM_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.METHOD_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The enum must have a documentation header."; + public const string Title = "The method must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -33,7 +32,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() /// /// The diagnostic descriptor rule. /// - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Methods/NonPublicMethodAnalyzer.cs similarity index 86% rename from CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Methods/NonPublicMethodAnalyzer.cs index f864a0d..81a456c 100644 --- a/CodeDocumentor/Analyzers/Methods/NonPublicMethodAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Methods/NonPublicMethodAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Methods { [DiagnosticAnalyzer(LanguageNames.CSharp)] public class NonPublicMethodAnalyzer : BaseDiagnosticAnalyzer @@ -51,7 +52,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); //NOTE: Since interfaces declarations do not have accessors, we allow documenting all the time. if (!node.IsOwnedByInterface() && settings.IsEnabledForPublicMembersOnly) { @@ -62,7 +63,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Properties/NonPublicPropertyAnalyzer.cs similarity index 83% rename from CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Properties/NonPublicPropertyAnalyzer.cs index 1609966..9881018 100644 --- a/CodeDocumentor/Analyzers/Properties/NonPublicPropertyAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Properties/NonPublicPropertyAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Properties { /// /// The property analyzer. @@ -47,7 +48,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is PropertyDeclarationSyntax node)) { @@ -57,7 +58,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly) { return; @@ -68,7 +69,7 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) return; } - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzer.cs similarity index 82% rename from CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzer.cs index 96f6d5d..4f82d55 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Properties { /// /// The property analyzer. @@ -46,7 +47,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is PropertyDeclarationSyntax node)) { @@ -61,8 +62,8 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzerSettings.cs similarity index 62% rename from CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzerSettings.cs index d5279bd..de508e0 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Properties/PropertyAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class PropertyAnalyzerSettings: BaseAnalyzerSettings + public class PropertyAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.PROPERTY_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.PROPERTY_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The property must have a documentation header."; + public const string Title = "The property must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -33,7 +32,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() /// /// The diagnostic descriptor rule. /// - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Records/NonPublicRecordAnalyzer.cs similarity index 86% rename from CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Records/NonPublicRecordAnalyzer.cs index 949d78f..2f7a244 100644 --- a/CodeDocumentor/Analyzers/Records/NonPublicRecordAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Records/NonPublicRecordAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Records { /// /// The class analyzer. @@ -53,7 +54,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); if (settings.IsEnabledForPublicMembersOnly) { return; @@ -63,7 +64,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzer.cs similarity index 82% rename from CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs rename to CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzer.cs index 8e90d74..b502c9c 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzer.cs @@ -1,12 +1,13 @@ using System.Collections.Immutable; -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers.Records { /// /// The class analyzer. @@ -46,7 +47,7 @@ public override void Initialize(AnalysisContext context) /// Analyzes node. /// /// The context. - internal void AnalyzeNode(SyntaxNodeAnalysisContext context) + public void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (!(context.Node is RecordDeclarationSyntax node)) { @@ -61,8 +62,8 @@ internal void AnalyzeNode(SyntaxNodeAnalysisContext context) { return; } - var settings = context.BuildSettings(StaticSettings); - context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment,settings)); + var settings = ServiceLocator.SettingService.BuildSettings(context, StaticSettings); + context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings)); } } } diff --git a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs b/CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzerSettings.cs similarity index 60% rename from CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs rename to CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzerSettings.cs index 98e2d76..d967157 100644 --- a/CodeDocumentor/Analyzers/Records/RecordAnalyzerSettings.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Records/RecordAnalyzerSettings.cs @@ -1,28 +1,27 @@ -using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using Microsoft.CodeAnalysis; -namespace CodeDocumentor +namespace CodeDocumentor.Analyzers { - internal class RecordAnalyzerSettings: BaseAnalyzerSettings + public class RecordAnalyzerSettings : BaseAnalyzerSettings { /// /// The diagnostic id. /// - internal const string DiagnosticId = Constants.DiagnosticIds.RECORD_DIAGNOSTIC_ID; + public const string DiagnosticId = Constants.DiagnosticIds.RECORD_DIAGNOSTIC_ID; /// /// The message format. /// - internal const string MessageFormat = Title; + public const string MessageFormat = Title; /// /// The title. /// - internal const string Title = "The record must have a documentation header."; + public const string Title = "The record must have a documentation header."; - internal DiagnosticDescriptor GetSupportedDiagnosticRule() + public DiagnosticDescriptor GetSupportedDiagnosticRule() { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, @@ -30,7 +29,7 @@ internal DiagnosticDescriptor GetSupportedDiagnosticRule() true); } - internal DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) + public DiagnosticDescriptor GetRule(bool hideDiagnosticSeverity, ISettings settings) { return new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, diff --git a/CodeDocumentor/Builders/DiagnosticBuilder.cs b/CodeDocumentor.Analyzers/Builders/DiagnosticBuilder.cs similarity index 89% rename from CodeDocumentor/Builders/DiagnosticBuilder.cs rename to CodeDocumentor.Analyzers/Builders/DiagnosticBuilder.cs index 77796a5..b6332dc 100644 --- a/CodeDocumentor/Builders/DiagnosticBuilder.cs +++ b/CodeDocumentor.Analyzers/Builders/DiagnosticBuilder.cs @@ -1,13 +1,12 @@ using System; using System.Linq; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; +using CodeDocumentor.Analyzers.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor.Builders +namespace CodeDocumentor.Analyzers.Builders { public static class DiagnosticBuilder { @@ -30,7 +29,7 @@ public static void BuildDiagnostic(this SyntaxNodeAnalysisContext context, CShar var commentHelper = ServiceLocator.CommentHelper; var alreadyHasComment = commentTriviaSyntax != null && commentHelper.HasComment(commentTriviaSyntax); - var settings = context.BuildSettings(null); + var settings = ServiceLocator.SettingService.BuildSettings(context, null); try { context.ReportDiagnostic(Diagnostic.Create(getRuleCallback.Invoke(alreadyHasComment), identifier.GetLocation())); diff --git a/CodeDocumentor/Builders/DocumentationBuilder.cs b/CodeDocumentor.Analyzers/Builders/DocumentationBuilder.cs similarity index 89% rename from CodeDocumentor/Builders/DocumentationBuilder.cs rename to CodeDocumentor.Analyzers/Builders/DocumentationBuilder.cs index 573a1e3..19c6665 100644 --- a/CodeDocumentor/Builders/DocumentationBuilder.cs +++ b/CodeDocumentor.Analyzers/Builders/DocumentationBuilder.cs @@ -1,15 +1,15 @@ using System.Collections.Generic; using System.Linq; +using CodeDocumentor.Analyzers.Constructors; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; using CodeDocumentor.Common.Models; -using CodeDocumentor.Constructors; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Builders +namespace CodeDocumentor.Analyzers.Builders { public class DocumentationBuilder { @@ -17,18 +17,18 @@ public class DocumentationBuilder private XmlElementSyntax _currentElement; private readonly List _list = new List(); - internal SyntaxList Build() + public SyntaxList Build() { return new SyntaxList(_list); } - internal DocumentationBuilder Reset() + public DocumentationBuilder Reset() { _currentElement = null; return this; } - internal DocumentationBuilder WithExceptionTypes(MethodDeclarationSyntax declarationSyntax) + public DocumentationBuilder WithExceptionTypes(MethodDeclarationSyntax declarationSyntax) { var exceptions = _documentationHeaderHelper.GetExceptions(declarationSyntax.Body?.ToFullString()); @@ -47,7 +47,7 @@ internal DocumentationBuilder WithExceptionTypes(MethodDeclarationSyntax declara return this; } - internal DocumentationBuilder WithExisting(CSharpSyntaxNode declarationSyntax, string xmlNodeName) + public DocumentationBuilder WithExisting(CSharpSyntaxNode declarationSyntax, string xmlNodeName) { var remarks = declarationSyntax.GetElementSyntax(xmlNodeName); if (remarks != null) @@ -59,7 +59,7 @@ internal DocumentationBuilder WithExisting(CSharpSyntaxNode declarationSyntax, s return this; } - internal DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declarationSyntax, WordMap[] wordMaps) + public DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declarationSyntax, WordMap[] wordMaps) { if (declarationSyntax?.ParameterList?.Parameters.Any() == true) { @@ -77,14 +77,14 @@ internal DocumentationBuilder WithParameters(BaseMethodDeclarationSyntax declara return this; } - internal DocumentationBuilder WithParameters(TypeDeclarationSyntax declarationSyntax, WordMap[] wordMaps) + public DocumentationBuilder WithParameters(TypeDeclarationSyntax declarationSyntax, WordMap[] wordMaps) { if (declarationSyntax?.ParameterList?.Parameters.Any() == true) { var commentHelper = ServiceLocator.CommentHelper; foreach (var parameter in declarationSyntax.ParameterList.Parameters) { - var parameterComment = commentHelper.CreateParameterComment(parameter,wordMaps); + var parameterComment = commentHelper.CreateParameterComment(parameter, wordMaps); var parameterElement = _documentationHeaderHelper.CreateParameterElementSyntax(parameter.Identifier.ValueText, parameterComment); @@ -96,7 +96,7 @@ internal DocumentationBuilder WithParameters(TypeDeclarationSyntax declarationSy return this; } - internal DocumentationBuilder WithPropertyValueTypes(BasePropertyDeclarationSyntax declarationSyntax, + public DocumentationBuilder WithPropertyValueTypes(BasePropertyDeclarationSyntax declarationSyntax, ReturnTypeBuilderOptions options, WordMap[] wordMaps) { if (options.GenerateReturnStatement) @@ -111,12 +111,12 @@ internal DocumentationBuilder WithPropertyValueTypes(BasePropertyDeclarationSynt return this; } - internal DocumentationBuilder WithReturnType(MethodDeclarationSyntax declarationSyntax, + public DocumentationBuilder WithReturnType(MethodDeclarationSyntax declarationSyntax, bool useNaturalLanguageForReturnNode, bool tryToIncludeCrefsForReturnTypes, WordMap[] wordMaps) { - var returnType = declarationSyntax.ReturnType.ToString().Replace("?",string.Empty); + var returnType = declarationSyntax.ReturnType.ToString().Replace("?", string.Empty); if (returnType != "void") { var commentConstructor = new ReturnCommentConstruction(declarationSyntax.ReturnType, @@ -133,7 +133,7 @@ internal DocumentationBuilder WithReturnType(MethodDeclarationSyntax declaration return this; } - internal DocumentationBuilder WithSummary(CSharpSyntaxNode declarationSyntax, string content, bool preserveExistingSummaryText) + public DocumentationBuilder WithSummary(CSharpSyntaxNode declarationSyntax, string content, bool preserveExistingSummaryText) { if (preserveExistingSummaryText) { @@ -153,7 +153,7 @@ internal DocumentationBuilder WithSummary(CSharpSyntaxNode declarationSyntax, st return this; } - internal DocumentationBuilder WithSummary(string content) + public DocumentationBuilder WithSummary(string content) { Reset().WithTripleSlashSpace().WithStartingTag(Constants.SUMMARY).WithLineEndTextSyntax() .WithTripleSlashSpace().WithContent(content).WithLineEndTextSyntax() @@ -162,7 +162,7 @@ internal DocumentationBuilder WithSummary(string content) return this; } - internal DocumentationBuilder WithTypeParamters(TypeDeclarationSyntax declarationSyntax) + public DocumentationBuilder WithTypeParamters(TypeDeclarationSyntax declarationSyntax) { if (declarationSyntax?.TypeParameterList?.Parameters.Any() == true) { @@ -177,7 +177,7 @@ internal DocumentationBuilder WithTypeParamters(TypeDeclarationSyntax declaratio return this; } - internal DocumentationBuilder WithTypeParamters(MethodDeclarationSyntax declarationSyntax) + public DocumentationBuilder WithTypeParamters(MethodDeclarationSyntax declarationSyntax) { if (declarationSyntax?.TypeParameterList?.Parameters.Any() == true) { diff --git a/CodeDocumentor.Analyzers/CodeDocumentor.Analyzers.csproj b/CodeDocumentor.Analyzers/CodeDocumentor.Analyzers.csproj new file mode 100644 index 0000000..8045aaf --- /dev/null +++ b/CodeDocumentor.Analyzers/CodeDocumentor.Analyzers.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0 + true + + + + + + + + + + + + diff --git a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs b/CodeDocumentor.Analyzers/Constructors/BaseReturnTypeCommentConstruction.cs similarity index 96% rename from CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs rename to CodeDocumentor.Analyzers/Constructors/BaseReturnTypeCommentConstruction.cs index 1c36752..8d32f3f 100644 --- a/CodeDocumentor/Constructors/BaseReturnTypeCommentConstruction.cs +++ b/CodeDocumentor.Analyzers/Constructors/BaseReturnTypeCommentConstruction.cs @@ -1,13 +1,13 @@ using System; using System.Linq; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; +using CodeDocumentor.Analyzers.Managers; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; -using CodeDocumentor.Managers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Constructors +namespace CodeDocumentor.Analyzers.Constructors { public abstract class BaseReturnTypeCommentConstruction { @@ -38,7 +38,7 @@ public abstract class BaseReturnTypeCommentConstruction /// The return type. /// The options /// The comment - internal virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOptions options, WordMap[] wordMaps) + public virtual string BuildComment(TypeSyntax returnType, ReturnTypeBuilderOptions options, WordMap[] wordMaps) { var returnComment = string.Empty; if (returnType is IdentifierNameSyntax identifier) diff --git a/CodeDocumentor/Constructors/ReturnCommentConstruction.cs b/CodeDocumentor.Analyzers/Constructors/ReturnCommentConstruction.cs similarity index 95% rename from CodeDocumentor/Constructors/ReturnCommentConstruction.cs rename to CodeDocumentor.Analyzers/Constructors/ReturnCommentConstruction.cs index ef017d1..44d3033 100644 --- a/CodeDocumentor/Constructors/ReturnCommentConstruction.cs +++ b/CodeDocumentor.Analyzers/Constructors/ReturnCommentConstruction.cs @@ -1,9 +1,8 @@ using System; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Constructors +namespace CodeDocumentor.Analyzers.Constructors { /// /// The return comment construction. @@ -34,7 +33,7 @@ public ReturnCommentConstruction(TypeSyntax returnType, ReturnTypeBuilderOptions } //used for testing - internal ReturnCommentConstruction() + public ReturnCommentConstruction() { } diff --git a/CodeDocumentor/Constructors/SingleWordCommentSummaryConstruction.cs b/CodeDocumentor.Analyzers/Constructors/SingleWordCommentSummaryConstruction.cs similarity index 96% rename from CodeDocumentor/Constructors/SingleWordCommentSummaryConstruction.cs rename to CodeDocumentor.Analyzers/Constructors/SingleWordCommentSummaryConstruction.cs index ed786d0..f17153e 100644 --- a/CodeDocumentor/Constructors/SingleWordCommentSummaryConstruction.cs +++ b/CodeDocumentor.Analyzers/Constructors/SingleWordCommentSummaryConstruction.cs @@ -1,9 +1,8 @@ using System; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Constructors +namespace CodeDocumentor.Analyzers.Constructors { public class SingleWordCommentSummaryConstruction : BaseReturnTypeCommentConstruction { diff --git a/CodeDocumentor/Helper/CommentHelper.cs b/CodeDocumentor.Analyzers/Helper/CommentHelper.cs similarity index 98% rename from CodeDocumentor/Helper/CommentHelper.cs rename to CodeDocumentor.Analyzers/Helper/CommentHelper.cs index 8ff3c3e..bf7f468 100644 --- a/CodeDocumentor/Helper/CommentHelper.cs +++ b/CodeDocumentor.Analyzers/Helper/CommentHelper.cs @@ -2,6 +2,8 @@ using System.Linq; using System.Runtime.CompilerServices; using CodeDocumentor.Common; +using CodeDocumentor.Common.Extensions; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Models; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -9,7 +11,7 @@ [assembly: InternalsVisibleTo("CodeDocumentor.Test")] -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Analyzers.Helper { /// /// The comment helper. @@ -74,7 +76,7 @@ public string CreateConstructorComment(string name, bool isPrivate, WordMap[] wo /// /// The name. /// A string. - public string CreateEnumComment(string name, WordMap[] wordMaps) + public string CreateEnumComment(string name, WordMap[] wordMaps) { if (string.IsNullOrEmpty(name)) { diff --git a/CodeDocumentor/Helper/DocumentationHeaderHelper.cs b/CodeDocumentor.Analyzers/Helper/DocumentationHeaderHelper.cs similarity index 92% rename from CodeDocumentor/Helper/DocumentationHeaderHelper.cs rename to CodeDocumentor.Analyzers/Helper/DocumentationHeaderHelper.cs index b2907a2..3751faf 100644 --- a/CodeDocumentor/Helper/DocumentationHeaderHelper.cs +++ b/CodeDocumentor.Analyzers/Helper/DocumentationHeaderHelper.cs @@ -2,14 +2,17 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Extensions; +using CodeDocumentor.Common.Helpers; +using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Common.Models; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Analyzers.Helper { /// /// The documentation header helper. @@ -21,7 +24,7 @@ public class DocumentationHeaderHelper private readonly Regex _regExInline = new Regex(@"(\w+Exception)\.Throw\w+", RegexOptions.IgnoreCase | RegexOptions.Multiline); private readonly Regex _regExParseXmlElement = new Regex(@"<(.*?)\s(\w*)=""(.*?)""\s*/>", RegexOptions.IgnoreCase); - private readonly Logger _eventLogger =ServiceLocator.Logger; + private readonly IEventLogger _eventLogger = ServiceLocator.Logger; /// /// Has analyzer exclusion. @@ -54,7 +57,7 @@ public bool HasAnalyzerExclusion(SyntaxNode node, bool recursive = true, List The parameter name. /// The parameter content. /// A XmlElementSyntax. - internal XmlElementSyntax CreateParameterElementSyntax(string parameterName, string parameterContent) + public XmlElementSyntax CreateParameterElementSyntax(string parameterName, string parameterContent) { var paramName = SyntaxFactory.XmlName("param"); @@ -94,7 +97,7 @@ internal XmlElementSyntax CreateParameterElementSyntax(string parameterName, str /// The content. /// The XML node name. /// A XmlNodeSyntax. - internal XmlNodeSyntax CreateReturnElementSyntax(string content, string xmlNodeName = "returns") + public XmlNodeSyntax CreateReturnElementSyntax(string content, string xmlNodeName = "returns") { var xmlName = SyntaxFactory.XmlName(xmlNodeName); /// [0]xxx[1] @@ -159,7 +162,7 @@ internal XmlNodeSyntax CreateReturnElementSyntax(string content, string xmlNodeN /// The specific type. /// Flag determines if name should be pluralized /// The comment. - internal string DetermineSpecificObjectName(TypeSyntax specificType, WordMap[] wordMaps, bool pluaralizeName = false, bool pluaralizeIdentifierType = true) + public string DetermineSpecificObjectName(TypeSyntax specificType, WordMap[] wordMaps, bool pluaralizeName = false, bool pluaralizeIdentifierType = true) { string value; switch (specificType) @@ -187,7 +190,7 @@ internal string DetermineSpecificObjectName(TypeSyntax specificType, WordMap[] w /// The return type. /// If true, use proper casing. /// A string. - internal string DetermineStartingWord(ReadOnlySpan returnType, bool useProperCasing = true) + public string DetermineStartingWord(ReadOnlySpan returnType, bool useProperCasing = true) { if (returnType.IsEmpty) { @@ -203,7 +206,7 @@ internal string DetermineStartingWord(ReadOnlySpan returnType, bool usePro return vowelChars.Contains(char.ToLower(returnType[0])) ? useProperCasing ? "An" : "an" : useProperCasing ? "A" : "a"; } - internal IEnumerable GetExceptions(string textToSearch) + public IEnumerable GetExceptions(string textToSearch) { if (string.IsNullOrEmpty(textToSearch)) { @@ -229,7 +232,7 @@ internal IEnumerable GetExceptions(string textToSearch) return exceptions.Distinct(); } - internal List ParseStringToXmlNodeSyntax(string cleanContent) + public List ParseStringToXmlNodeSyntax(string cleanContent) { var xmlNodes = new List(); TryHelper.Try(() => diff --git a/CodeDocumentor/Helper/ListExtensions.cs b/CodeDocumentor.Analyzers/Helper/ListExtensions.cs similarity index 96% rename from CodeDocumentor/Helper/ListExtensions.cs rename to CodeDocumentor.Analyzers/Helper/ListExtensions.cs index a47803d..2716d50 100644 --- a/CodeDocumentor/Helper/ListExtensions.cs +++ b/CodeDocumentor.Analyzers/Helper/ListExtensions.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using CodeDocumentor.Analyzers.Constructors; using CodeDocumentor.Common; using CodeDocumentor.Common.Models; -using CodeDocumentor.Constructors; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Analyzers.Helper { public static class ListExtensions { diff --git a/CodeDocumentor/Helper/PrivateMemberVerifier.cs b/CodeDocumentor.Analyzers/Helper/PrivateMemberVerifier.cs similarity index 99% rename from CodeDocumentor/Helper/PrivateMemberVerifier.cs rename to CodeDocumentor.Analyzers/Helper/PrivateMemberVerifier.cs index 8883921..4941ac2 100644 --- a/CodeDocumentor/Helper/PrivateMemberVerifier.cs +++ b/CodeDocumentor.Analyzers/Helper/PrivateMemberVerifier.cs @@ -2,7 +2,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Analyzers.Helper { /// /// Verifies whether a member is private. diff --git a/CodeDocumentor/Helper/SyntaxExtensions.cs b/CodeDocumentor.Analyzers/Helper/SyntaxExtensions.cs similarity index 94% rename from CodeDocumentor/Helper/SyntaxExtensions.cs rename to CodeDocumentor.Analyzers/Helper/SyntaxExtensions.cs index 4d176f3..8e0a354 100644 --- a/CodeDocumentor/Helper/SyntaxExtensions.cs +++ b/CodeDocumentor.Analyzers/Helper/SyntaxExtensions.cs @@ -1,11 +1,12 @@ using System; using System.Linq; +using CodeDocumentor.Common.Extensions; using CodeDocumentor.Common.Models; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Helper +namespace CodeDocumentor { public static class SyntaxExtensions { @@ -82,7 +83,7 @@ public static bool PropertyHasSetter(this PropertyDeclarationSyntax declarationS { if (declarationSyntax.AccessorList.Accessors.First(o => o.Kind() == SyntaxKind.SetAccessorDeclaration).ChildTokens().Any(o => o.IsKind(SyntaxKind.PrivateKeyword) || o.IsKind(SyntaxKind.InternalKeyword))) { - // private set or internal set should consider as no set. + // private set or public set should consider as no set. hasSetter = false; } else @@ -160,7 +161,7 @@ public static bool IsTask(this GenericNameSyntax nameSyntax) /// /// The syntax. /// A bool. - internal static bool HasSummary(this CSharpSyntaxNode syntax) + public static bool HasSummary(this CSharpSyntaxNode syntax) { return syntax.HasLeadingTrivia && syntax.GetLeadingTrivia().Any(a => a.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia) || a.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) @@ -172,7 +173,7 @@ internal static bool HasSummary(this CSharpSyntaxNode syntax) /// /// The declaration syntax. /// A bool. - internal static bool IsPrivate(this BaseMethodDeclarationSyntax declarationSyntax) + public static bool IsPrivate(this BaseMethodDeclarationSyntax declarationSyntax) { var isPrivate = false; if (declarationSyntax.Modifiers.Any(SyntaxKind.PrivateKeyword)) @@ -188,7 +189,7 @@ internal static bool IsPrivate(this BaseMethodDeclarationSyntax declarationSynta /// The syntax. /// The name. /// A XmlElementSyntax. - internal static XmlElementSyntax GetElementSyntax(this CSharpSyntaxNode syntax, string name) + public static XmlElementSyntax GetElementSyntax(this CSharpSyntaxNode syntax, string name) { if (syntax.HasLeadingTrivia) { @@ -217,7 +218,7 @@ internal static XmlElementSyntax GetElementSyntax(this CSharpSyntaxNode syntax, /// The leading trivia. /// The comment trivia. /// A SyntaxTriviaList. - internal static SyntaxTriviaList UpsertLeadingTrivia(this SyntaxTriviaList leadingTrivia, DocumentationCommentTriviaSyntax commentTrivia) + public static SyntaxTriviaList UpsertLeadingTrivia(this SyntaxTriviaList leadingTrivia, DocumentationCommentTriviaSyntax commentTrivia) { if (leadingTrivia.All(a => a.IsKind(SyntaxKind.EndOfLineTrivia))) { diff --git a/CodeDocumentor/Helper/WordExtensions.cs b/CodeDocumentor.Analyzers/Helper/WordExtensions.cs similarity index 88% rename from CodeDocumentor/Helper/WordExtensions.cs rename to CodeDocumentor.Analyzers/Helper/WordExtensions.cs index 1c1d6a3..75b6969 100644 --- a/CodeDocumentor/Helper/WordExtensions.cs +++ b/CodeDocumentor.Analyzers/Helper/WordExtensions.cs @@ -1,6 +1,6 @@ using System; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Analyzers.Helper { public static class WordExtensions { diff --git a/CodeDocumentor/Locators/ServiceLocator.cs b/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs similarity index 53% rename from CodeDocumentor/Locators/ServiceLocator.cs rename to CodeDocumentor.Analyzers/Locators/ServiceLocator.cs index e72a843..7d4331b 100644 --- a/CodeDocumentor/Locators/ServiceLocator.cs +++ b/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs @@ -1,13 +1,15 @@ -using CodeDocumentor.Builders; -using CodeDocumentor.Helper; -using CodeDocumentor.Managers; +using CodeDocumentor.Analyzers.Builders; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Managers; +using CodeDocumentor.Common.Interfaces; -namespace CodeDocumentor.Locators +namespace CodeDocumentor.Analyzers.Locators { - internal static class ServiceLocator + public static class ServiceLocator { public static DocumentationHeaderHelper DocumentationHeaderHelper { get; } = new DocumentationHeaderHelper(); - public static Logger Logger { get; } = new Logger(); + public static IEventLogger Logger { get; set; } + public static ISettingService SettingService { get; set; } public static CommentHelper CommentHelper { get; } = new CommentHelper(); public static GenericCommentManager GenericCommentManager { get; } = new GenericCommentManager(); public static DocumentationBuilder DocumentationBuilder => new DocumentationBuilder(); diff --git a/CodeDocumentor/Managers/GenericCommentManager.cs b/CodeDocumentor.Analyzers/Managers/GenericCommentManager.cs similarity index 98% rename from CodeDocumentor/Managers/GenericCommentManager.cs rename to CodeDocumentor.Analyzers/Managers/GenericCommentManager.cs index 5c13f45..639645c 100644 --- a/CodeDocumentor/Managers/GenericCommentManager.cs +++ b/CodeDocumentor.Analyzers/Managers/GenericCommentManager.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; using System.Text; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; +using CodeDocumentor.Common.Extensions; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace CodeDocumentor.Managers +namespace CodeDocumentor.Analyzers.Managers { public class GenericCommentManager { diff --git a/CodeDocumentor.Common/CodeDocumentor.Common.csproj b/CodeDocumentor.Common/CodeDocumentor.Common.csproj index d670910..53d3bec 100644 --- a/CodeDocumentor.Common/CodeDocumentor.Common.csproj +++ b/CodeDocumentor.Common/CodeDocumentor.Common.csproj @@ -5,7 +5,7 @@ - + diff --git a/CodeDocumentor.Common/Extensions/ListExtensions.cs b/CodeDocumentor.Common/Extensions/ListExtensions.cs index a000df4..bd2a6df 100644 --- a/CodeDocumentor.Common/Extensions/ListExtensions.cs +++ b/CodeDocumentor.Common/Extensions/ListExtensions.cs @@ -3,10 +3,11 @@ using System.Linq; using System.Text.RegularExpressions; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Models; using Microsoft.CodeAnalysis; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common.Extensions { public static class ListExtensions { diff --git a/CodeDocumentor.Common/Extensions/Translator.cs b/CodeDocumentor.Common/Extensions/Translator.cs index fa4dbff..a241eef 100644 --- a/CodeDocumentor.Common/Extensions/Translator.cs +++ b/CodeDocumentor.Common/Extensions/Translator.cs @@ -1,8 +1,9 @@ using System.Text.RegularExpressions; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Models; -namespace CodeDocumentor.Helper +namespace CodeDocumentor.Common.Extensions { public static class Translator { diff --git a/CodeDocumentor.Common/Helpers/NameSplitter.cs b/CodeDocumentor.Common/Helpers/NameSplitter.cs index 23117b0..fe88378 100644 --- a/CodeDocumentor.Common/Helpers/NameSplitter.cs +++ b/CodeDocumentor.Common/Helpers/NameSplitter.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; -namespace CodeDocumentor.Common +namespace CodeDocumentor.Common.Helpers { /// /// The name splitter. diff --git a/CodeDocumentor.Common/Helpers/TokenHelper.cs b/CodeDocumentor.Common/Helpers/TokenHelper.cs index d4c4a1d..ce9c5f1 100644 --- a/CodeDocumentor.Common/Helpers/TokenHelper.cs +++ b/CodeDocumentor.Common/Helpers/TokenHelper.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -namespace CodeDocumentor.Common +namespace CodeDocumentor.Common.Helpers { //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 public static class TokenHelper diff --git a/CodeDocumentor.Common/Helpers/TryHelper.cs b/CodeDocumentor.Common/Helpers/TryHelper.cs index 5a508ae..723c18b 100644 --- a/CodeDocumentor.Common/Helpers/TryHelper.cs +++ b/CodeDocumentor.Common/Helpers/TryHelper.cs @@ -1,7 +1,7 @@ using System; using CodeDocumentor.Common.Interfaces; -namespace CodeDocumentor.Common +namespace CodeDocumentor.Common.Helpers { public static class TryHelper { diff --git a/CodeDocumentor.Common/Interfaces/ISettingService.cs b/CodeDocumentor.Common/Interfaces/ISettingService.cs new file mode 100644 index 0000000..9e184be --- /dev/null +++ b/CodeDocumentor.Common/Interfaces/ISettingService.cs @@ -0,0 +1,10 @@ +using Microsoft.CodeAnalysis.Diagnostics; + +namespace CodeDocumentor.Common.Interfaces +{ + public interface ISettingService + { + ISettings BuildSettings(AnalyzerConfigOptions options, ISettings Settings); + ISettings BuildSettings(SyntaxNodeAnalysisContext context, ISettings Settings); + } +} diff --git a/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs b/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs index c576801..1254d19 100644 --- a/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs +++ b/CodeDocumentor.Test/Builders/DocumentationBuilderTests.cs @@ -1,8 +1,6 @@ using System.Diagnostics.CodeAnalysis; -using CodeDocumentor.Builders; -using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Analyzers.Builders; using FluentAssertions; -using Moq; using Xunit; using Xunit.Abstractions; diff --git a/CodeDocumentor.Test/Classes/ClassUnitTests.cs b/CodeDocumentor.Test/Classes/ClassUnitTests.cs index 3891a12..25c2b45 100644 --- a/CodeDocumentor.Test/Classes/ClassUnitTests.cs +++ b/CodeDocumentor.Test/Classes/ClassUnitTests.cs @@ -1,4 +1,6 @@ using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Classes; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/CodeDocumentor.Test.csproj b/CodeDocumentor.Test/CodeDocumentor.Test.csproj index 2e133a4..81bf4b0 100644 --- a/CodeDocumentor.Test/CodeDocumentor.Test.csproj +++ b/CodeDocumentor.Test/CodeDocumentor.Test.csproj @@ -487,22 +487,24 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + compile; build; native; contentfiles; analyzers; buildtransitive - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -513,6 +515,7 @@ + diff --git a/CodeDocumentor.Test/Constructors/ConstructorUnitTests.cs b/CodeDocumentor.Test/Constructors/ConstructorUnitTests.cs index 44452a2..00126b7 100644 --- a/CodeDocumentor.Test/Constructors/ConstructorUnitTests.cs +++ b/CodeDocumentor.Test/Constructors/ConstructorUnitTests.cs @@ -1,5 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Constructors; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Enums/EnumUnitTests.cs b/CodeDocumentor.Test/Enums/EnumUnitTests.cs index 7d4004d..4909172 100644 --- a/CodeDocumentor.Test/Enums/EnumUnitTests.cs +++ b/CodeDocumentor.Test/Enums/EnumUnitTests.cs @@ -1,4 +1,6 @@ using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Enums; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Fields/FieldUnitTests.cs b/CodeDocumentor.Test/Fields/FieldUnitTests.cs index fb2bfa0..3f82226 100644 --- a/CodeDocumentor.Test/Fields/FieldUnitTests.cs +++ b/CodeDocumentor.Test/Fields/FieldUnitTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Fields; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Helper/CommentHelperTests.cs b/CodeDocumentor.Test/Helper/CommentHelperTests.cs index b2e4e8a..3a9b68a 100644 --- a/CodeDocumentor.Test/Helper/CommentHelperTests.cs +++ b/CodeDocumentor.Test/Helper/CommentHelperTests.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Helper; using CodeDocumentor.Test.TestHelpers; using FluentAssertions; using Microsoft.CodeAnalysis; @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Xunit; using Xunit.Abstractions; +using CodeDocumentor.Common.Extensions; namespace CodeDocumentor.Test.Helper { diff --git a/CodeDocumentor.Test/Helper/DocumentationHeaderHelperTests.cs b/CodeDocumentor.Test/Helper/DocumentationHeaderHelperTests.cs index 67b0aa6..ecc5ff5 100644 --- a/CodeDocumentor.Test/Helper/DocumentationHeaderHelperTests.cs +++ b/CodeDocumentor.Test/Helper/DocumentationHeaderHelperTests.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers.Helper; using FluentAssertions; using Xunit; using Xunit.Abstractions; diff --git a/CodeDocumentor.Test/Helper/NameSplitterTests.cs b/CodeDocumentor.Test/Helper/NameSplitterTests.cs index 5965a75..0373156 100644 --- a/CodeDocumentor.Test/Helper/NameSplitterTests.cs +++ b/CodeDocumentor.Test/Helper/NameSplitterTests.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; -using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using FluentAssertions; using Xunit; diff --git a/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs b/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs index 7b25535..6d9f3ef 100644 --- a/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs +++ b/CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; +using CodeDocumentor.Analyzers.Constructors; using CodeDocumentor.Common.Models; -using CodeDocumentor.Constructors; using FluentAssertions; using Microsoft.CodeAnalysis.CSharp; using Xunit; diff --git a/CodeDocumentor.Test/Helper/TranslatorTests.cs b/CodeDocumentor.Test/Helper/TranslatorTests.cs index d629766..c0e5912 100644 --- a/CodeDocumentor.Test/Helper/TranslatorTests.cs +++ b/CodeDocumentor.Test/Helper/TranslatorTests.cs @@ -2,10 +2,10 @@ using System.Linq; using CodeDocumentor.Common; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; using FluentAssertions; using Xunit; using Xunit.Abstractions; +using CodeDocumentor.Common.Extensions; namespace CodeDocumentor.Test.Helper { diff --git a/CodeDocumentor.Test/Interfaces/InterfaceUnitTests.cs b/CodeDocumentor.Test/Interfaces/InterfaceUnitTests.cs index 4b9ccd7..0f9dfaa 100644 --- a/CodeDocumentor.Test/Interfaces/InterfaceUnitTests.cs +++ b/CodeDocumentor.Test/Interfaces/InterfaceUnitTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Interfaces; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Methods/MethodUnitTests.cs b/CodeDocumentor.Test/Methods/MethodUnitTests.cs index 1bd2d3a..baec7a3 100644 --- a/CodeDocumentor.Test/Methods/MethodUnitTests.cs +++ b/CodeDocumentor.Test/Methods/MethodUnitTests.cs @@ -1,5 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Methods; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Properties/PropertyUnitTests.cs b/CodeDocumentor.Test/Properties/PropertyUnitTests.cs index 55d0d3b..065b99a 100644 --- a/CodeDocumentor.Test/Properties/PropertyUnitTests.cs +++ b/CodeDocumentor.Test/Properties/PropertyUnitTests.cs @@ -1,6 +1,8 @@ using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Properties; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/Records/RecordUnitTests.cs b/CodeDocumentor.Test/Records/RecordUnitTests.cs index dc3f9f2..bc8d3db 100644 --- a/CodeDocumentor.Test/Records/RecordUnitTests.cs +++ b/CodeDocumentor.Test/Records/RecordUnitTests.cs @@ -1,4 +1,6 @@ using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Records; using CodeDocumentor.Test.TestHelpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor.Test/TestFixture.cs b/CodeDocumentor.Test/TestFixture.cs index ef038ac..1bb775c 100644 --- a/CodeDocumentor.Test/TestFixture.cs +++ b/CodeDocumentor.Test/TestFixture.cs @@ -6,8 +6,10 @@ using System.Linq; using System.Reflection; using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Common.Models; +using CodeDocumentor.Services; using CodeDocumentor.Test.TestHelpers; using FluentAssertions; using Microsoft.CodeAnalysis; @@ -62,6 +64,8 @@ public void Initialize(ITestOutputHelper output) MockSettings = new TestSettings(); BaseCodeFixProvider.SetSettings(MockSettings); BaseDiagnosticAnalyzer.SetSettings(MockSettings); + ServiceLocator.SettingService = new SettingService(); + ServiceLocator.Logger = new Logger(); } public void SetPublicProcessingOption(ISettings o, string diagType) diff --git a/CodeDocumentor.sln b/CodeDocumentor.sln index 3460881..9eb723f 100644 --- a/CodeDocumentor.sln +++ b/CodeDocumentor.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31912.275 +# Visual Studio Version 18 +VisualStudioVersion = 18.0.11109.219 d18.0-oob MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{FC202D1D-DC77-4AD6-BFA7-AFD04EFCAB03}" ProjectSection(SolutionItems) = preProject @@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeDocumentor.Common", "CodeDocumentor.Common\CodeDocumentor.Common.csproj", "{7CC64CDF-A7FF-463B-8F05-C37A6C0A820C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeDocumentor.Analyzers", "CodeDocumentor.Analyzers\CodeDocumentor.Analyzers.csproj", "{738D16AF-93E6-4F9C-9F6A-9283A3E62243}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -89,6 +91,18 @@ Global {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 + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|Any CPU.Build.0 = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|x64.ActiveCfg = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|x64.Build.0 = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|x86.ActiveCfg = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Debug|x86.Build.0 = Debug|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|Any CPU.ActiveCfg = Release|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|Any CPU.Build.0 = Release|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|x64.ActiveCfg = Release|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|x64.Build.0 = Release|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|x86.ActiveCfg = Release|Any CPU + {738D16AF-93E6-4F9C-9F6A-9283A3E62243}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CodeDocumentor/CodeDocumentor.Package.cs b/CodeDocumentor/CodeDocumentor.Package.cs index 8203255..929d005 100644 --- a/CodeDocumentor/CodeDocumentor.Package.cs +++ b/CodeDocumentor/CodeDocumentor.Package.cs @@ -1,10 +1,12 @@ using System; -using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; using CodeDocumentor.Common.Models; +using CodeDocumentor.Services; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Threading; @@ -63,6 +65,15 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke // When initialized asynchronously, the current thread may be a background thread at this point. Do any // initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + Load(); + + } + + private void Load() + { + //this needs to be set here due to bootstrapping environment and where EventLog is available + ServiceLocator.Logger = new Logger(); + ServiceLocator.SettingService = new SettingService(); //var hasCodeDocumentorInEditorConfig = await SlnHasEditorConfigAsync(hasCodeDocumentorInEditorConfig); @@ -73,33 +84,32 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke settings.SetFromOptionsGrid(options); BaseCodeFixProvider.SetSettings(settings); BaseDiagnosticAnalyzer.SetSettings(settings); - } - private async System.Threading.Tasks.Task SlnHasEditorConfigAsync(bool hasCodeDocumentorInEditorConfig) - { - var solutionService = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution; - if (solutionService != null) - { - solutionService.GetSolutionInfo(out string solutionDir, out _, out _); + //private async System.Threading.Tasks.Task SlnHasEditorConfigAsync(bool hasCodeDocumentorInEditorConfig) + //{ + // var solutionService = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution; + // if (solutionService != null) + // { + // solutionService.GetSolutionInfo(out string solutionDir, out _, out _); - if (!string.IsNullOrEmpty(solutionDir)) - { - // Look for .editorconfig in the solution directory - var editorConfigPath = System.IO.Path.Combine(solutionDir, ".editorconfig"); - if (System.IO.File.Exists(editorConfigPath)) - { - // Read the .editorconfig file - var lines = System.IO.File.ReadAllLines(editorConfigPath); - // Check for a specific value, e.g., "my_setting = true" - hasCodeDocumentorInEditorConfig = lines.Any(line => line.Trim().StartsWith("codedocumentor_", StringComparison.OrdinalIgnoreCase)); + // if (!string.IsNullOrEmpty(solutionDir)) + // { + // // Look for .editorconfig in the solution directory + // var editorConfigPath = System.IO.Path.Combine(solutionDir, ".editorconfig"); + // if (System.IO.File.Exists(editorConfigPath)) + // { + // // Read the .editorconfig file + // var lines = System.IO.File.ReadAllLines(editorConfigPath); + // // Check for a specific value, e.g., "my_setting = true" + // hasCodeDocumentorInEditorConfig = lines.Any(line => line.Trim().StartsWith("codedocumentor_", StringComparison.OrdinalIgnoreCase)); - } - } - } + // } + // } + // } - return hasCodeDocumentorInEditorConfig; - } + // return hasCodeDocumentorInEditorConfig; + //} #endregion } diff --git a/CodeDocumentor/CodeDocumentor.csproj b/CodeDocumentor/CodeDocumentor.csproj index 5da1759..8c40b6f 100644 --- a/CodeDocumentor/CodeDocumentor.csproj +++ b/CodeDocumentor/CodeDocumentor.csproj @@ -53,63 +53,25 @@ 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + Component - - - - - - - + @@ -117,22 +79,18 @@ - - 4.13.0 - - + compile; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all - 8.0.0 + 9.0.9 - - - + + @@ -151,8 +109,11 @@ true - + + {738d16af-93e6-4f9c-9f6a-9283a3e62243} + CodeDocumentor.Analyzers + {7cc64cdf-a7ff-463b-8f05-c37a6c0a820c} CodeDocumentor.Common diff --git a/CodeDocumentor/Helper/EditorConfigExtensions.cs b/CodeDocumentor/Helper/EditorConfigExtensions.cs index 10c0bb5..bc7f880 100644 --- a/CodeDocumentor/Helper/EditorConfigExtensions.cs +++ b/CodeDocumentor/Helper/EditorConfigExtensions.cs @@ -1,111 +1,18 @@ -using System; -using System.Linq; using System.Threading.Tasks; -using CodeDocumentor.Common; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Common.Models; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.Diagnostics; -namespace CodeDocumentor.Helper +namespace CodeDocumentor { public static class EditorConfigExtensions { - public static async Task BuildSettingsAsync(this CodeFixContext context, ISettings staticSettings) + public static async Task BuildSettingsAsync(this CodeFixContext context, ISettings Settings) { var tree = await context.Document.GetSyntaxTreeAsync(); - return context.Document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(tree).BuildSettings(staticSettings); - } - public static ISettings BuildSettings(this SyntaxNodeAnalysisContext context, ISettings staticSettings) - { - return context.Options.AnalyzerConfigOptionsProvider.GetOptions(context.Node.SyntaxTree).BuildSettings(staticSettings); - } - public static ISettings BuildSettings(this AnalyzerConfigOptions options, ISettings staticSettings) - { - var settings = new Settings(); - var defaultSev = DiagnosticSeverity.Warning; - if (!options.CanReadEditorConfig()) - { - //no editorconfig, return the static settings we have - return staticSettings; - } - - settings.ClassDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_class_diagram_severity", defaultSev); - settings.ConstructorDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_constructor_diagram_severity", defaultSev); - settings.DefaultDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_default_diagram_severity", defaultSev); - settings.EnumDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_enum_diagram_severity", defaultSev); - settings.FieldDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_field_diagram_severity", defaultSev); - settings.InterfaceDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_interface_diagram_severity", defaultSev); - settings.MethodDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_method_diagram_severity", defaultSev); - settings.PropertyDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_property_diagram_severity", defaultSev); - settings.RecordDiagnosticSeverity = options.ConvertToDiagnosticSeverity("codedocumentor_record_diagram_severity", defaultSev); - - settings.ExcludeAsyncSuffix = options.ConvertToBoolean("codedocumentor_exclude_async_suffix", false); - - settings.IncludeValueNodeInProperties = options.ConvertToBoolean("codedocumentor_include_value_node_in_properties", false); - settings.IsEnabledForPublicMembersOnly = options.ConvertToBoolean("codedocumentor_is_enabled_for_public_members_only", false); - settings.IsEnabledForNonPublicFields = options.ConvertToBoolean("codedocumentor_is_enabled_for_non_public_fields", false); - settings.PreserveExistingSummaryText = options.ConvertToBoolean("codedocumentor_preserve_existing_summary_text", true); - settings.TryToIncludeCrefsForReturnTypes = options.ConvertToBoolean("codedocumentor_try_to_include_crefs_for_return_types", true); - settings.UseNaturalLanguageForReturnNode = options.ConvertToBoolean("codedocumentor_use_natural_language_for_return_node", false); - settings.UseToDoCommentsOnSummaryError = options.ConvertToBoolean("codedocumentor_use_todo_comments_on_summary_error", true); - settings.WordMaps = options.ConvertToWordMap("codedocumentor_wordmap", Constants.DEFAULT_WORD_MAPS); - return settings; - } - - private static bool CanReadEditorConfig(this AnalyzerConfigOptions options) - { - return options.Keys.Any(a => a.StartsWith("codedocumentor_")); - } - - - private static WordMap[] ConvertToWordMap(this AnalyzerConfigOptions options, string key, WordMap[] defaultWordMaps) - { - options.TryGetValue(key, out var cds); - if (string.IsNullOrWhiteSpace(cds)) - { - return defaultWordMaps; - } - - return cds - .Split('|') - .Select(pair => pair.Split(':')) - .Where(parts => parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1])) - .Select(parts => new WordMap - { - Word = parts[0], - Translation = parts[1] - }) - .ToArray(); - } - - private static bool ConvertToBoolean(this AnalyzerConfigOptions options, string key, bool defaultBool) - { - options.TryGetValue(key, out var cds); - if (string.IsNullOrEmpty(cds)) - { - return defaultBool; - } - if (bool.TryParse(cds, out var converted)) - { - return converted; - } - return defaultBool; - } - - private static DiagnosticSeverity ConvertToDiagnosticSeverity(this AnalyzerConfigOptions options, string key, DiagnosticSeverity defaultSeverity) - { - options.TryGetValue(key, out var cds); - if (string.IsNullOrEmpty(cds)) - { - return defaultSeverity; - } - if (Enum.TryParse(cds, out var converted)) - { - return converted; - } - return defaultSeverity; + var opts = context.Document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(tree); + var svc = ServiceLocator.SettingService; + return svc.BuildSettings(opts, Settings); } } } diff --git a/CodeDocumentor/Helper/Logger.cs b/CodeDocumentor/Helper/Logger.cs index d972bc6..10e21b4 100644 --- a/CodeDocumentor/Helper/Logger.cs +++ b/CodeDocumentor/Helper/Logger.cs @@ -8,7 +8,7 @@ namespace CodeDocumentor { - public class Logger: IEventLogger + public class Logger : IEventLogger { /// /// Logs the error. @@ -21,7 +21,7 @@ public void LogError(string message, int eventId, short category, string diagnos // I'm co-opting the Visual Studio event source because I can't register my own from a .VSIX installer. EventLog.WriteEntry("Visual Studio", $"CodeDocumentor: DiagnosticId: {diagnosticId}. Message: {message ?? "null"}", - EventLogEntryType.Error,eventId, category); + EventLogEntryType.Error, eventId, category); } catch { diff --git a/CodeDocumentor/Models/OptionPageGrid.cs b/CodeDocumentor/Models/OptionPageGrid.cs index b6b00ff..895b05d 100644 --- a/CodeDocumentor/Models/OptionPageGrid.cs +++ b/CodeDocumentor/Models/OptionPageGrid.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Forms; +using CodeDocumentor.Analyzers; using CodeDocumentor.Common; using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Common.Models; diff --git a/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs b/CodeDocumentor/Providers/BaseCodeFixProvider.cs similarity index 96% rename from CodeDocumentor/Analyzers/BaseCodeFixProvider.cs rename to CodeDocumentor/Providers/BaseCodeFixProvider.cs index 8164454..beb566f 100644 --- a/CodeDocumentor/Analyzers/BaseCodeFixProvider.cs +++ b/CodeDocumentor/Providers/BaseCodeFixProvider.cs @@ -2,10 +2,12 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs b/CodeDocumentor/Providers/Classes/ClassCodeFixProvider.cs similarity index 94% rename from CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs rename to CodeDocumentor/Providers/Classes/ClassCodeFixProvider.cs index 68f8c30..a7e69fe 100644 --- a/CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Classes/ClassCodeFixProvider.cs @@ -4,10 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -96,7 +98,7 @@ internal Task AddDocumentationHeaderAsync(ISettings settings, Document /// /// The root. /// The nodes to replace. - internal static int BuildComments(ISettings settings, SyntaxNode root, Dictionary nodesToReplace) + internal static int BuildComments(ISettings settings, SyntaxNode root, Dictionary nodesToReplace) { var declarations = root.DescendantNodes().Where(w => w.IsKind(SyntaxKind.ClassDeclaration)).OfType().ToArray(); var neededCommentCount = 0; @@ -123,7 +125,7 @@ internal static int BuildComments(ISettings settings, SyntaxNode root, Dictiona private static ClassDeclarationSyntax BuildNewDeclaration(ISettings settings, ClassDeclarationSyntax declarationSyntax) { - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var comment = commentHelper.CreateClassComment(declarationSyntax.Identifier.ValueText, settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; var list = builder.WithSummary(declarationSyntax, comment, settings.PreserveExistingSummaryText) diff --git a/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs b/CodeDocumentor/Providers/Constructors/ConstructorCodeFixProvider.cs similarity index 97% rename from CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs rename to CodeDocumentor/Providers/Constructors/ConstructorCodeFixProvider.cs index 469679d..69bcbb1 100644 --- a/CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Constructors/ConstructorCodeFixProvider.cs @@ -4,10 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -118,7 +120,7 @@ private static ConstructorDeclarationSyntax BuildNewDeclaration(ISettings settin /// A DocumentationCommentTriviaSyntax. private static DocumentationCommentTriviaSyntax CreateDocumentationCommentTriviaSyntax(ISettings settings, ConstructorDeclarationSyntax declarationSyntax) { - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var comment = commentHelper.CreateConstructorComment(declarationSyntax.Identifier.ValueText, declarationSyntax.IsPrivate(), settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; var list = builder.WithSummary(declarationSyntax, comment, settings.PreserveExistingSummaryText) diff --git a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs b/CodeDocumentor/Providers/Enums/EnumCodeFixProvider.cs similarity index 98% rename from CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs rename to CodeDocumentor/Providers/Enums/EnumCodeFixProvider.cs index 49b7b5c..1c5b171 100644 --- a/CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Enums/EnumCodeFixProvider.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs b/CodeDocumentor/Providers/Fields/FieldCodeFixProvider.cs similarity index 96% rename from CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs rename to CodeDocumentor/Providers/Fields/FieldCodeFixProvider.cs index 6ac9174..e3103bd 100644 --- a/CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Fields/FieldCodeFixProvider.cs @@ -4,10 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -106,7 +108,7 @@ private static FieldDeclarationSyntax BuildNewDeclaration(ISettings settings, Fi { var leadingTrivia = declarationSyntax.GetLeadingTrivia(); var field = declarationSyntax.DescendantNodes().OfType().FirstOrDefault(); - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var comment = commentHelper.CreateFieldComment(field?.Identifier.ValueText, settings.ExcludeAsyncSuffix, settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; diff --git a/CodeDocumentor/Analyzers/Files/FileCodeFixProvider.cs b/CodeDocumentor/Providers/Files/FileCodeFixProvider.cs similarity index 97% rename from CodeDocumentor/Analyzers/Files/FileCodeFixProvider.cs rename to CodeDocumentor/Providers/Files/FileCodeFixProvider.cs index 99a72c3..becaaa1 100644 --- a/CodeDocumentor/Analyzers/Files/FileCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Files/FileCodeFixProvider.cs @@ -3,9 +3,8 @@ using System.Composition; using System.Diagnostics; using System.Linq; -using System.Threading; using System.Threading.Tasks; -using CodeDocumentor.Helper; +using CodeDocumentor.Analyzers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -68,7 +67,7 @@ public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context) SyntaxNode root = await tempDoc.GetSyntaxRootAsync(context.CancellationToken); //Order Matters var neededCommentCount = 0; - neededCommentCount += PropertyCodeFixProvider.BuildComments(settings,root, _nodesTempToReplace); + neededCommentCount += PropertyCodeFixProvider.BuildComments(settings, root, _nodesTempToReplace); neededCommentCount += ConstructorCodeFixProvider.BuildComments(settings, root, _nodesTempToReplace); neededCommentCount += EnumCodeFixProvider.BuildComments(settings, root, _nodesTempToReplace); neededCommentCount += FieldCodeFixProvider.BuildComments(settings, root, _nodesTempToReplace); diff --git a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs b/CodeDocumentor/Providers/Interfaces/InterfaceCodeFixProvider.cs similarity index 92% rename from CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs rename to CodeDocumentor/Providers/Interfaces/InterfaceCodeFixProvider.cs index 58d1455..58fabe8 100644 --- a/CodeDocumentor/Analyzers/Interfaces/InterfaceCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Interfaces/InterfaceCodeFixProvider.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -57,7 +58,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { return; } - var settings =await context.BuildSettingsAsync(StaticSettings); + var settings = await context.BuildSettingsAsync(StaticSettings); var displayTitle = declaration.HasSummary() ? TitleRebuild : Title; context.RegisterCodeFix( CodeAction.Create( @@ -96,7 +97,7 @@ internal static int BuildComments(ISettings settings, SyntaxNode root, Dictionar private static InterfaceDeclarationSyntax BuildNewDeclaration(ISettings settings, InterfaceDeclarationSyntax declarationSyntax) { - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var comment = commentHelper.CreateInterfaceComment(declarationSyntax.Identifier.ValueText, settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; var list = builder.WithSummary(declarationSyntax, comment, settings.PreserveExistingSummaryText) @@ -125,7 +126,7 @@ private Task AddDocumentationHeaderAsync(ISettings settings, Document var newDeclaration = BuildNewDeclaration(settings, declarationSyntax); var newRoot = root.ReplaceNode(declarationSyntax, newDeclaration); return document.WithSyntaxRoot(newRoot); - }, InterfaceAnalyzerSettings.DiagnosticId , EventLogger, (_) => 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/MethodCodeFixProvider.cs b/CodeDocumentor/Providers/Methods/MethodCodeFixProvider.cs similarity index 98% rename from CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs rename to CodeDocumentor/Providers/Methods/MethodCodeFixProvider.cs index a01cde0..a68a608 100644 --- a/CodeDocumentor/Analyzers/Methods/MethodCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Methods/MethodCodeFixProvider.cs @@ -4,10 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs b/CodeDocumentor/Providers/Properties/PropertyCodeFixProvider.cs similarity index 97% rename from CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs rename to CodeDocumentor/Providers/Properties/PropertyCodeFixProvider.cs index 2e9261a..259306d 100644 --- a/CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Properties/PropertyCodeFixProvider.cs @@ -4,11 +4,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; using CodeDocumentor.Common.Models; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -109,7 +111,7 @@ private static PropertyDeclarationSyntax BuildNewDeclaration(ISettings settings, var hasSetter = declarationSyntax.PropertyHasSetter(); - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var propertyComment = commentHelper.CreatePropertyComment(declarationSyntax.Identifier.ValueText, isBoolean, hasSetter, settings.ExcludeAsyncSuffix, settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; diff --git a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs b/CodeDocumentor/Providers/Records/RecordCodeFixProvider.cs similarity index 96% rename from CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs rename to CodeDocumentor/Providers/Records/RecordCodeFixProvider.cs index 9fdc32b..72d2a9c 100644 --- a/CodeDocumentor/Analyzers/Records/RecordCodeFixProvider.cs +++ b/CodeDocumentor/Providers/Records/RecordCodeFixProvider.cs @@ -4,10 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CodeDocumentor.Analyzers; +using CodeDocumentor.Analyzers.Helper; +using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common; +using CodeDocumentor.Common.Helpers; using CodeDocumentor.Common.Interfaces; -using CodeDocumentor.Helper; -using CodeDocumentor.Locators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -123,7 +125,7 @@ internal static int BuildComments(ISettings settings, SyntaxNode root, Dictionar private static RecordDeclarationSyntax BuildNewDeclaration(ISettings settings, RecordDeclarationSyntax declarationSyntax) { - var commentHelper = ServiceLocator.CommentHelper; + var commentHelper = ServiceLocator.CommentHelper; var comment = commentHelper.CreateRecordComment(declarationSyntax.Identifier.ValueText, settings.WordMaps); var builder = ServiceLocator.DocumentationBuilder; diff --git a/CodeDocumentor/Services/SettingService.cs b/CodeDocumentor/Services/SettingService.cs new file mode 100644 index 0000000..d409a72 --- /dev/null +++ b/CodeDocumentor/Services/SettingService.cs @@ -0,0 +1,107 @@ +using System; +using System.Linq; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Common.Models; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace CodeDocumentor.Services +{ + public class SettingService : ISettingService + { + public ISettings BuildSettings(SyntaxNodeAnalysisContext context, ISettings Settings) + { + var opts = context.Options.AnalyzerConfigOptionsProvider.GetOptions(context.Node.SyntaxTree); + return BuildSettings(opts, Settings); + } + + public ISettings BuildSettings(AnalyzerConfigOptions options, ISettings Settings) + { + var settings = new Settings(); + var defaultSev = DiagnosticSeverity.Warning; + if (!CanReadEditorConfig(options)) + { + //no editorconfig, return the settings we have + return Settings; + } + + settings.ClassDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_class_diagram_severity", defaultSev); + settings.ConstructorDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_constructor_diagram_severity", defaultSev); + settings.DefaultDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_default_diagram_severity", defaultSev); + settings.EnumDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_enum_diagram_severity", defaultSev); + settings.FieldDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_field_diagram_severity", defaultSev); + settings.InterfaceDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_interface_diagram_severity", defaultSev); + settings.MethodDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_method_diagram_severity", defaultSev); + settings.PropertyDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_property_diagram_severity", defaultSev); + settings.RecordDiagnosticSeverity = ConvertToDiagnosticSeverity(options, "codedocumentor_record_diagram_severity", defaultSev); + + settings.ExcludeAsyncSuffix = ConvertToBoolean(options, "codedocumentor_exclude_async_suffix", false); + + settings.IncludeValueNodeInProperties = ConvertToBoolean(options, "codedocumentor_include_value_node_in_properties", false); + settings.IsEnabledForPublicMembersOnly = ConvertToBoolean(options, "codedocumentor_is_enabled_for_public_members_only", false); + settings.IsEnabledForNonPublicFields = ConvertToBoolean(options, "codedocumentor_is_enabled_for_non_public_fields", false); + settings.PreserveExistingSummaryText = ConvertToBoolean(options, "codedocumentor_preserve_existing_summary_text", true); + settings.TryToIncludeCrefsForReturnTypes = ConvertToBoolean(options, "codedocumentor_try_to_include_crefs_for_return_types", true); + settings.UseNaturalLanguageForReturnNode = ConvertToBoolean(options, "codedocumentor_use_natural_language_for_return_node", false); + settings.UseToDoCommentsOnSummaryError = ConvertToBoolean(options, "codedocumentor_use_todo_comments_on_summary_error", true); + settings.WordMaps = ConvertToWordMap(options, "codedocumentor_wordmap", Constants.DEFAULT_WORD_MAPS); + return settings; + } + + + + private bool CanReadEditorConfig(AnalyzerConfigOptions options) + { + return options.Keys.Any(a => a.StartsWith("codedocumentor_")); + } + + private bool ConvertToBoolean(AnalyzerConfigOptions options, string key, bool defaultBool) + { + options.TryGetValue(key, out var cds); + if (string.IsNullOrEmpty(cds)) + { + return defaultBool; + } + if (bool.TryParse(cds, out var converted)) + { + return converted; + } + return defaultBool; + } + + private DiagnosticSeverity ConvertToDiagnosticSeverity(AnalyzerConfigOptions options, string key, DiagnosticSeverity defaultSeverity) + { + options.TryGetValue(key, out var cds); + if (string.IsNullOrEmpty(cds)) + { + return defaultSeverity; + } + if (Enum.TryParse(cds, out var converted)) + { + return converted; + } + return defaultSeverity; + } + + private WordMap[] ConvertToWordMap(AnalyzerConfigOptions options, string key, WordMap[] defaultWordMaps) + { + options.TryGetValue(key, out var cds); + if (string.IsNullOrWhiteSpace(cds)) + { + return defaultWordMaps; + } + + return cds + .Split('|') + .Select(pair => pair.Split(':')) + .Where(parts => parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1])) + .Select(parts => new WordMap + { + Word = parts[0], + Translation = parts[1] + }) + .ToArray(); + } + } +} diff --git a/Manifests/vs2022/source.extension.vsixmanifest b/Manifests/vs2022/source.extension.vsixmanifest index b0cfd16..7827955 100644 --- a/Manifests/vs2022/source.extension.vsixmanifest +++ b/Manifests/vs2022/source.extension.vsixmanifest @@ -1,44 +1,47 @@ - - - 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 f5a562360147a80ccd8d9803a6ecca4c9a4c8f27 Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Sun, 19 Oct 2025 17:17:27 -0600 Subject: [PATCH 2/6] code cleanup null guards --- .../Analyzers/BaseDiagnosticAnalyzer.cs | 5 ++- .../Analyzers/Files/FileAnalyzer.cs | 4 +- .../Locators/ServiceLocator.cs | 6 ++- .../Services/PreLoadLogger.cs | 18 +++++++++ .../Services/PreLoadSettingService.cs | 23 +++++++++++ CodeDocumentor.Common/Models/Settings.cs | 31 +++++++++++++-- CodeDocumentor/CodeDocumentor.Package.cs | 2 +- CodeDocumentor/CodeDocumentor.csproj | 1 + .../Helper/EditorConfigExtensions.cs | 15 +++++-- .../Providers/BaseCodeFixProvider.cs | 17 ++++---- .../Providers/Classes/ClassCodeFixProvider.cs | 4 +- .../Providers/Files/FileCodeFixProvider.cs | 39 ++++++++----------- CodeDocumentor/Settings/VsixOptions.cs | 2 +- .../vs2022/source.extension.vsixmanifest | 1 + 14 files changed, 122 insertions(+), 46 deletions(-) create mode 100644 CodeDocumentor.Analyzers/Services/PreLoadLogger.cs create mode 100644 CodeDocumentor.Analyzers/Services/PreLoadSettingService.cs diff --git a/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs index fcdcfc3..0798005 100644 --- a/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/BaseDiagnosticAnalyzer.cs @@ -1,10 +1,13 @@ using CodeDocumentor.Analyzers.Helper; using CodeDocumentor.Analyzers.Locators; using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Common.Models; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; namespace CodeDocumentor.Analyzers { + [DiagnosticAnalyzer(LanguageNames.CSharp)] public abstract class BaseDiagnosticAnalyzer : DiagnosticAnalyzer { protected DocumentationHeaderHelper DocumentationHeaderHelper = ServiceLocator.DocumentationHeaderHelper; @@ -18,6 +21,6 @@ public static void SetSettings(ISettings settings) protected static ISettings StaticSettings => //we serve up a fresh new instance from the static, and use that instead, keeps everything testable and decoupled from the static - _settings?.Clone(); + _settings?.Clone() ?? Settings.BuildDefaults(); } } diff --git a/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs index f5fe125..ac47f3e 100644 --- a/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs +++ b/CodeDocumentor.Analyzers/Analyzers/Files/FileAnalyzer.cs @@ -19,9 +19,7 @@ public override ImmutableArray SupportedDiagnostics { get { - return ImmutableArray.CreateRange(new List { - FileAnalyzerSettings.GetRule() } - ); + return ImmutableArray.Create(FileAnalyzerSettings.GetRule()); } } diff --git a/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs b/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs index 7d4331b..badca1f 100644 --- a/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs +++ b/CodeDocumentor.Analyzers/Locators/ServiceLocator.cs @@ -1,15 +1,17 @@ using CodeDocumentor.Analyzers.Builders; using CodeDocumentor.Analyzers.Helper; using CodeDocumentor.Analyzers.Managers; +using CodeDocumentor.Analyzers.Services; using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Services; namespace CodeDocumentor.Analyzers.Locators { public static class ServiceLocator { public static DocumentationHeaderHelper DocumentationHeaderHelper { get; } = new DocumentationHeaderHelper(); - public static IEventLogger Logger { get; set; } - public static ISettingService SettingService { get; set; } + public static IEventLogger Logger { get; set; } = new PreLoadLogger(); //this is a temp until the real logger can be set at package load time + public static ISettingService SettingService { get; set; } = new PreLoadSettingService(); //this is a temp until the LoadAsync can finish with the real settings. but we need something due to order of events firing public static CommentHelper CommentHelper { get; } = new CommentHelper(); public static GenericCommentManager GenericCommentManager { get; } = new GenericCommentManager(); public static DocumentationBuilder DocumentationBuilder => new DocumentationBuilder(); diff --git a/CodeDocumentor.Analyzers/Services/PreLoadLogger.cs b/CodeDocumentor.Analyzers/Services/PreLoadLogger.cs new file mode 100644 index 0000000..b787852 --- /dev/null +++ b/CodeDocumentor.Analyzers/Services/PreLoadLogger.cs @@ -0,0 +1,18 @@ + +using CodeDocumentor.Common.Interfaces; + +namespace CodeDocumentor.Analyzers.Services +{ + internal class PreLoadLogger : IEventLogger + { + public void LogError(string message, int eventId, short category, string diagnosticId) + { + + } + + public void LogInfo(string message, int eventId, short category, string diagnosticId) + { + + } + } +} diff --git a/CodeDocumentor.Analyzers/Services/PreLoadSettingService.cs b/CodeDocumentor.Analyzers/Services/PreLoadSettingService.cs new file mode 100644 index 0000000..88f8cae --- /dev/null +++ b/CodeDocumentor.Analyzers/Services/PreLoadSettingService.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using CodeDocumentor.Common; +using CodeDocumentor.Common.Interfaces; +using CodeDocumentor.Common.Models; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace CodeDocumentor.Services +{ + public class PreLoadSettingService : ISettingService + { + public ISettings BuildSettings(AnalyzerConfigOptions options, ISettings settings) + { + return Settings.BuildDefaults(); + } + + public ISettings BuildSettings(SyntaxNodeAnalysisContext context, ISettings settings) + { + return Settings.BuildDefaults(); + } + } +} diff --git a/CodeDocumentor.Common/Models/Settings.cs b/CodeDocumentor.Common/Models/Settings.cs index a1708bd..709f7c4 100644 --- a/CodeDocumentor.Common/Models/Settings.cs +++ b/CodeDocumentor.Common/Models/Settings.cs @@ -88,9 +88,34 @@ public class Settings : ISettings /// public bool UseEditorConfigForSettings { get; set; } + public static ISettings BuildDefaults() + { + return new Settings + { + ClassDiagnosticSeverity = DiagnosticSeverity.Warning, + ConstructorDiagnosticSeverity = DiagnosticSeverity.Warning, + DefaultDiagnosticSeverity = DiagnosticSeverity.Warning, + EnumDiagnosticSeverity = DiagnosticSeverity.Warning, + ExcludeAsyncSuffix = false, + FieldDiagnosticSeverity = DiagnosticSeverity.Warning, + IncludeValueNodeInProperties = false, + InterfaceDiagnosticSeverity = DiagnosticSeverity.Warning, + IsEnabledForNonPublicFields = false, + IsEnabledForPublicMembersOnly = false, + MethodDiagnosticSeverity = DiagnosticSeverity.Warning, + PreserveExistingSummaryText = true, + PropertyDiagnosticSeverity = DiagnosticSeverity.Warning, + RecordDiagnosticSeverity = DiagnosticSeverity.Warning, + TryToIncludeCrefsForReturnTypes = true, + UseNaturalLanguageForReturnNode = false, + UseToDoCommentsOnSummaryError = true, + WordMaps = Constants.DEFAULT_WORD_MAPS + }; + } + public ISettings Clone() { - var newService = new Settings + var newSettings = new Settings { ClassDiagnosticSeverity = ClassDiagnosticSeverity, ConstructorDiagnosticSeverity = ConstructorDiagnosticSeverity, @@ -120,8 +145,8 @@ public ISettings Clone() WordEvaluator = item.WordEvaluator }); } - newService.WordMaps = clonedMaps.ToArray(); - return newService; + newSettings.WordMaps = clonedMaps.ToArray(); + return newSettings; } } } diff --git a/CodeDocumentor/CodeDocumentor.Package.cs b/CodeDocumentor/CodeDocumentor.Package.cs index 929d005..e808e75 100644 --- a/CodeDocumentor/CodeDocumentor.Package.cs +++ b/CodeDocumentor/CodeDocumentor.Package.cs @@ -43,7 +43,7 @@ namespace CodeDocumentor.Vsix2022 [ProvideOptionPage(typeof(OptionPageGrid), OptionPageGrid.Category, OptionPageGrid.SubCategory, 1000, 1001, true)] //[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)] [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] - [ComVisible(true)] + //[ComVisible(true)] public sealed class CodeDocumentorPackage : AsyncPackage { #region Package Members diff --git a/CodeDocumentor/CodeDocumentor.csproj b/CodeDocumentor/CodeDocumentor.csproj index 8c40b6f..7df8525 100644 --- a/CodeDocumentor/CodeDocumentor.csproj +++ b/CodeDocumentor/CodeDocumentor.csproj @@ -119,6 +119,7 @@ CodeDocumentor.Common + From abf7806ccd88aff4918b035bf784bcbee46c0df9 Mon Sep 17 00:00:00 2001 From: "D. Turco" Date: Fri, 14 Nov 2025 17:25:14 -0700 Subject: [PATCH 6/6] update --- Readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 554e418..55a3e95 100644 --- a/Readme.md +++ b/Readme.md @@ -15,8 +15,7 @@ In the age of copilots this extension is still valuable when working on projects Download and install the VSIX from the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=DanTurco.CodeDocumentor) -**IMPORTANT!!** This extension is NOT compatible with Visual Studio 2026! While Microsoft claims backward compatibility, they have removed all support for analyzers being able to run in the foreground. Due to this this can no longer use Visual Studio Options Settings or load anything properly. -**IMPORTANT!!** A new version will be coming soon for Visual Studio 2026, that will run in the foreground, but no longer as an analyzer. +**IMPORTANT!!** This extension is NOT compatible with Visual Studio 2026! While Microsoft claims backward compatibility, they have removed all support for analyzers being able to run in the foreground. Due to this this can no longer use Visual Studio Options Settings or load anything properly. A new version will be coming soon for Visual Studio 2026, that will run in the foreground, but no longer as an analyzer. ## Table of Contents