{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/5358","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/5358/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/5358/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/5358/events","html_url":"https://github.com/dotnet/roslyn/issues/5358","id":107399590,"number":5358,"title":"Weird Formatter behaviour when formatting multidimensional arrays","user":{"login":"HellBrick","id":3703722,"avatar_url":"https://avatars.githubusercontent.com/u/3703722?v=3","gravatar_id":"","url":"https://api.github.com/users/HellBrick","html_url":"https://github.com/HellBrick","followers_url":"https://api.github.com/users/HellBrick/followers","following_url":"https://api.github.com/users/HellBrick/following{/other_user}","gists_url":"https://api.github.com/users/HellBrick/gists{/gist_id}","starred_url":"https://api.github.com/users/HellBrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HellBrick/subscriptions","organizations_url":"https://api.github.com/users/HellBrick/orgs","repos_url":"https://api.github.com/users/HellBrick/repos","events_url":"https://api.github.com/users/HellBrick/events{/privacy}","received_events_url":"https://api.github.com/users/HellBrick/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-IDE","name":"Area-IDE","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-20T15:56:54Z","updated_at":"2015-09-21T16:17:02Z","closed_at":null,"body":"Let's jump right to the code:\r\n```csharp\r\nprivate void FormatterWeirdnessExample()\r\n{\r\n\tAdhocWorkspace workspace = new AdhocWorkspace();\r\n\tworkspace.Options = workspace.Options\r\n\t\t.WithChangedOption( CSharpFormattingOptions.SpaceAfterComma, true )\r\n\t\t.WithChangedOption( CSharpFormattingOptions.SpaceBetweenEmptySquareBrackets, false )\r\n\t\t.WithChangedOption( CSharpFormattingOptions.SpaceWithinSquareBrackets, true );\r\n\r\n\tSyntaxTree tree = CSharpSyntaxTree.ParseText( \"int[ , ] array = new int[ 1, 1 ];\" );\r\n\tSyntaxNode root = tree.GetRoot();\r\n\tDebug.WriteLine( root );\r\n\r\n\tIList<TextChange> changes = Formatter.GetFormattedTextChanges( root, workspace );\r\n\tforeach ( var change in changes )\r\n\t\tDebug.WriteLine( change );\r\n\r\n\tSyntaxNode formatted = Formatter.Format( root, workspace );\r\n\tDebug.WriteLine( formatted );\r\n}\r\n```\r\n\r\nAnd here's the output:\r\n```\r\nint[ , ] array = new int[ 1, 1 ];\r\nTextChange: { [4..5), \"\" }\r\nTextChange: { [6..7), \"\" }\r\nTextChange: { [7..7), \" \" }\r\nint[, ] array = new int[ 1, 1 ];\r\n```\r\n\r\nFirst of all, the result of `Formatter.Format` looks kind of strange. I expected to get either the spaces both before and after the comma (`int[ , ]`) or no spaces around the comma at all (`int[,]`), but getting just the space after looks unexpected (and probably a bit ugly).\r\n\r\nSecond, the contradicting changes (`TextChange: { [6..7), \"\" }` and `TextChange: { [7..7), \" \" }`) are very confusing. That's actually how I stumbled upon this issue: I was writing an analyzer that checks if the document violates the formatting rules, so I used `GetFormattedTextChanges()` to detect the possible formatting changes. But apparently it's possible for the text changes to negate each other so the `Format()` method doesn't actually change anything. I don't know if it's a bug or a feature, but it definitely makes using `GetFormattedTextChanges()` a lot more difficult."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/142031838","html_url":"https://github.com/dotnet/roslyn/issues/5358#issuecomment-142031838","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/5358","id":142031838,"user":{"login":"Pilchie","id":312835,"avatar_url":"https://avatars.githubusercontent.com/u/312835?v=3","gravatar_id":"","url":"https://api.github.com/users/Pilchie","html_url":"https://github.com/Pilchie","followers_url":"https://api.github.com/users/Pilchie/followers","following_url":"https://api.github.com/users/Pilchie/following{/other_user}","gists_url":"https://api.github.com/users/Pilchie/gists{/gist_id}","starred_url":"https://api.github.com/users/Pilchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pilchie/subscriptions","organizations_url":"https://api.github.com/users/Pilchie/orgs","repos_url":"https://api.github.com/users/Pilchie/repos","events_url":"https://api.github.com/users/Pilchie/events{/privacy}","received_events_url":"https://api.github.com/users/Pilchie/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T16:17:02Z","updated_at":"2015-09-21T16:17:02Z","body":"We should just look at what VS2013 does for the various combinations of these options."}}