Repository navigation
Adds Terminal.Gui.Analyzers package to catch v1 API hallucinations and anti-patterns at compile time - #5697
Open
omm-prakash18 wants to merge 2 commits into
Open
Adds Terminal.Gui.Analyzers package to catch v1 API hallucinations and anti-patterns at compile time#5697omm-prakash18 wants to merge 2 commits into
omm-prakash18 wants to merge 2 commits into
Conversation
…allucinations at compile time - Implement V1ApiDiagnosticAnalyzer covering rules TGUI0001 through TGUI0014 - Implement V1ApiCodeFixProvider for automated Roslyn AST refactorings - Bundle Terminal.Gui.Analyzers.dll inside Terminal.Gui.nupkg under analyzers/dotnet/cs - Add unit test suite in Tests/Terminal.Gui.Analyzers.Tests and link to UnitTestsParallelizable
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The analyzer is not packaged for consumers and currently reports several false positives against valid v2 and unrelated code.
Review effort: Balanced
Findings: 1
Open (5)
RadioGroup code fix produces invalid OptionSelector construction · New Central Roslyn package downgrade affects existing projects · New Analyzer DLL is not included in the NuGet package · New Analyzer tests use lookalike APIs instead of Terminal.Gui · New New analyzer code violates repository formatting rules · New
What changed in this PR
Adds a consumer-facing Roslyn analyzer intended to guide migration from Terminal.Gui v1 APIs to v2.
Changes:
- Adds 14 diagnostics and six code fixes.
- Adds analyzer tests and solution integration.
- Attempts to bundle the analyzer with Terminal.Gui.
| File | Description |
|---|---|
.gitignore |
Ignores agent planning files. |
Directory.Packages.props |
Adds and changes Roslyn package versions. |
Terminal.Gui.Analyzers/Terminal.Gui.Analyzers.csproj |
Defines the analyzer project. |
Terminal.Gui.Analyzers/V1ApiCodeFixProvider.cs |
Implements code fixes. |
Terminal.Gui.Analyzers/V1ApiDiagnosticAnalyzer.cs |
Implements migration diagnostics. |
Terminal.Gui/Terminal.Gui.csproj |
References the analyzer. |
Terminal.slnx |
Adds analyzer projects. |
Tests/Terminal.Gui.Analyzers.Tests/Terminal.Gui.Analyzers.Tests.csproj |
Defines analyzer tests. |
Tests/Terminal.Gui.Analyzers.Tests/V1ApiDiagnosticAnalyzerTests.cs |
Tests analyzer diagnostics. |
Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj |
Links analyzer tests into the main suite. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+75
to
+81
| else if (diagnostic.Id == V1ApiDiagnosticAnalyzer.RuleRadioGroup.Id) | ||
| { | ||
| context.RegisterCodeFix( | ||
| CodeAction.Create( | ||
| title: "Replace with 'OptionSelector'", | ||
| createChangedDocument: c => ReplaceTokenAsync(context.Document, root, token, "OptionSelector", c), | ||
| equivalenceKey: "UseOptionSelector"), |
| <ItemGroup> | ||
| <!-- Enable Nuget Source Link for github --> | ||
| <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.9.0" /> | ||
| <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" /> |
| <!-- =================================================================== --> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\Terminal.Gui.Analyzers.Internal\Terminal.Gui.Analyzers.Internal.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="..\Terminal.Gui.Analyzers\Terminal.Gui.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> |
Comment on lines
+17
to
+20
| var compilation = CSharpCompilation.Create("TestAssembly", | ||
| new[] { tree }, | ||
| new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }, | ||
| new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); |
Comment on lines
+144
to
+147
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); | ||
| context.EnableConcurrentExecution(); |
…gure nupkg analyzer bundling
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes
Summary & Motivation
AI coding agents and developers migrating from Terminal.Gui v1 frequently hallucinate or rely on deprecated/removed v1 APIs (such as
button.Clicked, staticApplication.Init(),Toplevel,view.Bounds,new Button("OK"),TabView,TileView,RadioGroup,Colors.ColorSchemes,KeyCodebitmasks, and.Acceptinghandlers ignoring event args).Previously, these produced unhelpful compiler errors (
CS1061,CS0246) with zero migration guidance.This PR ships
Terminal.Gui.Analyzers(bundled intoTerminal.Gui.nupkgunderanalyzers/dotnet/cs/) providing 14 diagnostic rules (TGUI0001-TGUI0014) and Roslyn CodeFixes to correct v1 hallucinations at the point of compile error.Proposed Changes
Terminal.Gui.Analyzers(netstandard2.0) with 14 Roslyn diagnostic analyzers and CodeFixes:TGUI0001:.Clicked➔Accepted(post-event) orAccepting(cancellable event)TGUI0002: StaticApplication.Init()/Run()/Shutdown()/Top➔Application.Create().Init()TGUI0003:Toplevel➔Runnable/WindowTGUI0004:View.Bounds➔View.ViewportTGUI0005: Positional constructors ➔ parameterless constructor with object initializers (new Button { Text = "..." })TGUI0006:TabView/Tab➔TabsTGUI0007:TileView➔Pos/DimpanesTGUI0008:RadioGroup➔OptionSelectorTGUI0009:ColorScheme➔Scheme&SchemeManagerTGUI0010:KeyCodebitmask ➔Key.X.WithCtrlTGUI0011:.Acceptinghandler ignoring event args ➔AcceptedTGUI0012: Legacy 6-argMenuItemctor ➔ v2MenuItemctorTGUI0013:LayoutStyle.Computed➔Pos/DimTGUI0014:Pos.At/Pos.Left➔ direct integer assignment (X = 5)Terminal.Gui.Analyzers.dllinsideTerminal.Gui.nupkgunderanalyzers/dotnet/cs/Terminal.Gui.Analyzers.dllso every consumer app gets free compile-time feedback.Tests/Terminal.Gui.Analyzers.Tests/and link tests intoUnitTestsParallelizable.Pull Request Checklist:
dotnet testbefore commit (17,779 tests passed cleanly)