Skip to content

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
tui-cs:developfrom
omm-prakash18:feature/analyzers-v1-diagnostics
Open

omm-prakash18 wants to merge 2 commits into
tui-cs:developfrom
omm-prakash18:feature/analyzers-v1-diagnostics

Conversation

@omm-prakash18

Copy link
Copy Markdown

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, static Application.Init(), Toplevel, view.Bounds, new Button("OK"), TabView, TileView, RadioGroup, Colors.ColorSchemes, KeyCode bitmasks, and .Accepting handlers ignoring event args).

Previously, these produced unhelpful compiler errors (CS1061, CS0246) with zero migration guidance.

This PR ships Terminal.Gui.Analyzers (bundled into Terminal.Gui.nupkg under analyzers/dotnet/cs/) providing 14 diagnostic rules (TGUI0001 - TGUI0014) and Roslyn CodeFixes to correct v1 hallucinations at the point of compile error.


Proposed Changes

  • Create Terminal.Gui.Analyzers (netstandard2.0) with 14 Roslyn diagnostic analyzers and CodeFixes:
    • TGUI0001: .Clicked ➔ Accepted (post-event) or Accepting (cancellable event)
    • TGUI0002: Static Application.Init()/Run()/Shutdown()/Top ➔ Application.Create().Init()
    • TGUI0003: Toplevel ➔ Runnable / Window
    • TGUI0004: View.Bounds ➔ View.Viewport
    • TGUI0005: Positional constructors ➔ parameterless constructor with object initializers (new Button { Text = "..." })
    • TGUI0006: TabView/Tab ➔ Tabs
    • TGUI0007: TileView ➔ Pos/Dim panes
    • TGUI0008: RadioGroup ➔ OptionSelector
    • TGUI0009: ColorScheme ➔ Scheme & SchemeManager
    • TGUI0010: KeyCode bitmask ➔ Key.X.WithCtrl
    • TGUI0011: .Accepting handler ignoring event args ➔ Accepted
    • TGUI0012: Legacy 6-arg MenuItem ctor ➔ v2 MenuItem ctor
    • TGUI0013: LayoutStyle.Computed ➔ Pos/Dim
    • TGUI0014: Pos.At/Pos.Left ➔ direct integer assignment (X = 5)
  • Bundle Terminal.Gui.Analyzers.dll inside Terminal.Gui.nupkg under analyzers/dotnet/cs/Terminal.Gui.Analyzers.dll so every consumer app gets free compile-time feedback.
  • Add unit test suite in Tests/Terminal.Gui.Analyzers.Tests/ and link tests into UnitTestsParallelizable.

Pull Request Checklist:

…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
@omm-prakash18
omm-prakash18 requested a review from tig as a code owner October 4, 2026 05:35
@tig
tig requested a balanced review from Copilot October 5, 2026 12:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 3 Medium severity · 1 Low severity

Open (5)
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"),
Comment thread Directory.Packages.props
<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();

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants