[llvm-bugs] [Bug 43100] New: clang-format C# spaceRequiredBettween does not add a space between "using(FileStream ..."

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 23 05:07:18 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43100

            Bug ID: 43100
           Summary: clang-format C# spaceRequiredBettween does not add a
                    space between "using(FileStream ..."
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mydeveloperday at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

(see Rational)

No Space is left between "using" and ( when clang-formatting  (Irrespective of

Before
---------------------
            using (FileStream fs = new FileStream(path, FileMode.Open,
FileAccess.Read, FileShare.Read, bufferSize : 1))
            {
---------------------

After
---------------------                
            using(FileStream fs = new FileStream(path, FileMode.Open,
FileAccess.Read, FileShare.Read, bufferSize : 1))
               ^^^^^
            {
---------------------


wget -O File.cs
https://raw.githubusercontent.com/dotnet/corefx/master/src/Common/src/CoreLib/Internal/IO/File.cs
clang-format -i File.cs

--------- code to fix (something like) ------------------

diff --git a/clang/lib/Format/TokenAnnotator.cpp
b/clang/lib/Format/TokenAnnotator.cpp
index c391c489dc2..74499442a6c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2614,6 +2614,9 @@ bool TokenAnnotator::spaceRequiredBetween(const
AnnotatedLine &Line,
     if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
         (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
       return true;
+    // using (FileStream fs...
+    if (Style.isCSharp() && Left.is(tok::kw_using))
+      return true;
     return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||


--------------------------------------

Rational:
---------
clang-format C# support needs some extra knowledge of C# syntax.

As a driver for this I'm taking .NET core project "corefx" and running
clang-format over the code and seeing how it varies from the original with the
out of box default CSharp .clang-format configuration of just

-- .clang-format -------------------
Language: CSharp
BasedOnStyle: Microsoft
------------------------------------

There are 2 goals here, determine the best default settings that can be added
to the getMicrosoftStyle() function, using the existing C# capabilities that
most closely matches either code which is part of the .NET Core and/or code
new-generated by VS "New C# project"

  if (Style.isCSharp()) {
    Style.NamespaceIndentation = FormatStyle::NI_All;
    Style.AccessModifierOffset = 4;
    Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
    Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
    Style.SpaceInEmptyBlock = true;
    Style.SpaceAfterCStyleCast = false;
  }

We may identify cases that are either missing for C# specifics (as in this
using case here), that may include adding some new styles to give finer
control.

The aim is to identify those changes that are required in clang-format to
ensure good C# code formatting with clang-format (without impacting the other
language usages (ObjC, C++ etc..)

MyDeveloperDay

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190823/cf4f91a2/attachment.html>


More information about the llvm-bugs mailing list