ctx/tools/roslyn-helper
Ricardo Carneiro 15dc1b6b2f feat(csharp): implement 'outline' command for single-file structural summary
Adds OutlineHandler.cs to the Roslyn helper using CSharpSyntaxTree.ParseText
and manual syntax tree traversal (no solution load required). Extracts
namespaces, types, method/property/field/event signatures and line numbers
without method bodies. Handles file-scoped namespaces, generics, records,
nested types, partial classes, top-level statements, and [Obsolete] markers.

Adds Microsoft.CodeAnalysis.CSharp 4.13.0 as the sole new NuGet dependency
(pure parser, no MSBuild coupling). Go side adds Outline() client method,
OutlineResult/Type/Member types, outline.go command, and WriteOutline formatter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 19:41:47 -03:00
..
src/RoslynHelper feat(csharp): implement 'outline' command for single-file structural summary 2026-04-27 19:41:47 -03:00
.gitignore feat(roslyn-helper): C# subprocess helper with JSON-RPC over stdin/stdout 2026-04-27 18:12:21 -03:00
README.md feat(roslyn-helper): C# subprocess helper with JSON-RPC over stdin/stdout 2026-04-27 18:12:21 -03:00
RoslynHelper.sln feat(roslyn-helper): C# subprocess helper with JSON-RPC over stdin/stdout 2026-04-27 18:12:21 -03:00
test-input.txt feat(roslyn-helper): C# subprocess helper with JSON-RPC over stdin/stdout 2026-04-27 18:12:21 -03:00

ctx-roslyn-helper

C# subprocess invoked by ctx csharp commands. Loads .NET solutions with Roslyn and answers JSON-RPC queries over stdin/stdout.

Protocol

One JSON object per line, UTF-8 without BOM.

Request: {"id": 1, "method": "ping", "params": {}} Success: {"id": 1, "result": {...}} Error: {"id": 1, "error": {"code": "E_NOT_FOUND", "message": "..."}}

Methods

Method Params Description
ping {} Health check, returns version
loadSolution {"path": "C:\\...\\x.sln"} Load solution into workspace
projectSummary {} Summary of loaded solution
shutdown {} Exit cleanly (no response written)

Build

Requires: .NET 8+ SDK.

dotnet build src/RoslynHelper -c Release

Publish

dotnet publish src/RoslynHelper -c Release -r win-x64 --self-contained false -o publish/

Output: publish/ctx-roslyn-helper.exe

Manual test

cd publish
./ctx-roslyn-helper.exe

Then type line by line:

{"id": 1, "method": "ping", "params": {}}
{"id": 2, "method": "loadSolution", "params": {"path": "C:\\path\\to\\My.sln"}}
{"id": 3, "method": "projectSummary", "params": {}}
{"id": 99, "method": "shutdown", "params": {}}

Notes

  • Does NOT need to be self-contained. Requires .NET 8+ runtime on the target machine. Users of ctx csharp are .NET developers — the runtime is already there.
  • MSBuild warnings logged to stderr are informational (missing SDK targets, etc.). Only WorkspaceFailed events with Failure kind indicate real problems.
  • The helper is spawned once per ctx invocation and kept alive for all queries in that session. ctx Go manages the subprocess lifecycle.