Skip to content

Michael2150/codegraph-roslyn

Repository files navigation

codegraph-roslyn

Roslyn-based extractor for @colbymchenry/codegraph. Parses VB.NET and C# source files using the actual .NET compiler API and emits a JSON symbol graph — classes, modules, methods, properties, fields, enums, imports, call edges, inheritance edges — for import into codegraph's SQLite index.

Tree-sitter has no VB.NET grammar and its C# grammar lacks semantic information. This tool fills that gap by running as a subprocess invoked by the RoslynExtractor bridge in codegraph.


Using this on your own VB.NET codebase today

Check the PR first: VB.NET support is tracked in colbymchenry/codegraph#627. If that PR has been merged, the functionality is available in the official @colbymchenry/codegraph package and you do not need to use the fork — just npm install -g @colbymchenry/codegraph and run codegraph init in your project.

If the PR is still pending, follow the fork instructions below.

The upstream PR (colbymchenry/codegraph#627) is pending review. In the meantime you can run the fork directly.

1. Get Node.js 20+

Download from nodejs.org if you don't have it.

2. Clone the codegraph fork and install dependencies

git clone https://github.com/Michael2150/codegraph
cd codegraph
npm install
npm run build

3. Download the Roslyn binary

Go to the v1.0.1 release and download the binary for your platform:

Platform File to download
Windows codegraph-roslyn-win-x64.exe
macOS Intel codegraph-roslyn-osx-x64
macOS Apple Silicon codegraph-roslyn-osx-arm64
Linux codegraph-roslyn-linux-x64

Place it in the bin/ folder inside the cloned repo, keeping the exact filename.

On macOS/Linux you also need to make it executable:

chmod +x bin/codegraph-roslyn-osx-arm64

4. Index your VB.NET project

# From inside the codegraph fork directory
node dist/bin/codegraph.js init /path/to/your/vb/project

That's it. codegraph will index all .vb files using the Roslyn extractor and store the graph in .codegraph/ inside your project.

5. Use it with Claude Code or another MCP client

node dist/bin/codegraph.js serve --mcp --path /path/to/your/vb/project

Or install it into your agent by running:

node dist/bin/codegraph.js install

Requirements


Build

# Clone the repo
git clone https://github.com/your-fork/codegraph-roslyn
cd codegraph-roslyn

# Debug build (used during development and by the test suite)
dotnet build

# The binary lands at:
# src/CodeGraph.Roslyn/bin/Debug/net8.0/codegraph-roslyn.exe   (Windows)
# src/CodeGraph.Roslyn/bin/Debug/net8.0/codegraph-roslyn       (macOS / Linux)

Self-contained release build (for bundling with the npm package)

# Windows
dotnet publish src/CodeGraph.Roslyn -r win-x64 -c Release \
  -p:PublishSingleFile=true --self-contained true \
  -o publish/win-x64

# macOS (Intel)
dotnet publish src/CodeGraph.Roslyn -r osx-x64 -c Release \
  -p:PublishSingleFile=true --self-contained true \
  -o publish/osx-x64

# Linux
dotnet publish src/CodeGraph.Roslyn -r linux-x64 -c Release \
  -p:PublishSingleFile=true --self-contained true \
  -o publish/linux-x64

Copy the resulting binary into the codegraph fork's bin/ directory:

bin/
  codegraph-roslyn-win-x64.exe
  codegraph-roslyn-osx-x64
  codegraph-roslyn-linux-x64

CLI usage

codegraph-roslyn --file <path-to-source-file>

Writes JSON to stdout. Writes errors to stderr. Exit code 0 on success.

# Example
codegraph-roslyn --file fixtures/VbFixture/GeometryTypes.vb

Output:

{
  "nodes": [
    {
      "id": "C:/repo/GeometryTypes.vb::Fixtures::GeometryUtils",
      "kind": "module",
      "name": "GeometryUtils",
      "qualifiedName": "Fixtures.GeometryUtils",
      "filePath": "C:/repo/GeometryTypes.vb",
      "startLine": 3,
      "endLine": 20,
      "visibility": "public",
      "isStatic": false,
      "isAsync": false,
      "parentId": "C:/repo/GeometryTypes.vb::Fixtures"
    }
  ],
  "edges": [
    {
      "kind": "contains",
      "fromId": "C:/repo/GeometryTypes.vb::Fixtures",
      "toId": "C:/repo/GeometryTypes.vb::Fixtures::GeometryUtils",
      "toQualifiedName": "Fixtures.GeometryUtils"
    }
  ],
  "unresolvedReferences": [],
  "errors": []
}

Running against the test fixtures

The fixtures/ directory contains small VB.NET and C# files that cover the node and edge types the extractor must handle. You can run the tool against any of them directly:

# After a debug build, point to the binary
export CODEGRAPH_ROSLYN_BIN=./src/CodeGraph.Roslyn/bin/Debug/net8.0/codegraph-roslyn
# Windows (PowerShell)
$env:CODEGRAPH_ROSLYN_BIN = ".\src\CodeGraph.Roslyn\bin\Debug\net8.0\codegraph-roslyn.exe"

# Run against a VB.NET fixture
$env:CODEGRAPH_ROSLYN_BIN --file fixtures/VbFixture/GeometryTypes.vb | python -m json.tool

# Run against a C# fixture
$env:CODEGRAPH_ROSLYN_BIN --file fixtures/CsFixture/GeometryTypes.cs | python -m json.tool

Available fixtures:

File What it tests
VbFixture/GeometryTypes.vb Module, classes, methods, fields, Overrides
VbFixture/EventSystem.vb WithEvents, Handles, RaiseEvent, event handler wiring
VbFixture/PartialClass.Part1.vb / Part2.vb Partial class across two files
VbFixture/ImportAliases.vb Imports with aliases, nested namespaces
VbFixture/AsyncPatterns.vb Async Sub (void async), Async Function, Await
VbFixture/Animals.vb Inheritance (Inherits), Implements, qualified names
CsFixture/GeometryTypes.cs Classes, structs, interfaces, generics
CsFixture/EventSystem.cs Events, delegates, += wiring
CsFixture/AsyncPatterns.cs async/await, Task<T> return types
CsFixture/GenericTypes.cs Generic classes, constrained type parameters
CsFixture/Animals.cs Inheritance chain, interface implementation, override
CsFixture/ImportAliases.cs using aliases, nested namespaces

Running the tests

The test suite is xUnit-based. Tests require the debug binary to exist and are skipped (not failed) when it is unavailable.

# 1. Build the extractor first
dotnet build

# 2. Set the binary path — must be an absolute path (the test process cwd differs from the repo root)
# macOS / Linux
export CODEGRAPH_ROSLYN_BIN="$(pwd)/src/CodeGraph.Roslyn/bin/Debug/net8.0/codegraph-roslyn"

# Windows (PowerShell)
$env:CODEGRAPH_ROSLYN_BIN = "$PWD\src\CodeGraph.Roslyn\bin\Debug\net8.0\codegraph-roslyn.exe"

# 3. Run the full suite
dotnet test

# Run only VB.NET tests
dotnet test tests/VbFixture.Tests

# Run only C# tests
dotnet test tests/CsFixture.Tests

# Run a specific test by name
dotnet test --filter "Module_IsExtractedWithKindModule"

Expected output: 131 tests pass, 0 fail, 0 skip when CODEGRAPH_ROSLYN_BIN is set. All tests skip cleanly when the env var is absent (useful in CI before a binary build step).


Project structure

codegraph-roslyn/
├── src/
│   └── CodeGraph.Roslyn/
│       ├── CodeGraph.Roslyn.csproj
│       ├── Program.cs          # CLI entry point
│       ├── Models.cs           # JSON output types
│       ├── CSharpExtractor.cs  # C# syntax walker
│       └── VBNetExtractor.cs   # VB.NET syntax walker
├── tests/
│   ├── CsFixture.Tests/        # xUnit tests for C# extraction
│   └── VbFixture.Tests/        # xUnit tests for VB.NET extraction
├── fixtures/
│   ├── CsFixture/              # C# source fixtures
│   └── VbFixture/              # VB.NET source fixtures
└── codegraph-roslyn.slnx       # Solution file

How it integrates with codegraph

codegraph's RoslynExtractor class (at src/extraction/roslyn-extractor.ts in the codegraph fork) invokes this binary as a subprocess via execFileSync, passing --file <path>. The JSON output is parsed and mapped to codegraph's internal Node, Edge, and UnresolvedReference types before being written to SQLite.

The binary is selected at runtime based on platform:

Platform Binary
Windows bin/codegraph-roslyn-win-x64.exe
macOS bin/codegraph-roslyn-osx-x64
Linux bin/codegraph-roslyn-linux-x64

During development, set CODEGRAPH_ROSLYN_BIN to override the path to the binary.

About

Roslyn-based .NET extractor for @colbymchenry/codegraph. Parses VB.NET and C# source files using the .NET compiler APIs and outputs a JSON symbol graph (classes, methods, call edges, imports) for import into codegraph's SQLite index.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors