Repository navigation
Add JSONPath search to CodeBlock - #78
hannesstruss wants to merge 6 commits into
Conversation
r0adkll
left a comment
There was a problem hiding this comment.
🤖 Review notes on the JSONPath search. Two things to fix before merge are in the comments on CodeBlockNodeContent.kt:130 (scroll position resets) and CodeBlock.kt:64 (protocol version). The other comments are performance and polish notes. They're mostly about large payloads and can be follow-ups.
One more that isn't in the diff: docs/reference/ui.md (CodeBlock row around line 48) still lists only content, language, searchable and initialTreeState. It should document searchPlacement and the $-prefixed JSONPath behaviour.
JSONPath4K retains references to its default Napier listener even when a custom compiler is supplied. Desktop ProGuard and Android R8 both fail to resolve those references when Napier is excluded.
r0adkll
left a comment
There was a problem hiding this comment.
🤖 Thanks for the update. It addresses all of the earlier feedback, so I've resolved those threads. One new issue is left, in the comment below.
| // one job per CodeBlock run at a time so rapid payload changes cannot pile up work. | ||
| val pathDispatcher = remember { Dispatchers.Default.limitedParallelism(1) } | ||
| var document by remember(json) { mutableStateOf<JsonElement?>(null) } | ||
| var pathResult by remember(json, isJsonPath) { mutableStateOf<String?>(null) } |
There was a problem hiding this comment.
🤖 Content updates flash the full document while a JSONPath query is active. pathResult is still remembered under json, and the collector below restarts on LaunchedEffect(json, isJsonPath). So when the guest sends a new content patch while a $ query is showing:
pathResultresets tonull,displayedPathbecomes null, andkey(displayedPath != null)switches to the full, unfiltered document.- The restarted
snapshotFlow { query }.debounce(...)waits the full 200 ms before its first emission, even though the query hasn't changed. Then it parses and evaluates. - The key switches back and JsonTree is rebuilt with the result.
With live data such as the network inspector, the view keeps flipping between the whole document and the filtered result. Before this change it flipped to a spinner, which was less jarring.
Suggestion: remember pathResult (and invalidPath) by isJsonPath only, so the last result stays on screen until the new one replaces it. Also skip the debounce for the first evaluation after json changes, e.g. evaluate the current query right away when the effect starts, then drop(1) and debounce later edits. A test like ordinaryTreeKeepsItsScrollPositionAcrossPayloadUpdates, but with a $ query active, would cover it.
There was a problem hiding this comment.
🤖 Automated reply: Fixed in a7e01cf. The typing debounce runs separately from payload updates, so new payloads reuse the settled query. The last filtered tree stays visible until its replacement is ready. A loader appears before the first result.
The regression test checks that the result advances during rapid updates and the unfiltered document stays hidden. Here’s the Playground demo with $.tick active:

Searchable JSON CodeBlocks evaluate queries beginning with
$as JSONPath and show an array of matching values. Type\$to search for a literal dollar sign. Ordinary queries keep text highlighting, next/previous navigation, and scroll position when the payload changes.JSONPath waits for typing to pause and keeps the previous result visible while editing the query for the same payload. Small results open expanded, and large results start collapsed below the root. The compact field defaults to the top, with an option to put it underneath and a help button linking to Livewire’s reference.
Compatibility
CodeBlocksignature. The Android JSONPath4K artifact requires API 30 for apps embedding the Androidhost-uirenderer. The Android client does not depend on JSONPath4K.Validation