This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Special handling of spaces for C# code
ClosedPublic

Authored by jbcoe on Feb 25 2020, 9:45 AM.

Details

Summary

Ensure that there are spaces around braces '{', '}'.

Ensure that there is a space before and after '=>'.

Ensure that 'async' and 'when' are considered as keywords when inserting spaces.

Diff Detail

Event Timeline

jbcoe created this revision.Feb 25 2020, 9:45 AM

As a general comment, we should consider which of these special cases can already be simulated by a combination of existing style options:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
There are several Spaces* options there that can be used to independently control various spacing around parenthesis.

krasimir added inline comments.Feb 26 2020, 5:03 AM
clang/lib/Format/TokenAnnotator.cpp
2839

Move this to the already existing } else if (Style.isCSharp()) { on line 2902 below.

jbcoe planned changes to this revision.Feb 26 2020, 5:07 AM
jbcoe updated this revision to Diff 246688.Feb 26 2020, 5:59 AM
jbcoe edited the summary of this revision. (Show Details)

Treat async and when as keywords.

Consolidate C# space insertion logic.

jbcoe updated this revision to Diff 246689.Feb 26 2020, 6:04 AM
jbcoe marked an inline comment as done.

remove commented out code

krasimir accepted this revision.Feb 26 2020, 6:44 AM
krasimir added inline comments.
clang/unittests/Format/FormatTestCSharp.cpp
584

If these values for these options make sense for Google style in general, consider updating the getGoogleStyle default style with a C#-specific section here:
https://github.com/llvm/llvm-project/blob/master/clang/lib/Format/Format.cpp#L992
I'd recommend doing this in a separate patch based on top of this one.

This revision is now accepted and ready to land.Feb 26 2020, 6:44 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2020, 7:35 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript