JetBrains / JetBrains.Annotations

Annotations to increase the accuracy of JetBrains ReSharper/Rider code inspections
https://www.jetbrains.com/help/resharper/Code_Analysis__Code_Annotations.html
MIT License
34 stars 18 forks source link

Support Source-based File Templates #8

Open khalidabuhakmeh opened 2 years ago

khalidabuhakmeh commented 2 years ago

Similar to Source Templates, it would be nice to be able to ship File Templates inside of source code projects and NuGet Packages. This would help OSS projects ship boilerplate code and light-up experiences inside of ReSharper and Rider.

I'm still not sure 100% how to define variables, but an array of comma delimited values might work. Here's an example of a file template defined in code.

using JetBrains.Annotations;

public static class MySourceTemplates
{
    [FileTemplate(
        DefaultFileName="ClassTests.cs",
        Description = "Tests for $CLASS$", 
        Reformat=true, 
        ShortenQualifyingReferences=true, 
        Availability=new [] { "C# Projects", "F# Projects" }, 
        AddToNewMenu=true,
        Variables = new []
        {
            // Name, Macro, Editable (default false) 
            "HEADER,FileHeader",
            "CLASS,Current File Name,true",
            "NAMESPACE,"
        })]
    public static void xunit_test()
    {
        /* 
   $HEADER$namespace $NAMESPACE$
   {
     public class $CLASS$_TESTS {$END$}
   }
       */
    }
}