Skip to content

Commit

Permalink
Merge pull request #28 from d1820/bug-fixes
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
d1820 authored Oct 29, 2023
2 parents 64a7af6 + 841018c commit 018fe5a
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 571 deletions.
50 changes: 25 additions & 25 deletions CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIReadOnlyCollection
var roc = TestFixture.BuildGenericNameSyntax("IReadOnlyCollection", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A read only collection of strings.");
comment.Should().Be("A read only collection of strings");
}

[Fact]
Expand All @@ -35,7 +35,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIReadOnlyCollection
var roc = TestFixture.BuildGenericNameSyntax("IReadOnlyCollection", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A read only collection of list of strings.");
comment.Should().Be("A read only collection of list of strings");
}

[Fact]
Expand All @@ -46,7 +46,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIReadOnlyCollection
var roc = TestFixture.BuildGenericNameSyntax("IReadOnlyCollection", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A read only collection of read only collections of strings.");
comment.Should().Be("A read only collection of read only collections of strings");
}

#endregion
Expand All @@ -59,7 +59,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromList()
var roc = TestFixture.BuildGenericNameSyntax("List", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

[Fact]
Expand All @@ -70,7 +70,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromListOfList()
var roc = TestFixture.BuildGenericNameSyntax("List", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of list of strings.");
comment.Should().Be("A list of list of strings");
}

[Fact]
Expand All @@ -83,7 +83,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromListOfListOfList()
var roc = TestFixture.BuildGenericNameSyntax("List", list2);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of list of list of strings.");
comment.Should().Be("A list of list of list of strings");
}

[Fact]
Expand All @@ -92,7 +92,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIList()
var roc = TestFixture.BuildGenericNameSyntax("IList", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

[Fact]
Expand All @@ -102,7 +102,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIListOfIList()
var roc = TestFixture.BuildGenericNameSyntax("IList", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of list of strings.");
comment.Should().Be("A list of list of strings");
}

[Fact]
Expand All @@ -111,7 +111,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromListOfInt()
var roc = TestFixture.BuildGenericNameSyntax("List", SyntaxKind.IntKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of integers.");
comment.Should().Be("A list of integers");
}

[Fact]
Expand All @@ -120,7 +120,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromListOfListOfInt()
var list = TestFixture.BuildGenericNameSyntax("List", SyntaxKind.IntKeyword);
var roc = TestFixture.BuildGenericNameSyntax("IList", list);
var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of list of integers.");
comment.Should().Be("A list of list of integers");
}

#endregion
Expand All @@ -133,7 +133,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIEnumerable()
var roc = TestFixture.BuildGenericNameSyntax("IEnumerable", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

[Fact]
Expand All @@ -143,7 +143,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIEnumerableOfIEnume
var roc = TestFixture.BuildGenericNameSyntax("IEnumerable", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of list of strings.");
comment.Should().Be("A list of list of strings");
}

#endregion
Expand All @@ -156,7 +156,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromICollection()
var roc = TestFixture.BuildGenericNameSyntax("ICollection", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

[Fact]
Expand All @@ -165,7 +165,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromCollection()
var roc = TestFixture.BuildGenericNameSyntax("Collection", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

#endregion
Expand All @@ -178,7 +178,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIDictionary()
var roc = TestFixture.BuildGenericNameSyntax("IDictionary", SyntaxKind.StringKeyword, SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type string and a value of type string.");
comment.Should().Be("A dictionary with a key of type string and a value of type string");
}

[Fact]
Expand All @@ -187,7 +187,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIDictionaryOfInt()
var roc = TestFixture.BuildGenericNameSyntax("IDictionary", SyntaxKind.IntKeyword, SyntaxKind.IntKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type integer and a value of type integer.");
comment.Should().Be("A dictionary with a key of type integer and a value of type integer");
}

[Fact]
Expand All @@ -196,7 +196,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromDictionary()
var roc = TestFixture.BuildGenericNameSyntax("Dictionary", SyntaxKind.StringKeyword, SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type string and a value of type string.");
comment.Should().Be("A dictionary with a key of type string and a value of type string");
}

[Fact]
Expand All @@ -206,7 +206,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromDictionaryWithListV
var roc = TestFixture.BuildGenericNameSyntax("Dictionary", SyntaxKind.StringKeyword, list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type string and a value of type list of strings.");
comment.Should().Be("A dictionary with a key of type string and a value of type list of strings");
}

[Fact]
Expand All @@ -217,7 +217,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromDictionaryWithListO
var roc = TestFixture.BuildGenericNameSyntax("Dictionary", SyntaxKind.StringKeyword, list2);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type string and a value of type list of list of strings.");
comment.Should().Be("A dictionary with a key of type string and a value of type list of list of strings");
}

#endregion
Expand All @@ -230,7 +230,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromTaskOfString()
var roc = TestFixture.BuildGenericNameSyntax("Task", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A string.");
comment.Should().Be("string");
}

[Fact]
Expand All @@ -240,7 +240,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromTaskOfList()
var roc = TestFixture.BuildGenericNameSyntax("Task", list);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A list of strings.");
comment.Should().Be("A list of strings");
}

[Fact]
Expand All @@ -251,7 +251,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromTaskOfDictionary()
var roc = TestFixture.BuildGenericNameSyntax("Task", dict);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A dictionary with a key of type string and a value of type list of strings.");
comment.Should().Be("A dictionary with a key of type string and a value of type list of strings");
}

[Fact]
Expand All @@ -261,7 +261,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromTaskOfCustom()
var roc = TestFixture.BuildGenericNameSyntax("Task", custom);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A CustomClass.");
comment.Should().Be("CustomClass");
}

#endregion
Expand All @@ -281,7 +281,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromUnknown()
var roc = TestFixture.BuildGenericNameSyntax("Span", SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A Span.");
comment.Should().Be("Span");
}

[Fact]
Expand All @@ -290,7 +290,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromUnknownGeneric()
var roc = TestFixture.BuildGenericNameSyntax("CustomClass", SyntaxKind.StringKeyword, SyntaxKind.StringKeyword);

var comment = _returnCommentBuilder.BuildComment(roc, false);
comment.Should().Be("A CustomClass.");
comment.Should().Be("CustomClass");
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private static FieldDeclarationSyntax BuildNewDeclaration(FieldDeclarationSyntax
{
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();

VariableDeclaratorSyntax field = declarationSyntax.DescendantNodes().OfType<VariableDeclaratorSyntax>().First();
string comment = CommentHelper.CreateFieldComment(field.Identifier.ValueText);
VariableDeclaratorSyntax field = declarationSyntax.DescendantNodes().OfType<VariableDeclaratorSyntax>().FirstOrDefault();
string comment = CommentHelper.CreateFieldComment(field?.Identifier.ValueText);
DocumentationCommentTriviaSyntax commentTrivia = DocumentationHeaderHelper.CreateOnlySummaryDocumentationCommentTrivia(comment);

FieldDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(leadingTrivia.UpsertLeadingTrivia(commentTrivia));
Expand Down
15 changes: 10 additions & 5 deletions CodeDocumentor/Analyzers/Files/BaseCodeFixProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks;
using CodeDocumentor.Vsix2022;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -31,11 +32,15 @@ public abstract class BaseCodeFixProvider : CodeFixProvider
/// <returns> A Task. </returns>
protected async Task RegisterFileCodeFixesAsync(CodeFixContext context, Diagnostic diagnostic)
{
if (Runtime.RunningUnitTests)
{
return;
}

#if DEBUG
//if (Runtime.RunningUnitTests)
//{
// Debug.WriteLine("!!!DISABLING FILE CODE FIX. EITHER TESTS ARE RUNNING OR DEBUGGER IS ATTACHED!!!");
// return;
//}
Debug.WriteLine("!!!DISABLING FILE CODE FIX. EITHER TESTS ARE RUNNING OR DEBUGGER IS ATTACHED!!!");
return;
#endif
//build it up, but check for counts if anything actually needs to be shown
var _nodesTempToReplace = new Dictionary<CSharpSyntaxNode, CSharpSyntaxNode>();
Document tempDoc = context.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace CodeDocumentor
{
/// <summary> The property code fix provider. </summary>
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(PropertyCodeFixProvider)), Shared]
public class PropertyCodeFixProvider : CodeFixProvider
public class PropertyCodeFixProvider : BaseCodeFixProvider
{
/// <summary> Gets the fixable diagnostic ids. </summary>
public override sealed ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(PropertyAnalyzerSettings.DiagnosticId);
Expand Down Expand Up @@ -53,6 +53,8 @@ public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
createChangedDocument: c => AddDocumentationHeaderAsync(context.Document, root, declaration, c),
equivalenceKey: displayTitle),
diagnostic);

await RegisterFileCodeFixesAsync(context, diagnostic);
}

/// <summary> Builds the comments. This is only used in the file level fixProvider. </summary>
Expand Down
1 change: 1 addition & 0 deletions CodeDocumentor/CodeDocumentor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Analyzers\Classes\NonPublicClassAnalyzer.cs" />
<Compile Include="Analyzers\Methods\NonPublicMethodAnalyzer.cs" />
<Compile Include="Analyzers\Properties\NonPublicPropertyAnalyzer.cs" />
<Compile Include="Models\XmlInformation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Analyzers\Properties\PropertyAnalyzer.cs" />
<Compile Include="Analyzers\Properties\PropertyAnalyzerSettings.cs" />
Expand Down
Loading

0 comments on commit 018fe5a

Please sign in to comment.