Code style and wrapping settings
I have this piece of code:
var promptTemplateResult = await promptTemplateService.GetByIdAsync(request.PromptTemplateId, cancellationToken);
which extends past my 120 char limit. When I let Rider auto format via Ctrl+Alt+Enter, it ends up looking like this:
var promptTemplateResult =
await promptTemplateService.GetByIdAsync(request.PromptTemplateId, cancellationToken);
I don't like how it's wrapping in the middle of an assignment and would prefer it wrap the arguments being passed to GetByIdAsync
like this:
var promptTemplateResult = await promptTemplateService.GetByIdAsync(
request.PromptTemplateId,
cancellationToken);
I've tried formatting the code as I'd like it to appear and then letting Rider detect the code style from that selection, but it says it already conforms to my configured code style even though Rider will not format it correctly.
I've been trying to figure this out on and off for 2 days now and I'm stuck. I've read countless Stack Overflow threads, I've asked LLMs, I've read over Rider/ReSharper's documentation, I've tried just ticking and unticking boxes at random in the C# Code Style settings, and for some reason just can't get Rider to format the code in my preferred style.
Any help would be very much appreciated. TIA!
Please sign in to leave a comment.
In Settings | Editor | Code Style | C#, have a try with the following settings to see if it works.
Unfortunately I already have that set and am still experiencing the issue.
I did some testing and I cannot reproduce this issue with other lines. But this specific line, even if placed in a different file, will break in the assignment instead of arguments and I have no idea why, it's so strange.
Okay, this must just be a bug or something wacky in that project. In another project (completely different solution, unrelated to the originally mentioned codebase), I have a line that's very similar. I added some “A”s to make it hit the 120 char mark:
This one wraps correctly!
I'm really at a loss now lol. I can format the original one by hand, but it's more personal at this point, I just want to know why it's behaving differently for the one line. I've even tried rewriting the original line to see if it just needed a refresh or something.
I've also tried deleting
.idea
andProject.sln.DotSettings.user
.Andrew Krieg Have a try to reset the project index in File | Invalidate Cache. Just reviewed the thread, and it looks like you haven't tried that yet.
I have the exact same issue. My eyes are bleeding, and the monk ín me is raging.
Andrew Krieg Have exact same settings — no luck. But after a good old binary search-style debugging session (commenting out half of
.editorconfig
again and again), I found the culprit:csharp_preserve_single_line_blocks = true
which let to this behaviour. EVIL. Just remove it, or turn it tofalse
.Thank me later. :>