-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Diagnosticsfeature-request
Milestone
Description
Background and motivation
VS provides nice colorization of regular expressions when passed to known methods on Regex, e.g.

It also supports putting a comment before any string to mark the language being used in that string:

But there's currently no way to define an arbitrary API and annotate a string parameter as to what language is expected, e.g. you don't get this colorization today for RegexGenerator, because VS hasn't been taught about this API specifically:

While these examples are about regex, more generally this applies to arbitrary domain-specific languages. If VS adds colorization for JSON, for example, it'd be nice if every API that accepts JSON could be annotated appropriately.
API Proposal
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class StringLanguageAttribute : Attribute
{
public StringLanguageAttribute(string language);
public string Language { get; }
}
}API Usage
public sealed class RegexGeneratorAttribute : Attribute
{
public RegexGeneratorAttribute([StringLanguage("regex")] string pattern);
}Alternative Designs
No response
Risks
No response
svick, teo-tsirpanis, Sergio0694, CyrusNajmabadi, omariom and 19 morejoperezr, TwentyFourMinutes, ufcpp, huoyaoyuan, Mrxx99 and 2 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Diagnosticsfeature-request