Skip to content

Commit

Permalink
Support custom prefix and suffix for "Add TODO Comment"
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Sep 28, 2021
1 parent d9aca70 commit dfe778b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
27 changes: 25 additions & 2 deletions src/Menees.VsTools/CommentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,35 @@ public static void AddToDoComment(DTE dte)
sb.Append(' ');
}

sb.Append("TODO: ");
Tasks.Options options = MainPackage.TaskOptions;
sb.Append(options.AddTodoPrefix);

int noteStartIndex = sb.Length;
string memberName = GetMemberName(handler, language);
sb.Append("Finish ").Append(memberName ?? "implementation").Append('.');
int noteLength = sb.Length - noteStartIndex;
sb.Append(" [").Append(Environment.UserName).Append(", ").Append(DateTime.UtcNow.ToLocalTime().ToShortDateString()).Append(']');

if (options.AddTodoSuffix != TodoSuffix.None)
{
sb.Append(" [");
switch (options.AddTodoSuffix)
{
case TodoSuffix.User:
sb.Append(Environment.UserName);
break;

case TodoSuffix.UserDate:
sb.Append(Environment.UserName).Append(", ");
goto case TodoSuffix.Date;

case TodoSuffix.Date:
sb.Append(DateTime.UtcNow.ToLocalTime().ToShortDateString());
break;
}

sb.Append(']');
}

if (!string.IsNullOrEmpty(endDelimiter))
{
sb.Append(' ').Append(endDelimiter);
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.VsTools/MainPackage.Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed partial class MainPackage
//
// Note: When the version changes (major, minor, build, or revision), also update:
// - source.extension.vsixmanifest: <Identity Version="*"/>
internal const string Version = VersionYear + ".0.17";
internal const string Version = VersionYear + ".0.18";

internal const string Title = "Menees VS Tools";

Expand Down
14 changes: 13 additions & 1 deletion src/Menees.VsTools/Tasks/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ namespace Menees.VsTools.Tasks

#endregion

#region Public TodoSuffix

public enum TodoSuffix
{
None,
Date,
User,
UserDate,
}

#endregion

#region Internal HierarchyItemType

internal enum HierarchyItemType
Expand All @@ -21,7 +33,7 @@ internal enum HierarchyItemType

#endregion

#region internal RefreshAction
#region Internal RefreshAction

internal enum RefreshAction
{
Expand Down
45 changes: 42 additions & 3 deletions src/Menees.VsTools/Tasks/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// Note: The MainPackage has a ProvideOptionPage attribute that associates this class with that package.
[Guid(Guids.TaskOptionsString)]
[DefaultProperty(nameof(EnableCommentScans))] // Make this get focus in the PropertyGrid first since its category is alphabetically first.
[DefaultProperty(nameof(AddTodoPrefix))] // Make this get focus in the PropertyGrid first since its category is alphabetically first.
[SuppressMessage("Internal class never created.", "CA1812", Justification = "Created via reflection by VS.")]
internal sealed class Options : OptionsBase
{
Expand All @@ -30,6 +30,8 @@ internal sealed class Options : OptionsBase
@"jquery-\d+\.\d+\.\d+(-vsdoc)?\.js$";

private const string DefaultExcludeProjectsPatterns = @".+\.(sql|vc|vcx)proj$";
private const string DefaultTodoPrefix = "TODO: ";
private const TodoSuffix DefaultTodoSuffix = TodoSuffix.UserDate;

private const int MinParallelism = 1;
private const int MaxParallelism = 8;
Expand All @@ -41,6 +43,7 @@ internal sealed class Options : OptionsBase
private string excludeFileComments;
private string excludeCommentsPatterns;
private int? requestedMaxDegreeOfParallelism;
private string todoPrefix;

#endregion

Expand All @@ -53,19 +56,21 @@ public Options()
this.ExcludeProjectsPatterns = DefaultExcludeProjectsPatterns;
this.ExcludeFileComments = null;
this.ExcludeCommentsPatterns = null;
this.AddTodoPrefix = DefaultTodoPrefix;
this.AddTodoSuffix = DefaultTodoSuffix;
}

#endregion

#region Public Browsable Properties (for Options page)

[Category("Common")]
[Category("Scan")]
[DisplayName("Enable task scanning (requires restart)")]
[Description("Whether open documents and files referenced by the current solution should be scanned for task comments.")]
[DefaultValue(false)] // Off by default since it can have a serious CPU impact on large solutions.
public bool EnableCommentScans { get; set; }

[Category("Common")]
[Category("Scan")]
[DisplayName("Max degree of parallelism")]
[Description("The maximum number of concurrent file scans to perform. If blank, then "
+ ProcessorScaleFactorPercent + " of your logical CPU count will be used.")]
Expand Down Expand Up @@ -171,6 +176,40 @@ public string ExcludeCommentsPatterns
}
}

[Category("Add")]
[DisplayName("Comment prefix")]
[Description("The prefix that the \"Add TODO Comment\" command should add to each comment.")]
[DefaultValue(DefaultTodoPrefix)]
public string AddTodoPrefix
{
get
{
return this.todoPrefix;
}

set
{
if (string.IsNullOrWhiteSpace(value))
{
this.todoPrefix = DefaultTodoPrefix;
}
else
{
this.todoPrefix = value;
if (!char.IsWhiteSpace(this.todoPrefix[this.todoPrefix.Length - 1]))
{
this.todoPrefix += ' ';
}
}
}
}

[Category("Add")]
[DisplayName("Comment suffix")]
[Description("The suffix that the \"Add TODO Comment\" command should add to each comment.")]
[DefaultValue(DefaultTodoSuffix)]
public TodoSuffix AddTodoSuffix { get; set; }

#endregion

#region Public Non-Browsable Properties (for other state persistence)
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.VsTools/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Menees VS Tools 2019" Version="2019.0.17" Language="en-US" Publisher="Bill Menees" />
<Identity Id="Menees VS Tools 2019" Version="2019.0.18" Language="en-US" Publisher="Bill Menees" />
<DisplayName>Menees VS Tools 2019</DisplayName>
<Description xml:space="preserve">Provides several new commands such as Sort Lines, Sort Members, Trim, Statistics, ExecuteFile, AddRegion, CollapseAllRegions, ExpandAllRegions, and ToggleFiles.

Expand Down

0 comments on commit dfe778b

Please sign in to comment.