Show text-based resources inline with syntax highlighting#3861
Merged
Conversation
Textual assembly resources (JSON, XML, Markdown, plain text, ...) rendered as an opaque byte count with only a Save button. Detect text vs binary from the payload (size cap, BOM-aware decoding, strict UTF-8, rejecting control characters) and pick a highlighting extension by resource-name extension, falling back to content sniffing (angle-bracket for XML/HTML, an actual JsonDocument parse for JSON) when the extension is unknown. Text renders as the view's whole content with the matching highlighting; binary keeps the byte-count-plus-Save presentation. Container resources unpack their entries as raw byte arrays. Route those through the same IResourceNodeFactory pipeline as top-level resources so a nested .baml gets the BAML view, an image its viewer, and so on, instead of the generic byte node; the .resources and !AvaloniaResources views also list their entries by name. Register built-in AvaloniaEdit definitions (JSON, Markdown, ...) with the theme manager on lookup so they follow the dark theme like the bundled ones. Assisted-by: Claude:claude-fable-5:Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Textual assembly resources (JSON, XML, Markdown, plain text, ...) previously rendered as an opaque byte count with only a Save button. They now display inline in the decompiler text view with the correct syntax highlighting.
Detection
New
TextResourceDetector.TryDetectText:.json/.md/.js/.css/.html/.py/.sql/.ps1/... -> AvaloniaEdit built-ins). Unknown or missing extensions are content-sniffed: leading<is XML (or HTML on<!DOCTYPE html/<html), and{/[payloads are parsed withJsonDocumentbefore claiming JSON. Everything else displays as plain text.Display
The generic resource nodes (
ResourceEntryNode,ResourceTreeNode) render detected text as the view's whole content and setSyntaxExtensionOverrideaccordingly, mirroring how the XML/XAML nodes present theirs. Binary resources keep the byte-count-plus-Save presentation unchanged.Container routing
.resourcesand!AvaloniaResourcescontainers unpack their entries as raw byte arrays.ResourceEntryNode.Create(string, byte[])now dispatches those through the sameIResourceNodeFactorypipeline as top-level resources, so a nested.bamlgets the BAML view, an image its viewer, and so on, instead of the generic byte node. Both container views also list their entries by name.Theming
HighlightingService.GetByExtensionregisters whatever definition it resolves with the theme manager, so AvaloniaEdit's built-in definitions (JSON, Markdown, ...) follow the dark theme like the bundled ones.Tests
TDD throughout. 31 new tests in
TextResourceDetectionTests(encodings, binary rejection, no-read guarantee for oversized payloads, extension mapping, content sniffing, node-level rendering) plus factory-routing and entry-listing tests inResourceFactoryTests. FullILSpy.Testssuite green (1013/1013). Verified in the running app on Linux against a mixed-resource fixture and a real!AvaloniaResourcesbundle.A security review of the branch (untrusted resource bytes/names) found no exploitable issues: no XML parsing of resource content (prefix sniff only, no XXE),
JsonDocumentis a pure syntactic parser behind a size cap, attacker-controlled names reach only a literal whitelist, and no new file I/O. Nested-container reachability was checked and does not auto-recurse (resource nodes returnFilterResult.Match) and cannot nest infinitely (each level is a strict sub-slice of its parent).This PR was authored by an AI agent (Claude Code) operated by @siegfriedpammer and reviewed and manually verified by him.
🤖 Generated with Claude Code