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

Ignore leading whitespace before md comments #16

Closed
MarkEwer opened this issue Dec 17, 2024 · 9 comments
Closed

Ignore leading whitespace before md comments #16

MarkEwer opened this issue Dec 17, 2024 · 9 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@MarkEwer
Copy link

Situation:

When adding markdown comments to unit tests I am adding markdown comments between each of the tests to add documentation context to the output file. If I then use the automatic source code formatter in Visual Studio, it will indent the lines that have markdown comments, and this parser then fails to recognize the line's intention.

Suggestion:

When attempting to parse each line looking for markdown control comments, we should trim any initial whitespace from the line. Considering that whitespace to be non-significant would mean the automatic code formatting features could work as normal.

Example:

Here is a sample unit test that successfully generates a markdown output for documentation. Notice that all of the markdown comments are at the left margin.

     namespace MyDomain.Identifiers
     {
       public class TestPersonId
       {
     //md ```
     //md}
     //md 
     //md ## If two identifiers have different GUID values, then they should not be equal.
     //md ```csharp
         [Fact]
         public void ShouldReturnFalseWhenComparingTwoDifferentGUIDs()
         {
           // Arrange
           var guidId1 = new PersonId(Guid.NewGuid());
           var guidId2 = new PersonId(Guid.NewGuid());

           // Act
           var result = guidId1.Equals(guidId2.Value);

           // Assert
           Assert.False(result);
         }
     //md ```
     //md{ Closing Braces
     //md ```csharp
       }
     }
     //md ```
     //md}

The problem arises when you press CTRL+K,D in Visual Studio to trigger the automatic code formatting. When this happens, it assumes that all comments should be indented to the same level as the source code it is mixed into. Indention of these comments means that the CsToMd parser does not recognize them.

     namespace MyDomain.Identifiers
     {
       public class TestPersonId
       {
         //md ```
         //md}
         //md 
         //md ## If two identifiers have different GUID values, then they should not be equal.
         //md ```csharp
         [Fact]
         public void ShouldReturnFalseWhenComparingTwoDifferentGUIDs()
         {
           // Arrange
           var guidId1 = new PersonId(Guid.NewGuid());
           var guidId2 = new PersonId(Guid.NewGuid());

           // Act
           var result = guidId1.Equals(guidId2.Value);

           // Assert
           Assert.False(result);
         }
         //md ```
         //md{ Closing Braces
         //md ```csharp
       }
     }
     //md ```
     //md}
@dadhi
Copy link
Owner

dadhi commented Dec 18, 2024

Ok, great suggestion. Taking it in the works.

@dadhi dadhi self-assigned this Dec 18, 2024
@dadhi dadhi added the enhancement New feature or request label Dec 18, 2024
@dadhi dadhi added this to the v1.3.0 milestone Dec 18, 2024
@MarkEwer
Copy link
Author

I started to fix this for you and drop a PR but I ran into an issue where I can't compile locally because of this error:

error MSB4062: The "CompareBuildTaskVersion" task could not be loaded from the assembly C:\GitHub\dadhi-CsToMd\packages\Microsoft.VSSDK.BuildTools.16.5.5\tools\VSSDK\Microsoft.VisualStudio.Sdk.BuildTasks.16.0.dll

I think this means I don't have the same version of the SDK that you are using. Can you tell me what versions I need installed locally to compile this extension?

@dadhi
Copy link
Owner

dadhi commented Dec 18, 2024

Looking...

@dadhi
Copy link
Owner

dadhi commented Dec 26, 2024

@MarkEwer Are you using dotnet CLI tool or the VSIX extension?

@MarkEwer
Copy link
Author

I prefer the integrated compiler, but neither are working for me. I'm sure that I am doing something wrong. What version of VS and what version of the VS-SDK are you using?

@dadhi
Copy link
Owner

dadhi commented Dec 26, 2024

Ok. Strange. Checking...

@MarkEwer
Copy link
Author

if you just open the help->about page and tell me what version number of VS and the SDK you are using I can get the same ones and it should fix my issue.

@dadhi
Copy link
Owner

dadhi commented Jan 7, 2025

@MarkEwer I am using the CsToMd as a CLI tool in VSCode. I have installed the VS Community and checking what's happenning there.

@dadhi
Copy link
Owner

dadhi commented Jan 7, 2025

@MarkEwer I have updated the solution and the VSIX extension to the VS 2022+.
I will implement your suggestions later and will release the new versions of VSIX and CLI tool.

@dadhi dadhi changed the title Suggestion: Ignore whitespace at beginning of line when //md is used Ignore leading whitespace before md comments Jan 8, 2025
@dadhi dadhi closed this as completed in c229f1c Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants