Skip to content

Commit 018fe5a

Browse files
authored
Merge pull request #28 from d1820/bug-fixes
bug fixes
2 parents 64a7af6 + 841018c commit 018fe5a

17 files changed

Lines changed: 509 additions & 571 deletions

CodeDocumentor.Test/Helper/ReturnCommentConstructionTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void GenerateGenericTypeComment_CreatesValidStringFromIReadOnlyCollection
2424
var roc = TestFixture.BuildGenericNameSyntax("IReadOnlyCollection", SyntaxKind.StringKeyword);
2525

2626
var comment = _returnCommentBuilder.BuildComment(roc, false);
27-
comment.Should().Be("A read only collection of strings.");
27+
comment.Should().Be("A read only collection of strings");
2828
}
2929

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

3737
var comment = _returnCommentBuilder.BuildComment(roc, false);
38-
comment.Should().Be("A read only collection of list of strings.");
38+
comment.Should().Be("A read only collection of list of strings");
3939
}
4040

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

4848
var comment = _returnCommentBuilder.BuildComment(roc, false);
49-
comment.Should().Be("A read only collection of read only collections of strings.");
49+
comment.Should().Be("A read only collection of read only collections of strings");
5050
}
5151

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

6161
var comment = _returnCommentBuilder.BuildComment(roc, false);
62-
comment.Should().Be("A list of strings.");
62+
comment.Should().Be("A list of strings");
6363
}
6464

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

7272
var comment = _returnCommentBuilder.BuildComment(roc, false);
73-
comment.Should().Be("A list of list of strings.");
73+
comment.Should().Be("A list of list of strings");
7474
}
7575

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

8585
var comment = _returnCommentBuilder.BuildComment(roc, false);
86-
comment.Should().Be("A list of list of list of strings.");
86+
comment.Should().Be("A list of list of list of strings");
8787
}
8888

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

9494
var comment = _returnCommentBuilder.BuildComment(roc, false);
95-
comment.Should().Be("A list of strings.");
95+
comment.Should().Be("A list of strings");
9696
}
9797

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

104104
var comment = _returnCommentBuilder.BuildComment(roc, false);
105-
comment.Should().Be("A list of list of strings.");
105+
comment.Should().Be("A list of list of strings");
106106
}
107107

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

113113
var comment = _returnCommentBuilder.BuildComment(roc, false);
114-
comment.Should().Be("A list of integers.");
114+
comment.Should().Be("A list of integers");
115115
}
116116

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

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

135135
var comment = _returnCommentBuilder.BuildComment(roc, false);
136-
comment.Should().Be("A list of strings.");
136+
comment.Should().Be("A list of strings");
137137
}
138138

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

145145
var comment = _returnCommentBuilder.BuildComment(roc, false);
146-
comment.Should().Be("A list of list of strings.");
146+
comment.Should().Be("A list of list of strings");
147147
}
148148

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

158158
var comment = _returnCommentBuilder.BuildComment(roc, false);
159-
comment.Should().Be("A list of strings.");
159+
comment.Should().Be("A list of strings");
160160
}
161161

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

167167
var comment = _returnCommentBuilder.BuildComment(roc, false);
168-
comment.Should().Be("A list of strings.");
168+
comment.Should().Be("A list of strings");
169169
}
170170

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

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

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

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

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

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

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

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

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

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

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

232232
var comment = _returnCommentBuilder.BuildComment(roc, false);
233-
comment.Should().Be("A string.");
233+
comment.Should().Be("string");
234234
}
235235

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

242242
var comment = _returnCommentBuilder.BuildComment(roc, false);
243-
comment.Should().Be("A list of strings.");
243+
comment.Should().Be("A list of strings");
244244
}
245245

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

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

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

263263
var comment = _returnCommentBuilder.BuildComment(roc, false);
264-
comment.Should().Be("A CustomClass.");
264+
comment.Should().Be("CustomClass");
265265
}
266266

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

283283
var comment = _returnCommentBuilder.BuildComment(roc, false);
284-
comment.Should().Be("A Span.");
284+
comment.Should().Be("Span");
285285
}
286286

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

292292
var comment = _returnCommentBuilder.BuildComment(roc, false);
293-
comment.Should().Be("A CustomClass.");
293+
comment.Should().Be("CustomClass");
294294
}
295295

296296
#endregion

CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ private static FieldDeclarationSyntax BuildNewDeclaration(FieldDeclarationSyntax
8888
{
8989
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
9090

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

9595
FieldDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(leadingTrivia.UpsertLeadingTrivia(commentTrivia));

CodeDocumentor/Analyzers/Files/BaseCodeFixProvider.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Collections.Immutable;
3+
using System.Diagnostics;
34
using System.Threading.Tasks;
45
using CodeDocumentor.Vsix2022;
56
using Microsoft.CodeAnalysis;
@@ -31,11 +32,15 @@ public abstract class BaseCodeFixProvider : CodeFixProvider
3132
/// <returns> A Task. </returns>
3233
protected async Task RegisterFileCodeFixesAsync(CodeFixContext context, Diagnostic diagnostic)
3334
{
34-
if (Runtime.RunningUnitTests)
35-
{
36-
return;
37-
}
38-
35+
#if DEBUG
36+
//if (Runtime.RunningUnitTests)
37+
//{
38+
// Debug.WriteLine("!!!DISABLING FILE CODE FIX. EITHER TESTS ARE RUNNING OR DEBUGGER IS ATTACHED!!!");
39+
// return;
40+
//}
41+
Debug.WriteLine("!!!DISABLING FILE CODE FIX. EITHER TESTS ARE RUNNING OR DEBUGGER IS ATTACHED!!!");
42+
return;
43+
#endif
3944
//build it up, but check for counts if anything actually needs to be shown
4045
var _nodesTempToReplace = new Dictionary<CSharpSyntaxNode, CSharpSyntaxNode>();
4146
Document tempDoc = context.Document;

CodeDocumentor/Analyzers/Properties/PropertyCodeFixProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace CodeDocumentor
1717
{
1818
/// <summary> The property code fix provider. </summary>
1919
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(PropertyCodeFixProvider)), Shared]
20-
public class PropertyCodeFixProvider : CodeFixProvider
20+
public class PropertyCodeFixProvider : BaseCodeFixProvider
2121
{
2222
/// <summary> Gets the fixable diagnostic ids. </summary>
2323
public override sealed ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(PropertyAnalyzerSettings.DiagnosticId);
@@ -53,6 +53,8 @@ public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
5353
createChangedDocument: c => AddDocumentationHeaderAsync(context.Document, root, declaration, c),
5454
equivalenceKey: displayTitle),
5555
diagnostic);
56+
57+
await RegisterFileCodeFixesAsync(context, diagnostic);
5658
}
5759

5860
/// <summary> Builds the comments. This is only used in the file level fixProvider. </summary>

CodeDocumentor/CodeDocumentor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Analyzers\Classes\NonPublicClassAnalyzer.cs" />
9898
<Compile Include="Analyzers\Methods\NonPublicMethodAnalyzer.cs" />
9999
<Compile Include="Analyzers\Properties\NonPublicPropertyAnalyzer.cs" />
100+
<Compile Include="Models\XmlInformation.cs" />
100101
<Compile Include="Properties\AssemblyInfo.cs" />
101102
<Compile Include="Analyzers\Properties\PropertyAnalyzer.cs" />
102103
<Compile Include="Analyzers\Properties\PropertyAnalyzerSettings.cs" />

0 commit comments

Comments
 (0)