Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #30

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CodeDocumentor.Test/CodeDocumentor.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<Compile Remove="Methods\TestFiles\MethodWithBooleanParameterTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithCrefTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithCrefTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithExceptionTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithExceptionTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithInlineExceptionTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithInlineExceptionTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithIntReturnTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithIntReturnTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithListIntReturnTestCode.cs" />
Expand All @@ -39,6 +43,8 @@
<Compile Remove="Methods\TestFiles\MethodWithListListIntReturnTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithListQualifiedNameReturnTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithListQualifiedNameReturnTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithMixedExceptionTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithMIxedExceptionTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithNullableStructParameterTestCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithNullableStructParameterTestFixCode.cs" />
<Compile Remove="Methods\TestFiles\MethodWithObjectReturnTestCode.cs" />
Expand Down Expand Up @@ -67,6 +73,24 @@
<Content Include="Methods\TestFiles\InheritDocTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithMixedExceptionTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithInlineExceptionTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithExceptionTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithMixedExceptionTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithInlineExceptionTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Methods\TestFiles\MethodWithExceptionTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion CodeDocumentor.Test/Methods/MethodUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using CodeDocumentor.Test.TestHelpers;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -73,6 +73,9 @@ public async Task NoDiagnosticsShow(string testCode)
[InlineData("MethodWithListListIntReturnTestCode", "MethodWithListListIntReturnTestFixCode", 9, 32)]
[InlineData("MethodWithListQualifiedNameReturnTestCode", "MethodWithListQualifiedNameReturnTestFixCode", 9, 26)]
[InlineData("MethodWithCrefTestCode", "MethodWithCrefTestFixCode", 10, 35)]
[InlineData("MethodWithExceptionTestCode", "MethodWithExceptionTestFixCode", 9, 23)]
[InlineData("MethodWithInlineExceptionTestCode", "MethodWithInlineExceptionTestFixCode", 9, 23)]
[InlineData("MethodWithMixedExceptionTestCode", "MethodWithMixedExceptionTestFixCode", 9, 23)]
public async Task ShowMethodDiagnosticAndFix(string testCode, string fixCode, int line, int column)
{
var fix = _fixture.LoadTestFile($"./Methods/TestFiles/{fixCode}.cs");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
public string ShowMethodWithStringReturnTester()
{
throw new ArgumentNullException("test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
/// <summary>
/// Show method with string return tester.
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
/// <returns>string</returns>
public string ShowMethodWithStringReturnTester()
{
throw new ArgumentNullException("test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
public string ShowMethodWithStringReturnTester()
{
ArgumentNullException.ThrowIfNull("test", "test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
/// <summary>
/// Show method with string return tester.
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
/// <returns>string</returns>
public string ShowMethodWithStringReturnTester()
{
ArgumentNullException.ThrowIfNull("test", "test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
public string ShowMethodWithStringReturnTester()
{
ArgumentNullException.ThrowIfNull("test", "test");
ArgumentException.ThrowIfNullOrEmpty("test", "test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
{
public class MethodTester
{
/// <summary>
/// Show method with string return tester.
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
/// <returns>string</returns>
public string ShowMethodWithStringReturnTester()
{
ArgumentNullException.ThrowIfNull("test", "test");
ArgumentException.ThrowIfNullOrEmpty("test", "test");
}
}
}
31 changes: 19 additions & 12 deletions CodeDocumentor/Helper/DocumentationHeaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using CodeDocumentor.Vsix2022;
using EnvDTE;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.VisualStudio.OLE.Interop;
using SimpleInjector.Diagnostics;

namespace CodeDocumentor.Helper
{
Expand All @@ -34,6 +30,14 @@ public static class DocumentationHeaderHelper
/// <summary> The summary. </summary>
public const string SUMMARY = "summary";

/// <summary> The reg ex. </summary>
private static readonly Regex _regEx = new Regex(@"throw\s+new\s+\w+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

private static readonly Regex _regExInline = new Regex(@"(\w+Exception)\.Throw\w+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

/// <summary> type param regex. </summary>
private static readonly Regex _typeParamRegex = new Regex(@"""\w+""");

/// <summary> Creates the exception nodes. </summary>
/// <param name="exceptionType"> The exception type. </param>
/// <returns> An array of XmlNodeSyntaxes </returns>
Expand Down Expand Up @@ -559,14 +563,23 @@ internal static SyntaxTriviaList UpsertLeadingTrivia(this SyntaxTriviaList leadi
/// <returns> <![CDATA[IEnumerable<string>]]> </returns>
internal static IEnumerable<string> GetExceptions(string textToSearch)
{

if (string.IsNullOrEmpty(textToSearch))
{
return Enumerable.Empty<string>();
}



var exceptions = _regEx.Matches(textToSearch).OfType<Match>()
.Select(m => m?.Groups[0]?.Value)
.Distinct();
return exceptions;
.ToList();
System.Diagnostics.Debugger.Break();

var exceptionsInline = _regExInline.Matches(textToSearch).OfType<Match>()
.Select(m => m?.Groups.Count == 1 ? m?.Groups[0]?.Value : m?.Groups[1]?.Value).ToArray();
exceptions.AddRange(exceptionsInline);
return exceptions.Distinct();
}

/// <summary> Withs the exception types. </summary>
Expand Down Expand Up @@ -722,12 +735,6 @@ internal static SyntaxList<XmlNodeSyntax> WithTypeParamters(this SyntaxList<XmlN

#endregion Builders

/// <summary> The reg ex. </summary>
private static readonly Regex _regEx = new Regex(@"throw\s+new\s+\w+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

/// <summary> type param regex. </summary>
private static readonly Regex _typeParamRegex = new Regex(@"""\w+""");

/// <summary> Creates the comment exterior. </summary>
/// <returns> A SyntaxTriviaList. </returns>
private static SyntaxTriviaList CreateCommentExterior()
Expand Down
2 changes: 1 addition & 1 deletion Manifests/vs2022/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="CodeDocumentor.2022.88F29096-CA4C-4F88-A260-705D8BBFCF2A" Version="2.0.0.0" Language="en-US" Publisher="Dan Turco"/>
<Identity Id="CodeDocumentor.2022.88F29096-CA4C-4F88-A260-705D8BBFCF2A" Version="2.0.1.0" Language="en-US" Publisher="Dan Turco"/>
<DisplayName>CodeDocumentor</DisplayName>
<Description xml:space="preserve">An Extension to generate XML documentation automatically using IntelliSense for interface,class,enum, field, constructor, property and method.</Description>
<Icon>logo.png</Icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -28,9 +28,6 @@ public class TestTypes<T>

}

/// <summary>
/// The inhertit test types.
/// </summary>
public class InhertitTestTypes : TestTypes<int>
{

Expand Down Expand Up @@ -86,6 +83,17 @@ internal string WorkWithTypes<TEntity>(string test, string we)
return "";
}

internal string WorkWithTypesWithException(string test, string we)
{
throw new ArgumentException("");
}

internal string WorkWithTypesWithInlineException(string test, string we)
{
ArgumentException.ThrowIfNullOrEmpty(test, nameof(test));
ArgumentNullException.ThrowIfNull(we, nameof(we));
return "";
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion _git2_a15776

This file was deleted.

Loading