Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback VS Code Support: Let user choose LangVersion instead of defaulting to "latest"

Discussion in 'Experimental Scripting Previews' started by Neonlyte, Nov 1, 2020.

  1. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    There isn't a dedicated forum for VSCode editor support, so I am posting here hoping that any Unity staff could see and point it to the right people.

    My feedback/feature request is to let the user choose what LangVersion is used in csproj file, so that VSCode C# extension could provide relevant information.

    The official C# extension of VSCode is way ahead of Unity in language feature support -- they already moved on to C# 9. Because of this, the latest version of C# LangVersion is now "9.0". However, the generated C# project by Unity specifies LangVersion as "latest" and thus VSCode C# defaults the language to 9.0 and suggesting code fixes in C# 9 that Unity's C# 8 compiler does not yet recognize. For example, pattern matching:
    Code (CSharp):
    1. // Original code:
    2. Notification notification = args.Context as Notification;
    3. if (notification == null)
    4.     return;
    5.  
    6. // LangVersion: latest
    7. // Code fix with C# 9 feature:
    8. if(args.Context is not Notification notification)
    9.     return;
    However, VSCode C# extension already supports different code fixes based on LangVersion. If I change manually LangVersion to "8.0" in csproj file:
    Code (csharp):
    1.  <PropertyGroup>
    2.     <LangVersion>8.0</LangVersion>
    3.   </PropertyGroup>
    The code fix becomes:
    Code (CSharp):
    1. // Older C# code fix:
    2. if(!(args.Context is Notification notification))
    3.      return;
    There could be other use cases for this new feature, say if someone wants to limit themselves to use a specific language version in order to maintain source compatibility with some other older Unity projects, like Asset Stores authors.
     
    elmarj and wilgieseler like this.
  2. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    This is definitely an issue for me also!
     
    Neonlyte likes this.
  3. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    I'm not sure, but I think Unity partially supports C# 9 features that don't need runtime support, but I can be mistaken and confused with C# 8, which will not be fully supported until 2021.2.
     
  4. elmarj

    elmarj

    Joined:
    Mar 16, 2019
    Posts:
    1
    Neonlyte likes this.