Blazor: .razor files are parsed as raw C#, so members of `@code { }` are lost and most components report parse_unusable (0.12.1)

Aperta
#3,055 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp

Direzione di ricerca

Start by reading the .razor parsing path and the existing .razor.cs handling, then compare their graph output using the provided Pages/Items.razor example. Check get_file_outline and parse status after extracting component members; done means markup no longer breaks parsing and the @code members appear in the graph. The requested support for directives and markup call edges extends the scope.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug parsing/quality

Version: 0.12.1 (also 0.11.0), macOS arm64, index_repository mode full or fast.

Since #1824, .razor files are discovered and @page emits a Route node. However, the whole file appears to be handed to the C# grammar as it is. Razor markup (<h1>, @if (...) { <p>…</p> }, @onclick="...") and directives are not C#. Inside @code { }, members that are not valid as statements (properties, attributed members) produce errors too. The result:

  • In a real Blazor app, 108 of ~150 .razor files come back parse_unusable and 43 more parse_partial.
  • The component's methods, fields and properties are mostly missing from the graph, so search_graph / trace_path can't see the C# that most Blazor apps keep in @code.
Repro

Pages/Items.razor:

@page "/items"
@implements IDisposable
@inject NavigationManager Nav

<h1>Items</h1>
@if (error is not null)
{
    <p class="error">@error</p>
}
@foreach (var item in items)
{
    <button @onclick="() => Select(item)">@item</button>
}

@code {
    [Parameter, SupplyParameterFromQuery(Name = "q")] public string? Query { get; set; }
    [Parameter] public int? Page { get; set; }

    List<string> items = [];
    string? error;

    protected override async Task OnInitializedAsync()
    {
        items = await Load();
    }

    Task<List<string>> Load() => Task.FromResult(new List<string> { "a", "b" });

    void Select(string item) => Nav.NavigateTo($"/items/{item}");

    public void Dispose() { }
}

get_file_outline for Pages/Items.razor:

/items    Route     -
@inject   Function  2-32

parse_partial error ranges: 1-1,3-3,5-6,6-6,8-8,9-9,10-10,11-11,12-12,12-27.

Control: the same @code body as public partial class Items { … } in Pages/Items.cs gives class Items, the fields Query, Page, items and error, and the methods OnInitializedAsync, Load, Select and Dispose. (The two properties are labelled Field there, but they are found.)

A component with only simple members (fields and methods, no markup, no properties) parses almost cleanly. Adding two properties in a row, or any markup before @code, is enough to lose members.

Expected

For a .razor file:

  1. Take the bodies of @code { … } (and @functions { … }) and parse them as members of a class named after the file (Items, namespace from folder or @namespace), the same as a .razor.cs code-behind partial class.
  2. Use @inherits, @implements, @inject Type Name and @attribute as the class's base type, interfaces, injected members and attributes.
  3. Skip the markup, or at least don't let it break the @code parse. Calls from markup such as @onclick="() => Select(item)" or @Method() would be a bonus as CALLS edges from the component.

Related: #1667 / #1824 (discovery and @page routes), #2229.

Lingua principale
C
Stelle
45.8k
Fork
3.8k
Merge medio
2g 18h
PR unite (30g)
108

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DeusData/codebase-memory-mcp

Tutte le issue di DeusData/codebase-memory-mcp

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.