Skip to content

Add per-file overrides for casing options #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/TypeScriptDefinitionGenerator/Generator/IntellisenseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,44 @@ internal static IEnumerable<IntellisenseObject> ProcessFile(ProjectItem item, Ha
if (underProcess == null)
underProcess = new HashSet<CodeClass>();

Options.CamelCaseEnumerationValuesOverride = null;
Options.CamelCasePropertyNamesOverride = null;
Options.CamelCaseTypeNamesOverride = null;

foreach (CodeElement element in item.FileCodeModel.CodeElements)
{
if (element.Kind == vsCMElement.vsCMElementNamespace)
{
CodeNamespace cn = (CodeNamespace)element;
var summary = GetSummary(cn);
if (summary != null) {
var match = Regex.Match(summary, ".*CamelCaseEnumerationValuesOverride:\\s*(?<Value>(true)|(false))", RegexOptions.IgnoreCase);
if (match.Success)
{
if (bool.TryParse(match.Groups["Value"].Value, out bool value))
{
Options.CamelCaseEnumerationValuesOverride = value;
}
}

match = Regex.Match(summary, ".*CamelCasePropertyNamesOverride:\\s*(?<Value>(true)|(false))", RegexOptions.IgnoreCase);
if (match.Success)
{
if (bool.TryParse(match.Groups["Value"].Value, out bool value))
{
Options.CamelCasePropertyNamesOverride = value;
}
}

match = Regex.Match(summary, ".*CamelCaseTypeNamesOverride:\\s*(?<Value>(true)|(false))", RegexOptions.IgnoreCase);
if (match.Success)
{
if (bool.TryParse(match.Groups["Value"].Value, out bool value))
{
Options.CamelCaseTypeNamesOverride = value;
}
}
}

foreach (CodeElement member in cn.Members)
{
Expand Down Expand Up @@ -427,6 +460,8 @@ private static string GetName(CodeProperty property)
}

// External items throw an exception from the DocComment getter
private static string GetSummary(CodeNamespace property) { return property.InfoLocation != vsCMInfoLocation.vsCMInfoLocationProject ? null : GetSummary(property.InfoLocation, property.DocComment, property.Comment, property.FullName); }

private static string GetSummary(CodeProperty property) { return property.InfoLocation != vsCMInfoLocation.vsCMInfoLocationProject ? null : GetSummary(property.InfoLocation, property.DocComment, property.Comment, property.FullName); }

private static string GetSummary(CodeClass property) { return GetSummary(property.InfoLocation, property.DocComment, property.Comment, property.FullName); }
Expand Down
9 changes: 6 additions & 3 deletions src/TypeScriptDefinitionGenerator/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ public class Options
private const string OVERRIDE_FILE_NAME = "tsdefgen.json";

private static OptionsOverride overrides { get; set; } = null;
internal static bool? CamelCaseEnumerationValuesOverride { private get; set; } = null;
internal static bool? CamelCasePropertyNamesOverride { private get; set; } = null;
internal static bool? CamelCaseTypeNamesOverride { private get; set; } = null;

public static bool CamelCaseEnumerationValues => overrides?.CamelCaseEnumerationValues ?? DtsPackage.Options.CamelCaseEnumerationValues;
public static bool CamelCaseEnumerationValues => CamelCaseEnumerationValuesOverride ?? overrides?.CamelCaseEnumerationValues ?? DtsPackage.Options.CamelCaseEnumerationValues;

public static bool CamelCasePropertyNames => overrides?.CamelCasePropertyNames ?? DtsPackage.Options.CamelCasePropertyNames;
public static bool CamelCasePropertyNames => CamelCasePropertyNamesOverride ?? overrides?.CamelCasePropertyNames ?? DtsPackage.Options.CamelCasePropertyNames;

public static bool CamelCaseTypeNames => overrides?.CamelCaseTypeNames ?? DtsPackage.Options.CamelCaseTypeNames;
public static bool CamelCaseTypeNames => CamelCaseTypeNamesOverride ?? overrides?.CamelCaseTypeNames ?? DtsPackage.Options.CamelCaseTypeNames;

public static string DefaultModuleName => overrides?.DefaultModuleName ?? DtsPackage.Options.DefaultModuleName;

Expand Down