feat(plugins): diffs of up to 8 MiB per side from open-diff (#3445)

views.open-diff and content tab reply diffs accept 8 MiB per side (was 1 MiB). A larger side fails with invalid("diff too large: the <side> side is over 8 MiB") from the host call and "Diff too large" for a web view's open-diff message, so plugins can tell the size limit from a malformed request. WIT docs updated and plugin components rebuilt.
This commit is contained in:
l0ng-ai
2026-11-15 03:32:29 +08:00
committed by GitHub
parent 519c8ad8fc
commit ea644dcdb0
93 changed files with 110 additions and 56 deletions
+37 -2
View File
@@ -77,9 +77,22 @@ pub(super) fn validate_reply(reply: &ContentTabReply) -> Result<(), HostError> {
Ok(())
}
/// Largest side of a plugin diff, in UTF-16 code units (earlier hosts allowed 1 MiB).
pub(super) const MAX_DIFF_SIDE: usize = 8 << 20;
fn diff_side(value: &str, side: &str) -> Result<(), HostError> {
if value.contains('\0') {
return Err(HostError::Invalid(format!("the {side} side of the diff contains NUL")));
}
if value.encode_utf16().count() > MAX_DIFF_SIDE {
return Err(HostError::Invalid(format!("diff too large: the {side} side is over {} MiB", MAX_DIFF_SIDE >> 20)));
}
Ok(())
}
pub(super) fn validate_diff(diff: &ide_plugin::ContentDiff) -> Result<(), HostError> {
body(&diff.left)?;
body(&diff.right)?;
diff_side(&diff.left, "left")?;
diff_side(&diff.right, "right")?;
for value in [&diff.left_label, &diff.right_label].into_iter().flatten() {
label(value, 128)?;
}
@@ -571,3 +584,25 @@ impl PluginHost {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn diff(left: String, right: String) -> ide_plugin::ContentDiff {
ide_plugin::ContentDiff { left, right, left_label: None, right_label: None, title: None }
}
#[test]
fn diff_sides_up_to_the_limit_open_and_larger_ones_say_why() {
assert!(validate_diff(&diff("x".repeat(5 << 20), "y".repeat(MAX_DIFF_SIDE))).is_ok());
let err = validate_diff(&diff(String::new(), "y".repeat(MAX_DIFF_SIDE + 1))).unwrap_err();
assert!(
matches!(&err, HostError::Invalid(m) if m == "diff too large: the right side is over 8 MiB"),
"{err:?}"
);
assert!(
matches!(validate_diff(&diff("a\0".into(), String::new())), Err(HostError::Invalid(m)) if m.contains("NUL"))
);
}
}
Binary file not shown.
@@ -1 +1 @@
e616b87b24371581ad648f9c7072259de7732d122b5887b488f7bd480ebd69c2
0b77e7a414ec3b0dd1f41e5658b981f059dd842743dbe2f06e5d428f5b9570f9
Binary file not shown.
@@ -1 +1 @@
75eeecc467bff141bda14f1f080633348af348f7259e793be81e6548d2008669
6f7d6527837c8e5c86c377479cceef5116decd61666b28f36dd11332e36e9934
Binary file not shown.
@@ -1 +1 @@
4aaf7754e895f022d34dad05bd2b8018e3a61ba18771b8c95d9f070cb212530c
c1ac86a5b4d45b55013e6e00dcb83deda33b759ecc366c3fdf57739bdd22cbff
Binary file not shown.
@@ -1 +1 @@
e573144879a7caa0975e17b233476eb317ff54bef23fd8fa64280d3649bad700
e4d8d8f5f5849b912b2c0ebee6b91d60796c3070929d7698323e8ce4f200a38a
Binary file not shown.
@@ -1 +1 @@
36dd40ef751a617f1ad59491312889c12481b05666e580f21f7c2552df76edbc
e2e2fc44ad9cae9cf26a5bf706768d3786502f23db6994dc29695deb249ed73f
Binary file not shown.
@@ -1 +1 @@
724ed3bbd828e4fc1925c1b555bdaec9268633cb587806a661f8838e5a540545
61e1f0c43bbfddc35dcf40685169eb273777ddca13da534626e1699b47e8eac3
Binary file not shown.
@@ -1 +1 @@
1a3685234f1b3b0957184c44c603c0eefe7e3084b88d0df32da268b29292ee92
2ea1c1693db8638db996c9c47597f0c1635ef0a9c7dfb33685c515b7af95e6a6
Binary file not shown.
@@ -1 +1 @@
4283de821d69a18438f58062e4bc28b63ba5025cc5f9fa51f21ff475b677a6a5
3c788f6092b229484a5d94fd0e6f4651afc88dd0ab1b22b067d84614a6a0c85e
Binary file not shown.
@@ -1 +1 @@
0f25487b8e488e5ec01fabd2951bdb03d80bc26e4e9aa508394a7f9cd09d1759
18273599cc459833d6a30185a5f0ba127cdb4e22bc054a973571e530eb3a85ca
Binary file not shown.
@@ -1 +1 @@
80f9dc28e4f168dd22ccee1c53e1f6b08c446622eb10f07de29be5fc45e9fb1c
c9fafba362fa0745d7ee1685efe5582d432510003c04c98100eddd557bd1e2cf
Binary file not shown.
@@ -1 +1 @@
5355cb4ef373eba3c54806eb00294fcd5fccb3cf05dae3e1c2a4ad45ab958f03
4121009913709edeca8c5cb52d88dfcc2b16867bc06859768f73c17cf9c456a2
Binary file not shown.
@@ -1 +1 @@
fc75ede42e6db7619fa28fc8999f091d39e3c1ed401356db3a3f07de54287c99
b55bd202a06f5643c4f70abb6fb473fbe53af657f4e21a6d13581a23a726e085
Binary file not shown.
@@ -1 +1 @@
8793601496f1727cf912e4cdf86ec48fc340a17585098e98dee52a125cb8a16d
11a12228df67f9b94bd52375b5dddb2d955f7e5f88d7f9ea0a430b1db128f6ca
Binary file not shown.
@@ -1 +1 @@
fb2db14a645cad42941d20a25a3ff87ca6fdee635fdb40953383ff30ce16af8a
553ce6c57052f8ff2ea2526e88762d5a0aee2489cda192fc7ab708766078ccf7
Binary file not shown.
@@ -1 +1 @@
fc66b3b56a1ab1c9d547e3efe6bb4693dca908bb18be8b8ebd26f2fb41e4436c
7b43f8a2a06d7b2952f8d46727a4cce524fb2bdecee1035dad9c767261d276d0
Binary file not shown.
@@ -1 +1 @@
c76830df9dee3caba932ffaddaabce88ac7ef23b3957b3e8e570b4939dd58d9d
e994c69fda5eef94ae85d6dac5aec3d04fb6811c35c446c9d33236a449bd1c6c
@@ -1 +1 @@
3a41a06d54939a9e85fcf6b0bf15b336f928a3caf66576bd2da62c5b8b177c1d
c37f6a7ea9018ca636d0fd486a9d91cd397158615410de9b837ca9b8f9f593b7
Binary file not shown.
@@ -1 +1 @@
f30a8c0a7893519872628c001314efd567f87f4dfaf718a737ea3631b55881b0
1b298dfa5c1f2163d609ef0ccc3d42fafe78e69326002effe53abc4b82974749
Binary file not shown.
@@ -1 +1 @@
cb65533984ffd8684c9e9f5ddeef92a8f387735c12310b25282ee7bbf2d73cd7
1e11a95e0909d18308d21a9a8448f8b2e427d240d5d8cd13d8ddbe6ba5009237
Binary file not shown.
@@ -1 +1 @@
d11f9cb1130f3f3aaa89514bf47ec8ece9b2ca0edf1d82c11f80b262325f16be
d5cd77130cc97cffdbc742f04e3e1196f14160107b636806c6ef3c9b40724e84
Binary file not shown.
@@ -1 +1 @@
48ea4414469ebd70a89da8a5df7b7bddc4d32f5c50f1759ee3cea14558073c92
a0f74430b0a7d9ff48524d7aae4f8a0bd0fc60511e2a951dde9991b9bf7d15a9
Binary file not shown.
@@ -1 +1 @@
0c02303182be04ed3776fb532fd8b72e6057aa0fdb92b7d235000146fef4120e
65508f6e25bd0efc85820ae7d0f9037b58c778fa61e8498c5b9a5055cc38f6fc
Binary file not shown.
@@ -1 +1 @@
8162a70e848172663463119e6357984a73e54bc71a99b2845621d0733cf9333e
c86ed41d68c132f72eb8b5794f31b975492e5ad42e41b7823d1bf28ba118a262
Binary file not shown.
@@ -1 +1 @@
4524cab0ceac631153a945f6b76f7d40efd3c854740ae22c64580381e9532397
3da1a09906d803234016b3f9c30a88b9b40bf3187fc73840ff60a2e05f504b48
Binary file not shown.
@@ -1 +1 @@
a92f4def072ca4cc805414516ab4f046fc54bcf11394a5413a27ea151c156174
39e7a805120ce6433750c32b1d670b3caba990f7b15aea866a29c23b01cba708
Binary file not shown.
@@ -1 +1 @@
994fca61bc5a10f0229301406af76c188a9cb2f593db85a403c1ece746e9f7b5
5ec9be607955ce2aa4d921884df17c49af3ce98945f8fa641cec9a7f1b4d8384
Binary file not shown.
@@ -1 +1 @@
48eaf97f57cc08c3854a1effa37ebf29defca4782f76c7de1da6ef9a02c23441
f05df5c2faf1718ba9702be4d979c367ea8445a854794bb21e8e36b211f18122
Binary file not shown.
@@ -1 +1 @@
b896043cf261ff4bb19977f4648a736907fa897b8d4f0804077678a5895d1845
548cb8321b63b0685049fcf796dbc8390fcb22f3c1ffcfa09452e5a63382d27d
+5 -4
View File
@@ -445,7 +445,7 @@ matching SDK. Released 1.6 plugins keep working. New in 1.7:
two texts in the invoking window's diff viewer, for example a merge request's
file before and after; `file_name` picks the syntax highlighting. Web views
send `{ op: "open-diff", left, right, leftLabel?, rightLabel?, title?, fileName? }`.
Commands and events only; each side at most 1 MiB.
Commands and events only; each side at most 1 MiB (8 MiB on current hosts).
### API 1.5
@@ -669,7 +669,7 @@ then run `openidea-plugin check`.
| `host::write_terminal(key, text)` | `views.write-terminal` | API 1.4: write only to this plugin's still-running terminal in this window; trusted project, commands/events only. |
| `host::open_content_tab(tab)` | `views.open-content-tab` | API 1.4: the shared content editor protocol, without a web view; actions arrive as `content-tab-action`. |
| `host::reply_content_tab(request_id, reply)` | `views.reply-content-tab` | API 1.4: reply to an owned action in the originating window. No capability; commands/events only. |
| `host::open_diff(diff, file_name)` | `views.open-diff` | API 1.7: two texts in the invoking window's diff viewer; `file_name` (at most 256 characters) picks the highlighting. Commands/events only; each side at most 1 MiB. |
| `host::open_diff(diff, file_name)` | `views.open-diff` | API 1.7: two texts in the invoking window's diff viewer; `file_name` (at most 256 characters) picks the highlighting. Commands/events only; each side at most 8 MiB (earlier hosts: 1 MiB), a larger side fails with `Invalid("diff too large: …")`. |
| `RunConfigurations::configurations(root)` | export `run-configurations.configurations` | API 1.4: optional `plugin-run-configurations` world; SDK registration `run_configurations`. Full project list, refreshed on configuration listing. |
| `TestResults::parse(config, chunk)` | export `test-results.parse` | API 1.4: optional `plugin-test-results` world; SDK registration `test_results`. Bounded output batches for `framework = "plugin"`; failures use built-in parsers. |
| `TestResults::select_tests(config, tests)` | export `test-results.select-tests` | API 1.4: full replacement argv for test-tree name paths, or `None` when unsupported (the SDK default). Enables rerunning failed tests and running tree selections. |
@@ -1883,8 +1883,9 @@ are forwarded to the originating desktop window.
with the same content, action, reply and diff behavior. Its key is scoped to the
plugin and window, independently of web views. Save and toolbar actions arrive
as `content-tab-action`; answer with `host::reply_content_tab(request_id, reply)`.
The host accepts replies only from that plugin and window. Content and diff text
are limited to 1 Mi UTF-16 units, with at most 16 actions and one Save action.
The host accepts replies only from that plugin and window. Content is limited to
1 Mi UTF-16 units and each side of a diff to 8 Mi, with at most 16 actions and one
Save action.
### Plugin-backed content editor tabs (API 1.3)
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
56008cb5a36b35b8975b95da971212c95c165de378b0c8b7f7b428d9d9332ec1
93f5619378f0edaf2e78a95b38e92e6e14ffc4377aab425d575dbbcb30c7c3e4
Binary file not shown.
@@ -1 +1 @@
d87e571ebe16283bbffcc7525f69755d5faffb4693ff4a5183de67418976086b
007134d609d842c6f57386e35a6725948ad17fdd6458a2e209398ee38d034a23
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
254da92cdb20bdf432b5bb4e90ef9bdfaff92eca7195fbff38127f47fa231e6e
01d5abc7a65811684cac58e39d733218d5cde46681b7e57231897f6a07318133
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
50ea437aa2b99dc28afd51286fbac7e07d8386f826f222c517a8bd6e4f647a1a
9b29d2a047e223ecd432fb90914c684f708eb8becba6cc72cd55462064d15956
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
28584de67687b8e34376cd391a020d4c246fd98a3b904e15f413b56a650b5f06
0c017a96cee53de17cebb7324dde08f9fb932b17e0a077056f1d30d2eafffc9a
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
335fa8a14e0d517ef1f735b02c49d8d902a57895c862ca8240854bb758796928
dfdb67dc602c53e5a6ce811d1b1c60de1cc933309270eb71aa2f58fef3d5099c
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
d5ddd6d4b5dc7983945163188c31a844cbcbbdfda3fb893afc5a3acca2e012bb
9b95c44f257586bd04b5902b152d236c220ce8aac212e2b04ec16b78c8659b43
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
cdb81586fc7bd1043659a70b73241fa3111b9c86742029f018ca3a362cc3e9c2
2547ae57a16c7437b94e4d7f66a40d5d45ec417e1a17928d1223c1cc4739045c
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
de843867603a4d271af1b7159c3ce927236d1ab7575c5e8f12278b97910c8611
7807c2988d7ba0350674aeb9be578959eab03bfb65339dec79e7f376636683a8
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
756eaa234ef62773134d9c69f627c9bff7a537621b0441a65fb19564848cc301
0c9539d0e929be694e6ad1116e82600b7f556c4e7866adfeb8432b338afe6d05
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
bb6539e78a31a830edd6c59286c0f01d9b95418a20c8f492c962739e9b5f414a
68162a1e231ee6802df110fce6699f49e073837ebebc2c5d8412824e49e0045d
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
84fce12270a15e21be616d264bd9dd6d515bffd38ec37e992232843c80e7a439
edae1f19c6772d3eb147bcb2a8f6c809ab6c1f26767b3c3b563914b6af5b5648
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
1e2034c9629187cf72c694ea4afa4e901d1235deb37eaf44a1bb4ef37e2d8fa8
c5ac5c59a503e0fd7f4fff7a582e6fc61869c462d3fb33416f216efc568f1a59
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
69dfc009056d06e0ddc5bbca72171c476a91c6b1a8b1785d10b010c2636ae394
9551ec54d3c094cec9648998b03cbeb0176e34c124f5a748e20cac5a1fc3778a
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
080b26b102929dc4cc12b07b28e39ecb0f1e781efd436663b74d401858ee1d5d
1d001f2c36700f767f305521678f43459bc849e74f6c1765a0baeb76d2cfcab4
+2 -1
View File
@@ -153,7 +153,8 @@ interface views {
/// (API 1.7): a review's file before and after, say. `file-name` (a name or
/// relative path, at most 256 characters) picks the syntax highlighting and
/// names the tab when `diff.title` is absent. Only from a command or event
/// of a window; each side at most 1 MiB.
/// of a window. Each side at most 8 MiB (earlier hosts: 1 MiB); a larger
/// side fails with `invalid("diff too large: …")`.
open-diff: func(diff: content-diff, file-name: option<string>) -> result<_, error>;
/// The view (or every custom editor of that id) shows outdated content:
@@ -261,8 +261,14 @@ describe("plugin-backed content editor tabs", () => {
diffs.splice(2);
expect(() => openPluginDiffRequest({ left: "a", right: 1 }, 10)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b", fileName: "x\ny" }, 10)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b" }, 4 << 20)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b" }, 40 << 20)).toThrow();
expect(diffs).toHaveLength(2);
// Lock files and generated code: several MiB per side open; past the limit the error says why.
const big = "x".repeat(5 << 20);
openPluginDiffRequest({ left: big, right: big + "y" }, 10 << 20);
expect(diffs).toHaveLength(3);
const huge = "x".repeat((8 << 20) + 1);
expect(() => openPluginDiffRequest({ left: "a", right: huge }, huge.length)).toThrow(/Diff too large/);
} finally {
unregisterDiff();
}
+12 -3
View File
@@ -153,13 +153,21 @@ export function registerContentTabSender(pluginId: string, view: string, send: (
};
}
/** Largest side of a plugin diff, as the host checks it (`MAX_DIFF_SIDE`). */
const MAX_DIFF_SIDE = 8 << 20;
function validDiff(v: unknown): ContentTabDiff | undefined {
if (v === undefined) return undefined;
if (!v || typeof v !== "object") throw new Error(tx("Invalid content editor configuration"));
const d = v as Record<string, unknown>;
for (const side of [d.left, d.right]) {
if (typeof side === "string" && side.length > MAX_DIFF_SIDE) {
throw new Error(tx`Diff too large: a side is over ${MAX_DIFF_SIDE >> 20} MiB`);
}
}
if (
!bodyText(d.left, 1 << 20) ||
!bodyText(d.right, 1 << 20) ||
!bodyText(d.left, MAX_DIFF_SIDE) ||
!bodyText(d.right, MAX_DIFF_SIDE) ||
(d.leftLabel !== undefined && !text(d.leftLabel, 128)) ||
(d.rightLabel !== undefined && !text(d.rightLabel, 128)) ||
(d.title !== undefined && !text(d.title, 256))
@@ -201,7 +209,8 @@ export function openPluginDiff(diff: ContentTabDiff, name: string, title: string
/** `open-diff` from a plugin web view, or the `views.open-diff` host call. */
export function openPluginDiffRequest(value: object, length: number) {
const m = value as Record<string, unknown>;
if (length > 3 << 20 || (m.fileName !== undefined && !text(m.fileName, 256))) {
// Both sides as JSON (escapes included), with room for the labels.
if (length > 4 * MAX_DIFF_SIDE + (1 << 20) || (m.fileName !== undefined && !text(m.fileName, 256))) {
throw new Error(tx("Invalid content editor configuration"));
}
const fileName = m.fileName as string | undefined;
+2 -1
View File
@@ -8163,5 +8163,6 @@
"Copy Library": "复制库",
"PID {pid}": "PID {pid}",
"PID {pid} · {count} processes": "PID {pid} · {count} 个进程",
"End Process {label}": "结束进程 {label}"
"End Process {label}": "结束进程 {label}",
"Diff too large: a side is over {max} MiB": "差异过大:有一侧超过 {max} MiB"
}
+2 -1
View File
@@ -153,7 +153,8 @@ interface views {
/// (API 1.7): a review's file before and after, say. `file-name` (a name or
/// relative path, at most 256 characters) picks the syntax highlighting and
/// names the tab when `diff.title` is absent. Only from a command or event
/// of a window; each side at most 1 MiB.
/// of a window. Each side at most 8 MiB (earlier hosts: 1 MiB); a larger
/// side fails with `invalid("diff too large: …")`.
open-diff: func(diff: content-diff, file-name: option<string>) -> result<_, error>;
/// The view (or every custom editor of that id) shows outdated content: