Skip to content

Commit

Permalink
update document generation
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Sep 9, 2024
1 parent c3b3965 commit bac0ee4
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 183 deletions.
57 changes: 57 additions & 0 deletions src/RepoM.ActionMenu.CodeGen/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace RepoM.ActionMenu.CodeGen;

using System.Collections.Generic;
using RepoM.ActionMenu.CodeGen.Models;

internal static class Constants
{
internal static readonly Dictionary<string, TypeInfoDescriptor> TypeInfos = new()
{
{
typeof(Interface.YamlModel.Templating.Text).FullName!,
new TypeInfoDescriptor(nameof(Text), typeof(Interface.YamlModel.Templating.Text).FullName!)
{
Link = "repository_action_types.md#text",
}
},
{
typeof(Interface.YamlModel.Templating.Predicate).FullName!,
new TypeInfoDescriptor(nameof(Interface.YamlModel.Templating.Predicate), typeof(Interface.YamlModel.Templating.Predicate).FullName!)
{
Link = "repository_action_types.md#predicate",
}
},
{
typeof(Interface.YamlModel.ActionMenus.Context).FullName!,
new TypeInfoDescriptor(nameof(Interface.YamlModel.ActionMenus.Context), typeof(Interface.YamlModel.ActionMenus.Context).FullName!)
{
Link = "repository_action_types.md#context",
}
},
{
typeof(Interface.YamlModel.ActionMenus.Context).FullName! + "?",
new TypeInfoDescriptor(nameof(Interface.YamlModel.ActionMenus.Context), typeof(Interface.YamlModel.ActionMenus.Context).FullName! + "?")
{
Link = "repository_action_types.md#context",
}
},
};

/// <summary>
/// Project names of all the projects that are used in the code generation.
/// </summary>
public static readonly List<string> Projects =
[
"RepoM.ActionMenu.Interface", // this is for the description of the interface types and its members.
"RepoM.ActionMenu.Core",

"RepoM.Plugin.AzureDevOps",
"RepoM.Plugin.Clipboard",
"RepoM.Plugin.Heidi",
"RepoM.Plugin.LuceneQueryParser",
"RepoM.Plugin.SonarCloud",
"RepoM.Plugin.Statistics",
"RepoM.Plugin.WebBrowser",
"RepoM.Plugin.WindowsExplorerGitInfo",
];
}
8 changes: 4 additions & 4 deletions src/RepoM.ActionMenu.CodeGen/Misc/FileSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ namespace RepoM.ActionMenu.CodeGen.Misc;
using System;
using System.IO;

public static class FileSystemHelper
internal static class FileSystemHelper
{
public static void DeleteFileIsExist(string pathToGeneratedCode)
public static void DeleteFileIfExist(string pathToGeneratedCode)
{
if (!File.Exists(pathToGeneratedCode))
{
Expand All @@ -23,15 +23,15 @@ public static void DeleteFileIsExist(string pathToGeneratedCode)
}
}

public static void CheckDirectory(string path)
public static void CheckDirectoryExists(string path)
{
if (!Directory.Exists(path))
{
throw new Exception($"Folder '{path}' does not exist");
}
}

public static void CheckFile(string path)
public static void CheckFileExists(string path)
{
if (!File.Exists(path))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ActionMenuClassDescriptor : ClassDescriptor
/// <summary>
/// Properties
/// </summary>
public List<ActionMenuMemberDescriptor> ActionMenuProperties { get; set; } = new List<ActionMenuMemberDescriptor>();
public List<ActionMenuMemberDescriptor> ActionMenuProperties { get; } = [];

public string RepositoryActionName => Name;

Expand Down
4 changes: 3 additions & 1 deletion src/RepoM.ActionMenu.CodeGen/Models/ClassDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClassDescriptor : IXmlDocsExtended
/// <summary>
/// Properties, Functions, fields etc. etc.
/// </summary>
public List<MemberDescriptor> Members { get; set; } = [];
public List<MemberDescriptor> Members { get; } = [];

/// <summary>
/// Friendly name
Expand All @@ -31,6 +31,8 @@ public class ClassDescriptor : IXmlDocsExtended

public string Namespace { get; set; } = null!;

public string FullName => $"{Namespace}.{ClassName}";

public bool IsEnum => _symbolType == SymbolType.Enum;

public bool IsClass => _symbolType == SymbolType.Class;
Expand Down
4 changes: 2 additions & 2 deletions src/RepoM.ActionMenu.CodeGen/Models/MemberDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public static class TypeInfoDescriptorFactory
public static TypeInfoDescriptor Create(ITypeSymbol typeSymbol)
{
var displayString = typeSymbol.ToDisplayString();
if (Program.TypeInfos.TryGetValue(displayString, out TypeInfoDescriptor? typeInfoDescriptor))
if (Constants.TypeInfos.TryGetValue(displayString, out TypeInfoDescriptor? typeInfoDescriptor))
{
return typeInfoDescriptor;
}

var result = new TypeInfoDescriptor(typeSymbol);
Program.TypeInfos.Add(displayString, result);
Constants.TypeInfos.Add(displayString, result);
return result;
}
}
Expand Down
26 changes: 18 additions & 8 deletions src/RepoM.ActionMenu.CodeGen/Models/ProjectDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,37 @@ public sealed class ProjectDescriptor
/// <summary>
/// Assembly Name
/// </summary>
public string AssemblyName { get; set; } = null!;
public required string AssemblyName { get; init; }

/// <summary>
/// Project name
/// </summary>
public string ProjectName { get; set; } = null!;
public required string ProjectName { get; init; }

/// <summary>
/// Full filename of the sln or csproj.
/// </summary>
public required string FullFilename { get; init; }

/// <summary>
/// The directory of the project.
/// </summary>
public required string Directory { get; init; }

/// <summary>
/// List of class descriptors for repository actions.
/// </summary>
public List<ActionMenuClassDescriptor> ActionMenus { get; } = new();
public List<ActionMenuClassDescriptor> ActionMenus { get; } = [];

/// <summary>
/// List of class descriptors for context (ie scriban methods, properties)
/// </summary>
public List<ActionMenuContextClassDescriptor> ActionContextMenus { get; } = new();
public List<ActionMenuContextClassDescriptor> ActionContextMenus { get; } = [];

/// <summary>
/// Regular types (to be used when action type has sub type property)
/// Regular types (to be used when action type has subtype property)
/// </summary>
public List<ClassDescriptor> Types { get; } = new();
public List<ClassDescriptor> Types { get; } = [];

/// <summary>
/// when project is plugin, the pluginname.
Expand All @@ -51,8 +61,8 @@ public sealed class ProjectDescriptor
/// <summary>
/// is plugin or not.
/// </summary>
public bool IsPlugin { get; private set; } = false;

public bool IsPlugin { get; private set; }
[ScriptMemberIgnore]
public void SetPackageInformation(PackageAttribute attribute)
{
Expand Down
10 changes: 5 additions & 5 deletions src/RepoM.ActionMenu.CodeGen/ProcessMembersVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class ProcessMembersVisitor : IClassDescriptorVisitor

// todo extend.
private static readonly string[] _collectionTypes =
{
"System.Collections.Generic.List<T>",
"System.Collections.Generic.IList<T>",
"System.Collections.Generic.IEnumerable<T>",
};
[
"System.Collections.Generic.List<T>",
"System.Collections.Generic.IList<T>",
"System.Collections.Generic.IEnumerable<T>",
];

public ProcessMembersVisitor(ITypeSymbol typeSymbol, IDictionary<string, string> files)
{
Expand Down
Loading

0 comments on commit bac0ee4

Please sign in to comment.