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:
The markup outside the regions is blanked out with its line breaks kept.
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.
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");
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.
## 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 main2026-11-09 11:50:16 +00:00
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 main2026-11-09 12:10:24 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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:
.razor,.cshtml@code { … },@functions { … }.aspx,.ascx,.master<script runat="server"> … </script><%@ Page/Control/Master Language="…" %>names; C# when it names noneHow it works:
"…",@"…",$@"…","""…"""), character literals and comments. A block inside a Razor comment@* … *@is not code.Class names
Counter.razor→Counter).Inheritsnames (Plant._Default→_Default), else the file's name. Visual Studio namesDefault.aspx's class_DefaultbecauseDefaultis a VB keyword..razor.cs,.cshtml.cs,.aspx.csand.aspx.vbare 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:
@onclick="IncrementCount",OnClick="BtnSave_Click");@(@Title());<% %>blocks (<%# GetTitle() %>);OnInitialized[Async],OnParametersSet[Async],OnAfterRender[Async],SetParametersAsync,ShouldRender,Dispose[Async]);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)
@{ … },@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.Filenode only.Tests
@codeblock is not code.@onclick-wired, a lifecycle hook, called-from-code only (not), and label text (not).Inherits, lines,Page_LoadandOnClickentry points, a call edge; a client-side<script>is ignored;Language.Inheritswith an assembly qualifier, aRegisterdirective andCodeFileBaseClassignored.Ran locally:
-D warningson graph, agent and mcp;🤖 Generated with Claude Code