Repository navigation
feat(extract): link XAML ViewModels and bindings - #1473
MikeKatsoulakis wants to merge 1 commit into
Conversation
…rences (#1473) Builds on the initial XAML support (#1460). Resolves a view to its ViewModel from an explicit <Window.DataContext><vm:MainViewModel/>, a design-time d:DataContext="{d:DesignInstance Type=...}", the View->ViewModel naming convention, or Prism ViewModelLocator.AutoWireViewModel="True". Resolution is always against an actually-extracted C# class node, so a name matching no class (or an ambiguous 2+) emits no edge -- explicit DataContext is EXTRACTED, convention/Prism are INFERRED. Also extracts binding paths ({Binding User.Name}, Path=Order.Total), commands (Command="{Binding SaveCommand}"), converters, and CommunityToolkit [ObservableProperty]/[RelayCommand] generated members. The #1460 event-handler hardening is preserved unchanged: events still resolve only to methods with a .NET (object sender, ...EventArgs e) signature, and the free-form-attribute denylist still prevents values like Content="Save" from fabricating event edges (both regression tests still pass). ViewModel discovery is bounded to the active extraction root. Ported from PR #1473 by @MikeKatsoulakis (clean 3-way merge onto current v8). Maintainer fix on top: the CommunityToolkit member reader now reads the code-behind with errors="replace", so a non-UTF8 ViewModel .cs can't raise UnicodeDecodeError and abort extract_xaml (matches every other reader in the module). Added a regression test for that case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks @MikeKatsoulakis — strong follow-up to #1460. The ViewModel resolution is exactly the kind of careful work I hoped for: it resolves against actually-extracted C# class nodes and refuses to emit an edge when the name matches no class or an ambiguous 2+, with EXTRACTED for explicit DataContext and INFERRED for naming/Prism conventions. The binding-path/command/converter extraction and CommunityToolkit member synthesis are clean, and — importantly — the #1460 event-handler signature gate and the free-form-attribute denylist are preserved unchanged (both regression tests still pass). Landed on |
Dates the 0.8.50 CHANGELOG and bumps the version. Highlights: WPF/XAML extraction + ViewModel/binding links (#1460/#1473), Objective-C relationship fixes (#1475), .vue SFC grammar fix (#1468), Metal shader indexing (#1480), Java field/annotation references (#1485/#1487), portable wiki links (#1444), *_BASE_URL backend overrides (#1458), non-streaming OpenAI-compatible calls (#1223), reflect --if-stale sidecar freshness (#1470), label --missing-only (#1481), canvas grid + case-fold dedup (#1452/#1453), the Read|Glob hook extension fix (#1463), and the no-API-key skill clarification (#1461). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rences (Graphify-Labs#1473) Builds on the initial XAML support (Graphify-Labs#1460). Resolves a view to its ViewModel from an explicit <Window.DataContext><vm:MainViewModel/>, a design-time d:DataContext="{d:DesignInstance Type=...}", the View->ViewModel naming convention, or Prism ViewModelLocator.AutoWireViewModel="True". Resolution is always against an actually-extracted C# class node, so a name matching no class (or an ambiguous 2+) emits no edge -- explicit DataContext is EXTRACTED, convention/Prism are INFERRED. Also extracts binding paths ({Binding User.Name}, Path=Order.Total), commands (Command="{Binding SaveCommand}"), converters, and CommunityToolkit [ObservableProperty]/[RelayCommand] generated members. The Graphify-Labs#1460 event-handler hardening is preserved unchanged: events still resolve only to methods with a .NET (object sender, ...EventArgs e) signature, and the free-form-attribute denylist still prevents values like Content="Save" from fabricating event edges (both regression tests still pass). ViewModel discovery is bounded to the active extraction root. Ported from PR Graphify-Labs#1473 by @MikeKatsoulakis (clean 3-way merge onto current v8). Maintainer fix on top: the CommunityToolkit member reader now reads the code-behind with errors="replace", so a non-UTF8 ViewModel .cs can't raise UnicodeDecodeError and abort extract_xaml (matches every other reader in the module). Added a regression test for that case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Dates the 0.8.50 CHANGELOG and bumps the version. Highlights: WPF/XAML extraction + ViewModel/binding links (Graphify-Labs#1460/Graphify-Labs#1473), Objective-C relationship fixes (Graphify-Labs#1475), .vue SFC grammar fix (Graphify-Labs#1468), Metal shader indexing (Graphify-Labs#1480), Java field/annotation references (Graphify-Labs#1485/Graphify-Labs#1487), portable wiki links (Graphify-Labs#1444), *_BASE_URL backend overrides (Graphify-Labs#1458), non-streaming OpenAI-compatible calls (Graphify-Labs#1223), reflect --if-stale sidecar freshness (Graphify-Labs#1470), label --missing-only (Graphify-Labs#1481), canvas grid + case-fold dedup (Graphify-Labs#1452/Graphify-Labs#1453), the Read|Glob hook extension fix (Graphify-Labs#1463), and the no-API-key skill clarification (Graphify-Labs#1461). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Adds deeper WPF/XAML graph extraction on top of the initial XAML support.
This branch resolves XAML views to ViewModels from:
<Window.DataContext><vm:MainViewModel /></Window.DataContext>/ equivalentDataContextelementsd:DataContext="{d:DesignInstance Type=...}"SettingsView->SettingsViewModelViewModelLocator.AutoWireViewModel="True"It also extracts richer binding references:
{Binding User.Name},{Binding Path=Order.Total}Command="{Binding SaveCommand}"Converter={StaticResource MoneyConverter}<Binding Path="..." Converter="..." />This adds support for common WPF MVVM patterns/frameworks:
DataContextpatterns[ObservableProperty] private string userName;-> inferredUserName[ObservableProperty]on the line above a field -> inferred generated property[RelayCommand] private void Save()-> inferredSaveCommand[RelayCommand] private async Task SaveAsync()-> inferredSaveCommandInvokeCommandAction Command="{Binding SaveCommand}"Inference is conservative:
INFERRED[RelayCommand].gitignore/.graphifyignore.csscans inside the active extraction rootWhy
WPF apps often split UI behavior across
.xaml,.xaml.cs, ViewModels, binding paths, commands, converters, and MVVM framework conventions. Without these links, graphify can see the files but misses the relationships that explain how UI flows into application code.This makes WPF/XAML more useful in the graph:
Scope
This is WPF/XAML-oriented support.
WinUI, MAUI, Avalonia, and other XAML-based stacks may get some collateral benefit where their syntax overlaps with WPF/XAML, but they are not the focus of this PR or the previous WPF PR. I am not a WinUI/MAUI expert, so I would not want to claim direct support unless someone specifically asks for it and provides real examples.
If there are issues, bugs, or additions needed for further WPF support, please tag me: @MikeKatsoulakis.
Tests
Added focused fixtures and tests for:
DataContextDataContext.graphifyignorebehaviorValidated with:
Local full-suite note:
uv run --frozen pytest tests/ -qstill fails on this Windows checkout with existing platform/path/skillgen baseline failures; the targeted .NET/XAML checks above pass.Security Review
A security pass found that ViewModel lookup could scan
.csfiles outside the requested extraction boundary and repeat scans per XAML file. This branch fixes that by bounding lookup to the active extraction root, respecting ignore files, and caching the class scan during extraction.No XML entity expansion, regex DoS, or graph-label injection issue was found.