feat(graph): Razor and Web Forms code in the code graph (t84) #944

Merged
sharang merged 1 commits from feat/t84-razor-webforms into main 2026-11-09 12:10:24 +00:00
Owner

What

This is part 2 of item 3 of t84, stacked on #943 (the VB parser), which it needs for pages written in VB. Base it on main once #943 is merged.

The code regions of ASP.NET markup files now feed the code graph:

Files Code region Language
.razor, .cshtml @code { … }, @functions { … } C#
.aspx, .ascx, .master <script runat="server"> … </script> what <%@ Page/Control/Master Language="…" %> names; C# when it names none

How it works:

  1. The markup outside the regions is blanked out with its line breaks kept.
  2. Each region is wrapped in the file's class, so the existing C# or VB parser reads the members. Every line it reports is the markup file's own line; no re-mapping is needed.
  3. Razor brace matching skips C# strings ("…", @"…", $@"…", """…"""), character literals and comments. A block inside a Razor comment @* … *@ is not code.

Class names

  • Razor: the file's name (Counter.razor → Counter).
  • Web Forms: the class the directive's Inherits names (Plant._Default → _Default), else the file's name. Visual Studio names Default.aspx's class _Default because Default is a VB keyword.
  • Code-behind files: .razor.cs, .cshtml.cs, .aspx.cs and .aspx.vb are plain C#/VB and were already read. Their partial class is a separate node, as partial classes in two files already are.

Entry points

The framework calls these methods, so they are entry points:

  • methods the markup refers to:
    • in a tag's attribute values (@onclick="IncrementCount", OnClick="BtnSave_Click");
    • right after an @ (@Title());
    • in <% %> blocks (<%# GetTitle() %>);
  • Blazor lifecycle hooks (OnInitialized[Async], OnParametersSet[Async], OnAfterRender[Async], SetParametersAsync, ShouldRender, Dispose[Async]);
  • Web Forms AutoEventWireup handlers (Page_Load, Page_Init, Page_PreRender, …).

Text between tags doesn't count: a button labelled "Save" doesn't make Save() an entry point.

Left out (stated, not silent)

  • Inline Razor (@{ … }, @if, @foreach, @x.Y()) and Web Forms render blocks (<% … %>): they mix code with markup. Their calls don't become edges; they only mark entry points as above.
  • .vbhtml (VB Razor) is not read.
  • A markup file without code regions is a File node only.

Tests

  • Razor component:
    • the class and its methods, with the markup file's line span;
    • braces in strings, verbatim strings and comments;
    • a commented-out @code block is not code.
  • Entry points: @onclick-wired, a lifecycle hook, called-from-code only (not), and label text (not).
  • Web Forms:
    • a VB page: class from Inherits, lines, Page_Load and OnClick entry points, a call edge; a client-side <script> is ignored;
    • a C# control without a Language.
  • Directive: VB with single quotes, Inherits with an assembly qualifier, a Register directive and CodeFileBaseClass ignored.
  • Edge cases: a view without code, class names made identifiers, and the registry routing all five extensions.

Ran locally:

  • fmt;
  • clippy -D warnings on graph, agent and mcp;
  • lib tests: graph 116, agent 1021;
  • agent integration tests against Mongo: 97 passed, 0 failed.

🤖 Generated with Claude Code

## What This is part 2 of item 3 of t84, stacked on #943 (the VB parser), which it needs for pages written in VB. **Base it on main once #943 is merged.** The code regions of ASP.NET markup files now feed the code graph: | Files | Code region | Language | |---|---|---| | `.razor`, `.cshtml` | `@code { … }`, `@functions { … }` | C# | | `.aspx`, `.ascx`, `.master` | `<script runat="server"> … </script>` | what `<%@ Page/Control/Master Language="…" %>` names; C# when it names none | How it works: 1. The markup outside the regions is blanked out with its line breaks kept. 2. Each region is wrapped in the file's class, so the existing C# or VB parser reads the members. Every line it reports is the markup file's own line; no re-mapping is needed. 3. Razor brace matching skips C# strings (`"…"`, `@"…"`, `$@"…"`, `"""…"""`), character literals and comments. A block inside a Razor comment `@* … *@` is not code. ### Class names - **Razor:** the file's name (`Counter.razor` → `Counter`). - **Web Forms:** the class the directive's `Inherits` names (`Plant._Default` → `_Default`), else the file's name. Visual Studio names `Default.aspx`'s class `_Default` because `Default` is a VB keyword. - **Code-behind files:** `.razor.cs`, `.cshtml.cs`, `.aspx.cs` and `.aspx.vb` are plain C#/VB and were already read. Their partial class is a separate node, as partial classes in two files already are. ### Entry points The framework calls these methods, so they are entry points: - methods the markup refers to: - in a tag's attribute values (`@onclick="IncrementCount"`, `OnClick="BtnSave_Click"`); - right after an `@` (`@Title()`); - in `<% %>` blocks (`<%# GetTitle() %>`); - Blazor lifecycle hooks (`OnInitialized[Async]`, `OnParametersSet[Async]`, `OnAfterRender[Async]`, `SetParametersAsync`, `ShouldRender`, `Dispose[Async]`); - Web Forms AutoEventWireup handlers (`Page_Load`, `Page_Init`, `Page_PreRender`, …). Text between tags doesn't count: a button labelled "Save" doesn't make `Save()` an entry point. ### Left out (stated, not silent) - **Inline Razor** (`@{ … }`, `@if`, `@foreach`, `@x.Y()`) and **Web Forms render blocks** (`<% … %>`): they mix code with markup. Their calls don't become edges; they only mark entry points as above. - **`.vbhtml`** (VB Razor) is not read. - A markup file **without code regions** is a `File` node only. ## Tests - **Razor component:** - the class and its methods, with the markup file's line span; - braces in strings, verbatim strings and comments; - a commented-out `@code` block is not code. - **Entry points:** `@onclick`-wired, a lifecycle hook, called-from-code only (not), and label text (not). - **Web Forms:** - a VB page: class from `Inherits`, lines, `Page_Load` and `OnClick` entry points, a call edge; a client-side `<script>` is ignored; - a C# control without a `Language`. - **Directive:** VB with single quotes, `Inherits` with an assembly qualifier, a `Register` directive and `CodeFileBaseClass` ignored. - **Edge cases:** a view without code, class names made identifiers, and the registry routing all five extensions. Ran locally: - fmt; - clippy `-D warnings` on graph, agent and mcp; - lib tests: graph 116, agent 1021; - agent integration tests against Mongo: 97 passed, 0 failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang changed target branch from feat/t84-vb-razor to main 2026-11-09 11:50:16 +00:00
sharang added 1 commit 2026-11-09 11:50:16 +00:00
feat(graph): Razor and Web Forms code in the code graph (t84)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m19s
CI / Check (pull_request) Successful in 19m26s
f4b50459ee
The code regions of ASP.NET markup files are now parsed: @code and
@functions blocks of .razor and .cshtml files, and <script runat="server">
blocks of .aspx, .ascx and .master files, in C# or, as the page directive
says, VB. The markup around them is blanked out with its line breaks kept
and each region is wrapped in the file's class, so the C# and VB parsers
read the members and report the markup file's own lines.

Methods the markup refers to (@onclick="Save", OnClick="BtnSave_Click",
<%# Title() %>) and the framework's lifecycle hooks (OnInitialized,
Page_Load) are entry points. A markup file without code regions is a file
node. Inline Razor and <% %> render blocks are left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 29d3c91f5a into main 2026-11-09 12:10:24 +00:00
Sign in to join this conversation.