Have a CU which contains code like below and from the whole node format that range. Observe that you don't get formatting results.
sourceText = sourceText.WithChanges(new[] {
new TextChange( new TextSpan(startOffset, endOffset - startOffset), request.NewText)
});
From: https://github.com/OmniSharp/omnisharp-roslyn/issues/75
@basoundr Can you take a look? @jrieken Can you elaborate on what you mean? Maybe post a complete Roslyn Console application that demonstrates the issue?
@Pilchie - sorry, the formatting is off. The code looks like shown here (https://github.com/OmniSharp/omnisharp-roslyn/issues/75#issue-57596743) and I expect the formatter to remove the unnecessary whitespace.
sourceText = sourceText.WithChanges(new[] {
new TextChange( new TextSpan(startOffset, endOffset - startOffset), request.NewText)
});
should become something like this
sourceText = sourceText.WithChanges(new[] {
new TextChange(new TextSpan(startOffset, endOffset - startOffset), request.NewText)
});
@jrieken @Pilchie Formatting inside Array Initializers is treated special. Array Initializers are usually custom formatted by the user. For Eg:
int[] matrix = new[] {
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15};
Another Example is,
Customer customers = new Customer[](new[] {
//LastName //FirstName
new Customer( "A", "B"),
new Customer( "BiggerName", "BiggerName"),
new Customer( "VeryLongLongName", "VeryLongLongName")
});
Hence we have the current behavior which is to preserve the user preferred format and not disturb it.
This is related to #1376.
The issue #1376 talks about introducing a pragma for not formatting. If we do end up having a pragma(or something similar) then we have a region which either will be formatted or not formatted
This issue is a special case where we treat the array and collection initializers different and do not format. If the users still wants to format inside of the array and collection initializer then introducing an option to _format inside initializer _would be a good idea(default value: false. So we dont break other existing users)
@basoundr +1 for having a flag to not break other customers, but I would really love the option to have my collection initializers formatted.
Agree with @RemyArmstro
Duplicate of #8269
Most helpful comment
@basoundr +1 for having a flag to not break other customers, but I would really love the option to have my collection initializers formatted.