|
| 1 | +# GitHub Copilot Instructions for ktsu.Coder |
| 2 | + |
| 3 | +This repository contains a flexible and extensible .NET library for representing code as Abstract Syntax Trees (AST), serializing to YAML, and generating code in multiple programming languages. |
| 4 | + |
| 5 | +## Technology Stack |
| 6 | + |
| 7 | +- **.NET Version**: 9.0 |
| 8 | +- **Language**: C# |
| 9 | +- **Testing Framework**: MSTest with FluentAssertions |
| 10 | +- **Package Management**: Central Package Version Management (CPM) |
| 11 | +- **CI/CD**: PowerShell-based PSBuild pipeline |
| 12 | +- **Key Dependencies**: YamlDotNet, ktsu.DeepClone, Microsoft.Extensions.DependencyInjection |
| 13 | + |
| 14 | +## Project Structure |
| 15 | + |
| 16 | +``` |
| 17 | +Coder/ |
| 18 | +├── Coder.Core/ # Core library with AST, serialization, and language generators |
| 19 | +│ ├── Ast/ # Abstract Syntax Tree node definitions |
| 20 | +│ ├── Serialization/ # YAML serialization/deserialization |
| 21 | +│ └── Languages/ # Language-specific code generators (ILanguageGenerator) |
| 22 | +├── Coder.ConsoleApp/ # Interactive TUI application (Spectre.Console) |
| 23 | +├── Coder.Test/ # Unit tests (MSTest) |
| 24 | +└── scripts/ # Build and release automation scripts (PSBuild) |
| 25 | +``` |
| 26 | + |
| 27 | +## Build and Test Commands |
| 28 | + |
| 29 | +### Building |
| 30 | +```bash |
| 31 | +dotnet build |
| 32 | +``` |
| 33 | + |
| 34 | +### Running Tests |
| 35 | +```bash |
| 36 | +dotnet test |
| 37 | +``` |
| 38 | + |
| 39 | +### Running the Console Application |
| 40 | +```bash |
| 41 | +dotnet run --project Coder.ConsoleApp |
| 42 | +``` |
| 43 | + |
| 44 | +## Code Style Requirements |
| 45 | + |
| 46 | +### EditorConfig Rules |
| 47 | +- **Indentation**: Tabs for C# files (`.cs`, `.csx`, `.cake`) |
| 48 | +- **Line Endings**: CRLF (`\r\n`) |
| 49 | +- **Encoding**: UTF-8 with BOM |
| 50 | +- **Final Newline**: Required |
| 51 | +- **Trailing Whitespace**: Must be trimmed |
| 52 | +- **.NET Code Style**: All analyzer diagnostics are treated as **errors** |
| 53 | + |
| 54 | +### File Headers |
| 55 | +All C# files must include the following header: |
| 56 | +```csharp |
| 57 | +// Copyright (c) ktsu.dev |
| 58 | +// All rights reserved. |
| 59 | +// Licensed under the MIT license. |
| 60 | +``` |
| 61 | + |
| 62 | +### Naming and Style |
| 63 | +- Use language keywords over framework type names (`int` not `Int32`) |
| 64 | +- Always specify accessibility modifiers |
| 65 | +- Prefer `readonly` fields where applicable |
| 66 | +- No `this.` qualifier unless necessary |
| 67 | +- Parentheses required for clarity in complex expressions |
| 68 | + |
| 69 | +## Architecture Principles |
| 70 | + |
| 71 | +This library follows **SOLID principles**: |
| 72 | + |
| 73 | +1. **Single Responsibility**: Each class handles one concern (AST structure, serialization, or code generation) |
| 74 | +2. **Open/Closed**: Language support is extensible through `ILanguageGenerator` interface without modifying core code |
| 75 | +3. **Liskov Substitution**: All language generators are interchangeable through the interface |
| 76 | +4. **Interface Segregation**: Focused interfaces with only required methods |
| 77 | +5. **Dependency Inversion**: Core library depends on abstractions (`ILanguageGenerator`), not concrete implementations |
| 78 | + |
| 79 | +### Key Design Patterns |
| 80 | +- **Visitor Pattern**: Used for AST traversal and code generation |
| 81 | +- **Dependency Injection**: Language generators should be registered via DI container |
| 82 | +- **Deep Cloning**: All AST nodes support cloning via `IDeepCloneable` |
| 83 | + |
| 84 | +## Package Management |
| 85 | + |
| 86 | +This repository uses **Central Package Version Management**: |
| 87 | +- Package versions are defined in `Directory.Packages.props` |
| 88 | +- **Never** specify versions in `.csproj` `<PackageReference>` elements |
| 89 | +- Use `<PackageReference Include="PackageName" />` without `Version` attribute |
| 90 | +- Add new package versions to `Directory.Packages.props` first |
| 91 | + |
| 92 | +## Testing Requirements |
| 93 | + |
| 94 | +### Required Tests |
| 95 | +- Add unit tests for **all** new functionality |
| 96 | +- Use **MSTest** with `[TestClass]` and `[TestMethod]` attributes |
| 97 | +- Use **FluentAssertions** for assertions (e.g., `result.Should().Be(expected)`) |
| 98 | +- Test files should match pattern `*Tests.cs` |
| 99 | +- Tests should cover: |
| 100 | + - Happy path scenarios |
| 101 | + - Edge cases and boundary conditions |
| 102 | + - Error handling and validation |
| 103 | + |
| 104 | +### Test Structure Example |
| 105 | +```csharp |
| 106 | +[TestClass] |
| 107 | +public class MyFeatureTests |
| 108 | +{ |
| 109 | + [TestMethod] |
| 110 | + public void MethodName_Scenario_ExpectedBehavior() |
| 111 | + { |
| 112 | + // Arrange |
| 113 | + var sut = new MyClass(); |
| 114 | + |
| 115 | + // Act |
| 116 | + var result = sut.Method(); |
| 117 | + |
| 118 | + // Assert |
| 119 | + result.Should().Be(expected); |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +## Working with AST Nodes |
| 125 | + |
| 126 | +### Creating New AST Node Types |
| 127 | +1. Inherit from `AstNode` or `AstCompositeNode` |
| 128 | +2. Implement `IDeepCloneable<T>` for cloning support |
| 129 | +3. Add YAML serialization support in `YamlSerializer` and `YamlDeserializer` |
| 130 | +4. Update language generators to handle the new node type |
| 131 | +5. Add comprehensive unit tests |
| 132 | + |
| 133 | +### Adding New Language Generators |
| 134 | +1. Implement `ILanguageGenerator` interface (or extend `LanguageGeneratorBase`) |
| 135 | +2. Override `LanguageId`, `DisplayName`, and `FileExtension` properties |
| 136 | +3. Implement code generation logic in `Generate(AstNode)` method |
| 137 | +4. Handle indentation correctly for block-structured languages |
| 138 | +5. Add unit tests with various AST structures |
| 139 | + |
| 140 | +## CI/CD Workflow |
| 141 | + |
| 142 | +The repository uses a PowerShell-based build system (`PSBuild`): |
| 143 | +- **Build Script**: `scripts/PSBuild.psm1` |
| 144 | +- **Workflow**: `.github/workflows/dotnet.yml` |
| 145 | +- **Process**: Restore → Build → Test → Package → Release |
| 146 | +- **Version Management**: Automated via `VERSION.md` and changelog |
| 147 | +- **Release**: Automatic on `main` branch with changelog updates |
| 148 | + |
| 149 | +### Important Notes |
| 150 | +- Do not modify version numbers manually |
| 151 | +- Update `CHANGELOG.md` for user-facing changes |
| 152 | +- CI runs on Windows (not cross-platform compatible yet) |
| 153 | +- SonarQube integration for code quality analysis |
| 154 | + |
| 155 | +## Common Tasks |
| 156 | + |
| 157 | +### Adding a New Feature |
| 158 | +1. Create feature branch from `main` or `develop` |
| 159 | +2. Implement core functionality in `Coder.Core` |
| 160 | +3. Add comprehensive unit tests in `Coder.Test` |
| 161 | +4. Update README.md if API changes |
| 162 | +5. Update CHANGELOG.md with feature description |
| 163 | +6. Ensure all tests pass and build succeeds |
| 164 | + |
| 165 | +### Fixing a Bug |
| 166 | +1. Add a failing test that reproduces the bug |
| 167 | +2. Fix the bug with minimal code changes |
| 168 | +3. Verify the test now passes |
| 169 | +4. Add regression tests if needed |
| 170 | +5. Update CHANGELOG.md if user-facing |
| 171 | + |
| 172 | +### Updating Dependencies |
| 173 | +1. Update version in `Directory.Packages.props` |
| 174 | +2. Run `dotnet restore` to verify compatibility |
| 175 | +3. Run full test suite to check for breaking changes |
| 176 | +4. Update code if API changes are required |
| 177 | + |
| 178 | +## What NOT to Do |
| 179 | + |
| 180 | +- ❌ Don't modify working tests without good reason |
| 181 | +- ❌ Don't add package versions to `.csproj` files (use `Directory.Packages.props`) |
| 182 | +- ❌ Don't change line endings from CRLF to LF |
| 183 | +- ❌ Don't use spaces for indentation in C# files (use tabs) |
| 184 | +- ❌ Don't skip file headers on new C# files |
| 185 | +- ❌ Don't bypass .editorconfig rules |
| 186 | +- ❌ Don't commit without running tests |
| 187 | +- ❌ Don't modify CI/CD scripts unless specifically required |
| 188 | + |
| 189 | +## Documentation |
| 190 | + |
| 191 | +- **Main README**: `/README.md` - Library overview and quick start |
| 192 | +- **Design Document**: `/docs/design.md` - Architecture and design decisions |
| 193 | +- **Implementation Plan**: `/docs/implementation-plan.md` - Development roadmap |
| 194 | + |
| 195 | +## Additional Resources |
| 196 | + |
| 197 | +- Repository follows ktsu.dev conventions and standards |
| 198 | +- Uses `ktsu.Sdk.Lib` for common build configurations |
| 199 | +- Leverages ktsu.dev packages for common functionality (DeepClone, StrongStrings, etc.) |
0 commit comments