Skip to content

feat: add XAML extraction support - #1460

Closed
MikeKatsoulakis wants to merge 1 commit into
Graphify-Labs:v8from
MikeKatsoulakis:feat-xaml-extraction
Closed

MikeKatsoulakis wants to merge 1 commit into
Graphify-Labs:v8from
MikeKatsoulakis:feat-xaml-extraction

Conversation

@MikeKatsoulakis

@MikeKatsoulakis MikeKatsoulakis commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1456.

What

Adds basic WPF/XAML structural extraction without a new parser dependency.

This PR makes .xaml files first-class code inputs and extracts:

  • the XAML file/root element
  • named controls from x:Name / Name
  • simple {Binding ...} references
  • x:Class references
  • event-handler references that resolve to methods on the matching .xaml.cs partial class

Why

WPF projects keep important frontend structure in XAML, but graphify currently skips .xaml files. That means UI controls, bindings, view classes, and event handlers are invisible in the graph even though the matching C# code-behind is already extractable.

Resolving x:Class and event handlers gives the graph a useful bridge from the view markup to the C# partial class and methods without turning this into a full WPF analyzer.

XAML coverage in this PR

Added now:

  • .xaml file discovery and dispatch
  • root element extraction (Window, UserControl, etc.)
  • control nodes for elements with x:Name or Name
  • control type references (Button, TextBox, StackPanel, etc.)
  • simple {Binding PropertyName} references
  • x:Class="Namespace.Type" links to the matching .xaml.cs partial class when present
  • event-handler links from XAML attributes to methods on that partial class

Deferred deeper analysis:

  • StaticResource / DynamicResource and resource dictionary resolution
  • merged dictionaries, styles, templates, and control templates
  • complex binding paths, converters, commands, and DataContext / ViewModel inference
  • routed event bubbling semantics
  • cross-file resolution between XAML views and separate ViewModel classes

Changes

  • graphify/detect.py: add .xaml to CODE_EXTENSIONS
  • graphify/extract.py: add extract_xaml() and dispatch registration
  • tests/fixtures/sample.xaml / sample.xaml.cs: add a small WPF fixture pair
  • tests/test_dotnet.py: cover XAML class resolution, named controls, bindings, and event-handler links
  • tests/test_languages.py: add the contribution-path XAML smoke test
  • README.md: document .xaml in the supported file extensions table

Testing

  • uv run pytest tests/test_dotnet.py tests/test_languages.py::test_xaml_finds_class_and_event_references -q
  • uv run ruff check graphify tests --select E9,F63,F7,F82

Full uv run pytest tests/ -q was attempted locally on Windows, but existing unrelated Windows/path and install/skillgen failures prevent a clean full-suite result on this machine.

@MikeKatsoulakis
MikeKatsoulakis marked this pull request as ready for review June 25, 2026 11:30
safishamsi pushed a commit that referenced this pull request Jun 25, 2026
…#1460)

Makes .xaml a first-class code input. extract_xaml() uses stdlib XML (no new
parser dependency) behind the same DOCTYPE/ENTITY and size guards as the .csproj
extractor, and captures: the root element, named controls (x:Name/Name) and their
control types, {Binding ...} references, x:Class, and -- the useful part -- a
bridge from the view markup to its .xaml.cs code-behind by resolving event-handler
attributes to the matching methods on the partial class.

Ported from PR #1460 by @MikeKatsoulakis onto current v8.

Maintainer hardening on top of the original PR: event resolution is now gated so
it can't fabricate edges. The original matched any attribute value against
code-behind method names, so Content="Save" next to a business method Save(), or
Tag="<a-handler-name>", produced spurious "event" edges. Resolution now requires
(a) the attribute is not a known free-form/identity property (Content, Text, Tag,
Title, ToolTip, Header, ...), (b) the value is a bare identifier, and (c) the
matched method actually has the .NET event-handler signature
(object sender, <T>EventArgs e) -- read from the code-behind source since the C#
extractor does not record parameter lists on method nodes. Added regression tests
for both false-positive cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks @MikeKatsoulakis — this is a genuinely useful addition, and the code-behind bridge (resolving x:Class and event handlers to the matching .xaml.cs partial class) is the right idea. I especially liked that it scopes handler matching to the partial class's own method edges and reuses the existing XML safety guards (DOCTYPE/ENTITY rejection + size cap), so there's no new attack surface and no new parser dependency.

Landed on v8 in 7dc5d96 with your authorship preserved.

One change I made on top before merging: tightened event-handler resolution so it can't create false edges. The original matched any attribute value against code-behind method names, so in real WPF a property like Content="Save" next to a business method Save(), or Tag="...", would produce a spurious event edge (I could reproduce this). Resolution now requires three things: the attribute isn't a known free-form/identity property (Content, Text, Tag, Title, ToolTip, Header, …), the value is a bare identifier, and the matched method actually has the .NET event-handler signature (object sender, …EventArgs e) — read from the code-behind source, since the C# extractor doesn't record parameter lists on method nodes. Added regression tests for both false-positive cases.

Full suite (2417 passed) + skillgen guards green, and I verified the end-to-end bridge on the fixture (3 real events, x:Class, binding, all events resolving to code-behind methods).

The deferred items you listed (resource dictionaries, styles/templates, converters, ViewModel inference, cross-file view↔VM resolution) are good follow-ups if you want to keep going. Closing as merged-by-port — thanks for the contribution.

@safishamsi safishamsi closed this Jun 25, 2026
safishamsi pushed a commit that referenced this pull request Jun 26, 2026
…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]>
safishamsi added a commit that referenced this pull request Jun 27, 2026
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]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…Graphify-Labs#1460)

Makes .xaml a first-class code input. extract_xaml() uses stdlib XML (no new
parser dependency) behind the same DOCTYPE/ENTITY and size guards as the .csproj
extractor, and captures: the root element, named controls (x:Name/Name) and their
control types, {Binding ...} references, x:Class, and -- the useful part -- a
bridge from the view markup to its .xaml.cs code-behind by resolving event-handler
attributes to the matching methods on the partial class.

Ported from PR Graphify-Labs#1460 by @MikeKatsoulakis onto current v8.

Maintainer hardening on top of the original PR: event resolution is now gated so
it can't fabricate edges. The original matched any attribute value against
code-behind method names, so Content="Save" next to a business method Save(), or
Tag="<a-handler-name>", produced spurious "event" edges. Resolution now requires
(a) the attribute is not a known free-form/identity property (Content, Text, Tag,
Title, ToolTip, Header, ...), (b) the value is a bare identifier, and (c) the
matched method actually has the .NET event-handler signature
(object sender, <T>EventArgs e) -- read from the code-behind source since the C#
extractor does not record parameter lists on method nodes. Added regression tests
for both false-positive cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…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]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants