Skip to content

Conversation

@calledude
Copy link
Contributor

Affects:

  • DiscordWebhookSink
  • Code pasting
  • IL decompiling
  • REPL responses
  • Popularity contest (no idea what this is)

The (now removed) formatting logic was inherently flawed, so I decided to remove it altogether
The "short" run-down of why the current logic didn't work was the fact that it used the first line with whitespace in it, and then the last whitespace on that line. It then went on to nuke that amount of whitespace from each and every subsequent line, failing to remove whitespace if it had less than that
So in examples like this

// Some cool comment
void MyThing()
{
    Console.WriteLine("hello");
    DoSomeMoreStuff();
}

It would pick the first whitespace from the comment, the start being before "Some" and the end being between "cool" and "comment" (11 characters of whitespace), completely ignoring that there might not have been whitespace inbetween those occurences of whitespace in the first place.
Now, if we remove the comment altogether, we end up with the next line with whitespace as the Console.WriteLine line, this has 4 spaces. This leads to the whitespace being removed entirely for both Console.WriteLine and the subsequent line.
Ergo inconsistent indentation depending on how you wrote the code.

The idea here is that we can't possibly deal with all of the edge-cases if we were to roll our own code-formatting, so we either
a) Don't deal with it at all, and present the code back to the user exactly as they wrote it
b) Introduce opinionated formatting wherever we want to, i.e. via roslyn

Fixes #975

@Scott-Caldwell Scott-Caldwell added the bug Defective functionality or otherwise unwanted behaviour. label Jul 3, 2023
@calledude calledude force-pushed the remove-code-formatting branch from 066fc37 to 97bc5f8 Compare July 4, 2023 18:35
@Scott-Caldwell Scott-Caldwell merged commit 4f4ca80 into discord-csharp:main Jul 4, 2023
@calledude calledude deleted the remove-code-formatting branch March 26, 2024 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Defective functionality or otherwise unwanted behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repl strips indentation from code !eval removes indentation when displaying code in the result embed

2 participants