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

Issue Formatting Region #1197

Closed
davidescapolan01 opened this issue Mar 8, 2024 · 4 comments · Fixed by #1216
Closed

Issue Formatting Region #1197

davidescapolan01 opened this issue Mar 8, 2024 · 4 comments · Fixed by #1216
Milestone

Comments

@davidescapolan01
Copy link

Input:

I'm experiencing a strange issue where formatting a code with regions makes CSharpier throw an exception for stack empty.

How to Replicate:

  • generate a code where there are some regions
internal class TMessages : TEntity<int>
{
    #region Properties
    // csharpier-ignore-start
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public string sender { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public List<string> receivers { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public List<string>? copy_receivers { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public string date_reception { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public string subject { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public List<string>? attachment_s3_key { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public string? content { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public bool disabled { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public int message_type_id { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà")]
    public int connection_id { get; set; }
    // csharpier-ignore-end
    #endregion

    protected override string TableName => "public.messages";

    public override string GetTableName()
    {
        return TableName;
    }
}
  • run the format on the file

Output:

I get this output running the command line tool:

Error ./DataProvider/DBData/TMessages.cs - Threw exception while formatting.
  Stack empty.
     at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
     at System.Collections.Generic.Stack`1.Pop()
     at CSharpier.DocPrinter.DocPrinter.ProcessNextCommand() in /home/runner/work/csharpier/csharpier/Src/CSharpier/DocPrinter/DocPrinter.cs:line 159
     at CSharpier.DocPrinter.DocPrinter.Print() in /home/runner/work/csharpier/csharpier/Src/CSharpier/DocPrinter/DocPrinter.cs:line 40
     at CSharpier.DocPrinter.DocPrinter.Print(Doc document, PrinterOptions printerOptions, String endOfLine) in /home/runner/work/csharpier/csharpier/Src/CSharpier/DocPrinter/DocPrinter.cs:line 33
     at CSharpier.CSharpFormatter.FormatAsync(SyntaxTree syntaxTree, PrinterOptions printerOptions, SourceCodeKind sourceCodeKind, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier/CSharpFormatter.cs:line 130
     at CSharpier.Cli.CommandLineFormatter.PerformFormattingSteps(FileToFormatInfo fileToFormatInfo, IFormattedFileWriter formattedFileWriter, CommandLineFormatterResult commandLineFormatterResult, FileIssueLogger fileIssueLogger, PrinterOptions printerOptions, CommandLineOptions commandLineOptions, IFormattingCache formattingCache, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/CommandLineFormatter.cs:line 386

Formatted 1 files in 425ms.

and I get this output by running the tool from VisualStudio 2022

[Info - 08/03/2024 08:13:56] Formatting started for C:\Github\19300040-Argo365\01.Software\BusinessLogic\Argo\DataProvider\DBData\TMessages.cs.
[Debug - 08/03/2024 08:13:56] File is ignored by .csharpierignore or there was an error
[Info - 08/03/2024 08:13:56] Formatted in 26ms
[Debug - 08/03/2024 08:13:56] Skipping write because result is empty

Expected behavior:

Format the file as usual

Obviously removing the regions fixes this problem but in my team we use a lot the regions to navigate faster the code.

Hope the info I supplied is enough.

In case of need ask some more

@davidescapolan01
Copy link
Author

Found a solution

Apparently the issue was the // csharpier-ignore-start and the // csharpier-ignore-end

changing the code to this:

internal class TMessages : TEntity<int>
{
	#region Properties
	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public string sender { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public List<string> receivers { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public List<string>? copy_receivers { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public string date_reception { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public string subject { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public List<string>? attachment_s3_key { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public string? content { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public bool disabled { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public int message_type_id { get; set; }

	[System.Diagnostics.CodeAnalysis.SuppressMessage(
		"Style",
		"IDE1006:Naming Styles",
		Justification = "Naming necessario per l'interpolazione delle colonne a partire dalla proprietà"
	)]
	// csharpier-ignore
	public int connection_id { get; set; }
	#endregion


	protected override string TableName => "public.messages";

	public override string GetTableName()
	{
		return TableName;
	}
}

allows it to format.

I think that the start and end of ignore in combo with regions make it tink the file is among the .csharpierignore but I'm not sure

belav added a commit that referenced this issue Mar 24, 2024
@belav belav added this to the 0.28.0 milestone Mar 24, 2024
@belav
Copy link
Owner

belav commented Mar 24, 2024

This was a bug with assuming an ending region always had a starting region to use to determine how much it needed to be indented. In this case the starting region was included in the unformatted code, which is treated as just a string by the printer.

Thanks for reporting the bug!

@davidescapolan01
Copy link
Author

No problem.
I really like your software and we are starting to use it at work.
How can I help you? Maybe through some funding or something?
Do you have any link like buy me a coffee?

@belav
Copy link
Owner

belav commented Mar 28, 2024

I really like your software and we are starting to use it at work.

I got my team at work using it with a very early version, I can't image life without it at this point. So much time saved not thinking about formatting when reviewing PRs.

Do you have any link like buy me a coffee?

I do have a sponser link set up - https://github.com/sponsors/belav
I appreciate the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants