Skip to content
Merged
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
6 changes: 1 addition & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
push:
branches:
- develop
pull_request:
schedule:
- cron: '0 6 * * 1' # Every Monday at 06:00 UTC

Expand All @@ -29,10 +28,7 @@ jobs:
uses: github/codeql-action/init@v4
with:
languages: csharp
build-mode: manual

- name: Build
run: dotnet build ProjGraph.slnx --configuration Release
build-mode: autobuild

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ dotnet test tests/ProjGraph.Tests.Unit.ClassDiagram --filter "ClassAnalysisDepth

### Test Organisation

| Project | Purpose |
|-------------------------|-------------------------------------------------------------------------|
| `Tests.Unit.*` | Unit tests per library |
| `Tests.Integration.Cli` | CLI end-to-end tests |
| `Tests.Integration.Mcp` | MCP tool integration tests |
| `Tests.Contract` | MCP contract validation & DI wiring |
| `Tests.Shared` | Shared helpers (`TestDirectory`, `NullOutputConsole`, `TestPathHelper`) |
| Project | Purpose |
|-------------------------|----------------------------------------------------|
| `Tests.Unit.*` | Unit tests per library |
| `Tests.Integration.Cli` | CLI end-to-end tests |
| `Tests.Integration.Mcp` | MCP tool integration tests |
| `Tests.Contract` | MCP contract validation & DI wiring |
| `Tests.Shared` | Shared helpers (`TestDirectory`, `TestPathHelper`) |

## Adding a New Feature

Expand Down
12 changes: 6 additions & 6 deletions specs/004-config-class-members/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

The `AnalysisOptions` class in `ProjGraph.Lib.ClassDiagram` will be extended with the following fields:

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| IncludeProperties | bool | true | When true, includes properties and fields in the type definition. |
| Field | Type | Default | Description |
|-------|------|---------|------------------------------------------------------------------------------------------------------------------------------------|
| IncludeProperties | bool | true | When true, includes properties and fields in the type definition. |
| IncludeFunctions | bool | true | When true, includes methods in the type definition. Constructors are not currently extracted by the analyzer and are out of scope. |

## Entity: MemberDefinition (Reference)

Existing entity in `ProjGraph.Core.Models`.

| Field | Type | Category mapping |
|-------|------|------------------|
| Field | Type | Category mapping |
|-------|------|----------------------------|
| Kind | MemberKind | Property, Field -> "Properties" |
| Kind | MemberKind | Method -> "Functions" |
| Kind | MemberKind | Method -> "Functions" |

Note: The `MemberKind` enum contains `Field = 0`, `Property = 1`, `Method = 2`. There is no `Constructor` value — constructors are not extracted by `TypeAnalyzer` and are out of scope.

Expand Down
9 changes: 5 additions & 4 deletions src/ProjGraph.Cli/Commands/ClassDiagramCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ public override async Task<int> ExecuteAsync(
{
try
{
var model = await analysisService.AnalyzeFileAsync(
settings.Path,
var options = new AnalysisOptions(
settings.Depth,
settings.IncludeInheritance,
settings.IncludeDependencies,
settings.IncludeProperties,
settings.IncludeFunctions,
settings.Depth);
settings.IncludeFunctions);

var model = await analysisService.AnalyzeFileAsync(settings.Path, options);

var mermaidOutput = mermaidRenderer.Render(model, new DiagramOptions(settings.ShowTitle));
console.WriteLine(mermaidOutput);
Expand Down
45 changes: 18 additions & 27 deletions src/ProjGraph.Lib.ClassDiagram/Application/AnalysisOptions.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
using System.ComponentModel;

namespace ProjGraph.Lib.ClassDiagram.Application;

/// <summary>
/// Represents the options for configuring the analysis process, such as depth and inclusion of relationships.
/// </summary>
public sealed class AnalysisOptions
{
/// <summary>
/// The maximum depth of type relationships to analyze.
/// </summary>
public required int MaxDepth { get; init; }

/// <summary>
/// Indicates whether inheritance relationships should be included in the analysis.
/// </summary>
public required bool IncludeInheritance { get; init; }

/// <summary>
/// Indicates whether dependency relationships should be included in the analysis.
/// </summary>
public required bool IncludeDependencies { get; init; }

/// <summary>
/// Indicates whether properties and fields should be included in the analysis.
/// </summary>
public required bool IncludeProperties { get; init; }

/// <summary>
/// Indicates whether functions and methods should be included in the analysis.
/// </summary>
public required bool IncludeFunctions { get; init; }
}
/// <param name="MaxDepth">The maximum depth of type relationships to analyze.</param>
/// <param name="IncludeInheritance">Indicates whether inheritance relationships should be included in the analysis.</param>
/// <param name="IncludeDependencies">Indicates whether dependency relationships should be included in the analysis.</param>
/// <param name="IncludeProperties">Indicates whether properties and fields should be included in the analysis.</param>
/// <param name="IncludeFunctions">Indicates whether functions and methods should be included in the analysis.</param>
public record AnalysisOptions(
[Description("How many levels of relationships to follow (default: 1).")]
int MaxDepth = 1,
[Description("Whether to search the workspace for base classes and interfaces.")]
bool IncludeInheritance = false,
[Description("Whether to search for and include other classes used as properties or fields.")]
bool IncludeDependencies = false,
[Description("Whether to display properties and fields in the class diagram (default: true).")]
bool IncludeProperties = true,
[Description("Whether to display functions/methods in the class diagram (default: true).")]
bool IncludeFunctions = true);
14 changes: 2 additions & 12 deletions src/ProjGraph.Lib.ClassDiagram/Application/ClassAnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@ public class ClassAnalysisService(AnalyzeFileUseCase analyzeFileUseCase) : IClas
/// <inheritdoc />
public async Task<ClassModel> AnalyzeFileAsync(
string filePath,
bool includeInheritance = false,
bool includeDependencies = false,
bool includeProperties = true,
bool includeFunctions = true,
int maxDepth = 1)
AnalysisOptions? options = null)
{
return await analyzeFileUseCase.ExecuteAsync(
filePath,
includeInheritance,
includeDependencies,
includeProperties,
includeFunctions,
maxDepth);
return await analyzeFileUseCase.ExecuteAsync(filePath, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ public interface IClassAnalysisService
/// Analyzes a specific C# file and optionally discovers its relationships in the workspace.
/// </summary>
/// <param name="filePath">Target .cs file path.</param>
/// <param name="includeInheritance">Whether to discover base classes/interfaces.</param>
/// <param name="includeDependencies">Whether to discover types used in members.</param>
/// <param name="includeProperties">Whether to include properties and fields.</param>
/// <param name="includeFunctions">Whether to include functions and methods.</param>
/// <param name="maxDepth">Depth of relationship discovery.</param>
/// <param name="options">The analysis options.</param>
/// <returns>A ClassModel representing the discovered types and relationships.</returns>
Task<ClassModel> AnalyzeFileAsync(
string filePath,
bool includeInheritance = false,
bool includeDependencies = false,
bool includeProperties = true,
bool includeFunctions = true,
int maxDepth = 1);
Task<ClassModel> AnalyzeFileAsync(string filePath, AnalysisOptions? options = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@ public class AnalyzeFileUseCase(
/// Executes the analysis of a C# source file to extract class definitions and their relationships.
/// </summary>
/// <param name="filePath">The path to the C# source file to analyze.</param>
/// <param name="includeInheritance">Specifies whether to include inheritance relationships in the analysis.</param>
/// <param name="includeDependencies">Specifies whether to include dependency relationships in the analysis.</param>
/// <param name="includeProperties">Specifies whether to include properties and fields in the analysis.</param>
/// <param name="includeFunctions">Specifies whether to include functions and methods in the analysis.</param>
/// <param name="maxDepth">The maximum depth for analyzing relationships.</param>
/// <param name="options">The analysis options.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the analyzed class model.</returns>
/// <exception cref="FileNotFoundException">Thrown when the specified source file is not found.</exception>
public async Task<ClassModel> ExecuteAsync(
string filePath,
bool includeInheritance = false,
bool includeDependencies = false,
bool includeProperties = true,
bool includeFunctions = true,
int maxDepth = 1)
AnalysisOptions? options = null)
{
options ??= new AnalysisOptions();

if (!fileSystem.FileExists(filePath))
{
throw new FileNotFoundException("Source file not found", filePath);
Expand All @@ -58,15 +52,6 @@ public async Task<ClassModel> ExecuteAsync(
StartDirectory = startDir
};

var options = new AnalysisOptions
{
MaxDepth = maxDepth,
IncludeInheritance = includeInheritance,
IncludeDependencies = includeDependencies,
IncludeProperties = includeProperties,
IncludeFunctions = includeFunctions
};

var typesToAnalyze = new Queue<(INamedTypeSymbol Symbol, int Depth)>();

await EnqueueInitialTypesAsync(syntaxTree, compilation, typesToAnalyze);
Expand Down
20 changes: 3 additions & 17 deletions src/ProjGraph.Mcp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,8 @@ internal sealed class ProjGraphTools(
public async Task<string> GetClassDiagramAsync(
[Description("Absolute path to the .cs file to analyze.")]
string path,
[Description("Whether to search the workspace for base classes and interfaces.")]
bool includeInheritance = false,
[Description("Whether to search for and include other classes used as properties or fields.")]
bool includeDependencies = false,
[Description("Whether to display properties and fields in the class diagram (default: true).")]
bool includeProperties = true,
[Description("Whether to display functions/methods in the class diagram (default: true).")]
bool includeFunctions = true,
[Description("How many levels of relationships to follow (default: 1).")]
int depth = 1,
[Description("Analysis and discovery options.")]
AnalysisOptions? options = null,
[Description("Whether to include the title in the diagram (default: true).")]
bool showTitle = true,
CancellationToken cancellationToken = default)
Expand All @@ -86,13 +78,7 @@ public async Task<string> GetClassDiagramAsync(

FilePathGuard.RequireCsFile(path);

var model = await classService.AnalyzeFileAsync(
path,
includeInheritance,
includeDependencies,
includeProperties,
includeFunctions,
depth);
var model = await classService.AnalyzeFileAsync(path, options);

return classRenderer.Render(model, new DiagramOptions(showTitle));
}
Expand Down
39 changes: 14 additions & 25 deletions tests/ProjGraph.Tests.Contract/McpClassDiagramTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using ModelContextProtocol.Server;
using ProjGraph.Lib.ClassDiagram.Application;
using ProjGraph.Mcp;
using System.ComponentModel;
using System.Reflection;
Expand Down Expand Up @@ -43,35 +44,23 @@ public void GetClassDiagram_ShouldHave_RequiredParameters()
pathParam.ParameterType.Should().Be<string>();
pathParam.GetCustomAttribute<DescriptionAttribute>().Should().NotBeNull();

// Check optional flags
var inheritanceParam = parameters.Should().ContainSingle(p => p.Name == "includeInheritance").Which;
inheritanceParam.ParameterType.Should().Be<bool>();
inheritanceParam.IsOptional.Should().BeTrue();
inheritanceParam.DefaultValue.Should().Be(false);

var dependenciesParam = parameters.Should().ContainSingle(p => p.Name == "includeDependencies").Which;
dependenciesParam.ParameterType.Should().Be<bool>();
dependenciesParam.IsOptional.Should().BeTrue();
dependenciesParam.DefaultValue.Should().Be(false);

var propertiesParam = parameters.Should().ContainSingle(p => p.Name == "includeProperties").Which;
propertiesParam.ParameterType.Should().Be<bool>();
propertiesParam.IsOptional.Should().BeTrue();
propertiesParam.DefaultValue.Should().Be(true);

var functionsParam = parameters.Should().ContainSingle(p => p.Name == "includeFunctions").Which;
functionsParam.ParameterType.Should().Be<bool>();
functionsParam.IsOptional.Should().BeTrue();
functionsParam.DefaultValue.Should().Be(true);

var depthParam = parameters.Should().ContainSingle(p => p.Name == "depth").Which;
depthParam.ParameterType.Should().Be<int>();
depthParam.IsOptional.Should().BeTrue();
depthParam.DefaultValue.Should().Be(1);
// Check options parameter
var optionsParam = parameters.Should().ContainSingle(p => p.Name == "options").Which;
optionsParam.ParameterType.Should().Be<AnalysisOptions>();
optionsParam.IsOptional.Should().BeTrue();
optionsParam.DefaultValue.Should().BeNull();
optionsParam.GetCustomAttribute<DescriptionAttribute>().Should().NotBeNull();

// Check showTitle parameter
var titleParam = parameters.Should().ContainSingle(p => p.Name == "showTitle").Which;
titleParam.ParameterType.Should().Be<bool>();
titleParam.IsOptional.Should().BeTrue();
titleParam.DefaultValue.Should().Be(true);
titleParam.GetCustomAttribute<DescriptionAttribute>().Should().NotBeNull();

// Check cancellationToken parameter
var ctParam = parameters.Should().ContainSingle(p => p.Name == "cancellationToken").Which;
ctParam.ParameterType.Should().Be<CancellationToken>();
ctParam.IsOptional.Should().BeTrue();
}
}
Loading
Loading