|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Test |
| 6 | + |
| 7 | +``` |
| 8 | +# Restore packages |
| 9 | +nuget restore CodeDocumentor.sln |
| 10 | +
|
| 11 | +# Build (no VS deployment) |
| 12 | +msbuild CodeDocumentor.sln /p:configuration="Release" /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal |
| 13 | +
|
| 14 | +# Debug build (deploys to VS Experimental Instance) |
| 15 | +msbuild CodeDocumentor.sln /p:configuration="Debug" |
| 16 | +
|
| 17 | +# Run tests |
| 18 | +vstest.console.exe CodeDocumentor.Test\bin\Release\net48\CodeDocumentor.Test.dll |
| 19 | +``` |
| 20 | + |
| 21 | +CI runs on `windows-latest` via `.github/workflows/dotnet.yml`. |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +Visual Studio extension (VSIX) that generates XML doc comments (`///`) for C# code members using Roslyn -- no network calls. |
| 26 | + |
| 27 | +### Projects |
| 28 | + |
| 29 | +| Project | Role | |
| 30 | +|---|---| |
| 31 | +| `CodeDocumentor2026` | Main VSIX (.NET 4.8, VS2022/VS2026). Entry point: `CodeDocumentor2026Package.cs` | |
| 32 | +| `CodeDocumentor.Common` | Core logic: comment generation, Roslyn tree manipulation (netstandard2.0) | |
| 33 | +| `CodeDocumentor.Test` | xUnit + MSTest suite (net48) | |
| 34 | +| `CodeDocumentor.Analyzers` | Legacy Roslyn DiagnosticAnalyzer approach -- kept for reference, not used by 2026 extension | |
| 35 | +| `CodeDocumentor` | Older VS2022-era VSIX -- retained but superseded | |
| 36 | + |
| 37 | +### Data Flow |
| 38 | + |
| 39 | +``` |
| 40 | +User action (context menu / editor command) |
| 41 | + → Command.Execute() |
| 42 | + → CommentExecutor -- iterates selected DTE project items, recurses folders |
| 43 | + → TextSelectionExecutor -- grabs raw C# from editor, inserts result, calls SmartFormat |
| 44 | + → CommentBuilderService.AddDocumentation(fileContents) |
| 45 | + → CSharpSyntaxTree.ParseText() |
| 46 | + → Build*Comments() per member type (two passes: members first, then containers) |
| 47 | + → root.ReplaceNodes() |
| 48 | + → returns modified source string |
| 49 | +``` |
| 50 | + |
| 51 | +### Key Files in `CodeDocumentor.Common` |
| 52 | + |
| 53 | +- `Services/CommentBuilderService.cs` -- central service; `AddDocumentation()` is the main entry; processes Properties/Constructors/Enums/Fields/Methods first, then Interfaces/Classes/Records (second pass because they contain the first) |
| 54 | +- `Builders/DocumentationBuilder.cs` -- fluent Roslyn `XmlNodeSyntax` builder; methods: `WithSummary`, `WithParameters`, `WithTypeParamters`, `WithReturnType`, `WithExceptionTypes`, `WithPropertyValueTypes`, `WithExisting` |
| 55 | +- `Helper/CommentHelper.cs` -- converts PascalCase identifiers to human-readable summary text via WordMaps, pluralization, and article insertion |
| 56 | +- `Helper/DocumentationHeaderHelper.cs` -- creates Roslyn XML element syntax nodes |
| 57 | +- `Helpers/NameSplitter.cs` -- splits PascalCase/camelCase into word parts |
| 58 | +- `Locators/ServiceLocator.cs` -- static singleton locator for `DocumentationHeaderHelper`, `CommentHelper`, `GenericCommentManager`, `ICommentBuilderService`, `IEventLogger`, `ISettingService` |
| 59 | +- `Models/Settings2026.cs` -- all user settings: async suffix, value nodes, public-only, preserve existing summary, natural language returns, cref inclusion, word maps, TODO fallback |
| 60 | + |
| 61 | +### Supported Member Types (8 total) |
| 62 | + |
| 63 | +`CommentBuilderService` handles these Roslyn syntax node types. Each has a `Build*Comments()` method and a `BuildNewDeclaration()` overload, and is registered in `IsDocumentableNode()` and `BuildNewDocumentationNode()`: |
| 64 | + |
| 65 | +| C# construct | Roslyn type | Batch | |
| 66 | +|---|---|---| |
| 67 | +| class | `ClassDeclarationSyntax` | 2 (container) | |
| 68 | +| interface | `InterfaceDeclarationSyntax` | 2 (container) | |
| 69 | +| record | `RecordDeclarationSyntax` | 2 (container) | |
| 70 | +| enum | `EnumDeclarationSyntax` | 1 (member) | |
| 71 | +| method | `MethodDeclarationSyntax` | 1 (member) | |
| 72 | +| property | `PropertyDeclarationSyntax` | 1 (member) | |
| 73 | +| constructor | `ConstructorDeclarationSyntax` | 1 (member) | |
| 74 | +| field | `FieldDeclarationSyntax` | 1 (member) | |
| 75 | + |
| 76 | +Two-pass `root.ReplaceNodes()` is intentional: batch 1 (members) runs first so container nodes in batch 2 already contain updated children. |
| 77 | + |
| 78 | +### Adding a New Member Type |
| 79 | + |
| 80 | +To add support for a new C# syntax node type (e.g. `EventFieldDeclarationSyntax`): |
| 81 | + |
| 82 | +1. Add a `Build*Comments()` method in `CommentBuilderService.cs` (follow existing pattern -- collect old/new node pairs, return a replacement dictionary) |
| 83 | +2. Add a `BuildNewDeclaration(XxxSyntax node, ...)` overload in `CommentBuilderService.cs` |
| 84 | +3. Register in `IsDocumentableNode()` switch (line ~528) |
| 85 | +4. Register in `BuildNewDocumentationNode()` switch (line ~566) |
| 86 | +5. Add to the appropriate batch in `AddDocumentation()` (batch 1 for members, batch 2 for containers) |
| 87 | +6. Add to `ICommentBuilderService` interface |
| 88 | +7. Use `DocumentationBuilder` fluent methods -- `WithSummary` always; add `WithParameters` / `WithReturnType` / `WithExceptionTypes` as applicable |
| 89 | +8. Use `DocumentationHeaderHelper` to create raw XML nodes; `CommentHelper` to generate human-readable text from identifier names |
| 90 | + |
| 91 | +### Known Missing Types (not yet supported) |
| 92 | + |
| 93 | +- `EventFieldDeclarationSyntax` -- `public event EventHandler Click;` (field-like, most common form) |
| 94 | +- `EventDeclarationSyntax` -- explicit `add`/`remove` event accessors |
| 95 | +- `DelegateDeclarationSyntax` -- `public delegate void MyHandler(...)` |
| 96 | +- `StructDeclarationSyntax` -- `struct` (mirrors class; would go in batch 2) |
| 97 | +- `IndexerDeclarationSyntax` -- `this[int index]` |
| 98 | +- `DestructorDeclarationSyntax` -- `~MyClass()` |
| 99 | +- `OperatorDeclarationSyntax` -- `operator+` etc. |
| 100 | +- `ConversionOperatorDeclarationSyntax` -- `implicit`/`explicit` operator |
| 101 | +- `EnumMemberDeclarationSyntax` -- individual enum values (whole enum is supported, members are not) |
| 102 | + |
| 103 | +### Commands (`CodeDocumentor2026/Commands/`) |
| 104 | + |
| 105 | +- `CodeDocumentorContextCommand` -- Solution Explorer right-click on file/folder |
| 106 | +- `CodeDocumentorEditorCommand` -- Editor right-click "Document This" for single member |
| 107 | +- `CodeDocumentorFileMenu` -- Tools menu "Document File" |
| 108 | + |
| 109 | +### Settings |
| 110 | + |
| 111 | +`OptionPageGrid` in the VSIX reads settings and populates `IBaseSettings`. `ServiceLocator.SettingService` is the runtime access point throughout `Common`. |
| 112 | + |
| 113 | +### Test Project Notes |
| 114 | + |
| 115 | +Tests reference both `CodeDocumentor.Analyzers` and old `CodeDocumentor` projects. New behavior tests should target `CodeDocumentor.Common` directly via `CommentBuilderService`. |
0 commit comments