Home > Back-end >  Where's the documentation for "Enable All JSON editor features" for Visual Studio, wh
Where's the documentation for "Enable All JSON editor features" for Visual Studio, wh

Time:01-29

When editing a string in Visual Studio there's an option called Enable All JSON editor features, which adds a comment to the data. Screenshot of the Quick Actions

The comment looks like this:

/*lang=json,strict*/

It pops up only if the string in C# code contains serialized JSON. I wasn't able to find any documentation online for it. Is it some hidden feature? Are other languages (SQL/YAML/JavaScript) supported in strings in a similar fashion?

CodePudding user response:

I only know that lang=regex is also supported.

However, in .NET7 for:

  • better handling of string literals and
  • adding a semantic meaning to strings

please see:

  1. Raw string literals:
    • No more \" escaping,
    • great leading spaces handling, and
    • great interpolation experience.

      From enter image description here

  2. StringSyntaxAttribute which allows you to mark parameters with their meaning which then becomes a clue to the editor. For example:
    var s = "...";
    ...
    void F([StringSyntax(StringSyntaxAttribute.DateTimeFormat)]string s)
    
    in an editor which supports it (e.g. Visual Studio 2022) would:
    • add hints as you type s (hints with yyyy, MM, etc.),
    • add errors if the string doesn't make sense (in my experience this works best with StringSyntaxAttribute.Json for now).

      As of Jan 2023 this feature is neither finished nor documented well. The best introduction I know is The .NET 7 feature that gives meaning to your Strings (video, ~7mins).
  • Related