дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-21 09:00:49 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
144bea3993 |
No files matched your search
@@ -77,22 +77,9 @@ 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> {
|
||||
diff_side(&diff.left, "left")?;
|
||||
diff_side(&diff.right, "right")?;
|
||||
body(&diff.left)?;
|
||||
body(&diff.right)?;
|
||||
for value in [&diff.left_label, &diff.right_label].into_iter().flatten() {
|
||||
label(value, 128)?;
|
||||
}
|
||||
@@ -584,25 +571,3 @@ 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"))
|
||||
);
|
||||
}
|
||||
}
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
0b77e7a414ec3b0dd1f41e5658b981f059dd842743dbe2f06e5d428f5b9570f9
|
||||
e616b87b24371581ad648f9c7072259de7732d122b5887b488f7bd480ebd69c2
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
6f7d6527837c8e5c86c377479cceef5116decd61666b28f36dd11332e36e9934
|
||||
75eeecc467bff141bda14f1f080633348af348f7259e793be81e6548d2008669
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c1ac86a5b4d45b55013e6e00dcb83deda33b759ecc366c3fdf57739bdd22cbff
|
||||
4aaf7754e895f022d34dad05bd2b8018e3a61ba18771b8c95d9f070cb212530c
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
e4d8d8f5f5849b912b2c0ebee6b91d60796c3070929d7698323e8ce4f200a38a
|
||||
e573144879a7caa0975e17b233476eb317ff54bef23fd8fa64280d3649bad700
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
e2e2fc44ad9cae9cf26a5bf706768d3786502f23db6994dc29695deb249ed73f
|
||||
36dd40ef751a617f1ad59491312889c12481b05666e580f21f7c2552df76edbc
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
61e1f0c43bbfddc35dcf40685169eb273777ddca13da534626e1699b47e8eac3
|
||||
724ed3bbd828e4fc1925c1b555bdaec9268633cb587806a661f8838e5a540545
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
2ea1c1693db8638db996c9c47597f0c1635ef0a9c7dfb33685c515b7af95e6a6
|
||||
1a3685234f1b3b0957184c44c603c0eefe7e3084b88d0df32da268b29292ee92
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
3c788f6092b229484a5d94fd0e6f4651afc88dd0ab1b22b067d84614a6a0c85e
|
||||
4283de821d69a18438f58062e4bc28b63ba5025cc5f9fa51f21ff475b677a6a5
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
18273599cc459833d6a30185a5f0ba127cdb4e22bc054a973571e530eb3a85ca
|
||||
0f25487b8e488e5ec01fabd2951bdb03d80bc26e4e9aa508394a7f9cd09d1759
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c9fafba362fa0745d7ee1685efe5582d432510003c04c98100eddd557bd1e2cf
|
||||
80f9dc28e4f168dd22ccee1c53e1f6b08c446622eb10f07de29be5fc45e9fb1c
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
4121009913709edeca8c5cb52d88dfcc2b16867bc06859768f73c17cf9c456a2
|
||||
5355cb4ef373eba3c54806eb00294fcd5fccb3cf05dae3e1c2a4ad45ab958f03
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
b55bd202a06f5643c4f70abb6fb473fbe53af657f4e21a6d13581a23a726e085
|
||||
fc75ede42e6db7619fa28fc8999f091d39e3c1ed401356db3a3f07de54287c99
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
11a12228df67f9b94bd52375b5dddb2d955f7e5f88d7f9ea0a430b1db128f6ca
|
||||
8793601496f1727cf912e4cdf86ec48fc340a17585098e98dee52a125cb8a16d
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
553ce6c57052f8ff2ea2526e88762d5a0aee2489cda192fc7ab708766078ccf7
|
||||
fb2db14a645cad42941d20a25a3ff87ca6fdee635fdb40953383ff30ce16af8a
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
7b43f8a2a06d7b2952f8d46727a4cce524fb2bdecee1035dad9c767261d276d0
|
||||
fc66b3b56a1ab1c9d547e3efe6bb4693dca908bb18be8b8ebd26f2fb41e4436c
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
e994c69fda5eef94ae85d6dac5aec3d04fb6811c35c446c9d33236a449bd1c6c
|
||||
c76830df9dee3caba932ffaddaabce88ac7ef23b3957b3e8e570b4939dd58d9d
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c37f6a7ea9018ca636d0fd486a9d91cd397158615410de9b837ca9b8f9f593b7
|
||||
3a41a06d54939a9e85fcf6b0bf15b336f928a3caf66576bd2da62c5b8b177c1d
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
1b298dfa5c1f2163d609ef0ccc3d42fafe78e69326002effe53abc4b82974749
|
||||
f30a8c0a7893519872628c001314efd567f87f4dfaf718a737ea3631b55881b0
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
1e11a95e0909d18308d21a9a8448f8b2e427d240d5d8cd13d8ddbe6ba5009237
|
||||
cb65533984ffd8684c9e9f5ddeef92a8f387735c12310b25282ee7bbf2d73cd7
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
d5cd77130cc97cffdbc742f04e3e1196f14160107b636806c6ef3c9b40724e84
|
||||
d11f9cb1130f3f3aaa89514bf47ec8ece9b2ca0edf1d82c11f80b262325f16be
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
a0f74430b0a7d9ff48524d7aae4f8a0bd0fc60511e2a951dde9991b9bf7d15a9
|
||||
48ea4414469ebd70a89da8a5df7b7bddc4d32f5c50f1759ee3cea14558073c92
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
65508f6e25bd0efc85820ae7d0f9037b58c778fa61e8498c5b9a5055cc38f6fc
|
||||
0c02303182be04ed3776fb532fd8b72e6057aa0fdb92b7d235000146fef4120e
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
c86ed41d68c132f72eb8b5794f31b975492e5ad42e41b7823d1bf28ba118a262
|
||||
8162a70e848172663463119e6357984a73e54bc71a99b2845621d0733cf9333e
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
3da1a09906d803234016b3f9c30a88b9b40bf3187fc73840ff60a2e05f504b48
|
||||
4524cab0ceac631153a945f6b76f7d40efd3c854740ae22c64580381e9532397
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
39e7a805120ce6433750c32b1d670b3caba990f7b15aea866a29c23b01cba708
|
||||
a92f4def072ca4cc805414516ab4f046fc54bcf11394a5413a27ea151c156174
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
5ec9be607955ce2aa4d921884df17c49af3ce98945f8fa641cec9a7f1b4d8384
|
||||
994fca61bc5a10f0229301406af76c188a9cb2f593db85a403c1ece746e9f7b5
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
f05df5c2faf1718ba9702be4d979c367ea8445a854794bb21e8e36b211f18122
|
||||
48eaf97f57cc08c3854a1effa37ebf29defca4782f76c7de1da6ef9a02c23441
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
548cb8321b63b0685049fcf796dbc8390fcb22f3c1ffcfa09452e5a63382d27d
|
||||
b896043cf261ff4bb19977f4648a736907fa897b8d4f0804077678a5895d1845
|
||||
@@ -136,11 +136,6 @@ buttons can act on what the user is editing.
|
||||
Toolbar buttons: `View::new(body).button(Button::new("refresh", "Refresh").icon("refresh"))`
|
||||
and `.status("12 items")`.
|
||||
|
||||
An item or button `icon` is an IDE icon name, a registered plugin icon, or a small raster image as a `data:` URI
|
||||
(`data:image/png;base64,…`; PNG, JPEG, GIF or WebP, at most 64 KiB), drawn at the icon's size: an avatar or a pipeline
|
||||
status badge. Fetch the image yourself (a `net` grant) and pass it inline; the IDE never loads URLs for an icon. Older
|
||||
hosts show the generic file icon in its place.
|
||||
|
||||
### Events
|
||||
|
||||
`ViewEvent` carries `Button(id)`, `Activate(key)` (double click or Enter), `Select(key)`,
|
||||
@@ -369,10 +364,6 @@ host::open_content_tab(&ContentTab {
|
||||
})?;
|
||||
```
|
||||
|
||||
A Markdown tab (`language` `markdown`, or a `file_name` ending in `.md`) has the Markdown editor's layouts (Editor Only,
|
||||
Editor and Preview, Preview Only) and opens on the rendered preview when it is read-only, such as a merge request's
|
||||
description. Web links in the preview open in the browser.
|
||||
|
||||
## Decorations
|
||||
|
||||
Decorations (API 1.4, WIT `decorations.wit`) annotate editors and the Project tree. They
|
||||
|
||||
@@ -126,8 +126,6 @@ register_plugin!(TodoFinder, views);
|
||||
|
||||
工具栏按钮:`View::new(body).button(Button::new("refresh", "Refresh").icon("refresh"))`,状态行:`.status("12 items")`。
|
||||
|
||||
条目和按钮的 `icon` 可以是 IDE 图标名、已注册的插件图标,或者以 `data:` URI 给出的小尺寸位图(`data:image/png;base64,…`,支持 PNG、JPEG、GIF、WebP,最大 64 KiB),按图标尺寸绘制,适合头像或流水线状态徽章。图片由插件自己获取(需要 `net` 授权)后内联传入,IDE 不会为图标加载 URL。较旧的宿主会在该位置显示通用文件图标。
|
||||
|
||||
### 事件
|
||||
|
||||
`ViewEvent` 包括 `Button(id)`、`Activate(key)`(双击或回车)、`Select(key)`、`Expand(key)`、`Collapse(key)`、
|
||||
@@ -331,8 +329,6 @@ host::open_content_tab(&ContentTab {
|
||||
})?;
|
||||
```
|
||||
|
||||
Markdown 标签页(`language` 为 `markdown`,或 `file_name` 以 `.md` 结尾)提供与 Markdown 编辑器相同的布局(仅编辑器、编辑器和预览、仅预览),只读时直接打开渲染后的预览,适合合并请求的描述这类内容。预览中的网页链接在浏览器中打开。
|
||||
|
||||
## 装饰
|
||||
|
||||
装饰(API 1.4,WIT `decorations.wit`)用于在编辑器和项目树中添加标注。需要 `project.read`,路径必须在打开的项目内。
|
||||
|
||||
@@ -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 (8 MiB on current hosts).
|
||||
Commands and events only; each side at most 1 MiB.
|
||||
|
||||
### 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 8 MiB (earlier hosts: 1 MiB), a larger side fails with `Invalid("diff too large: …")`. |
|
||||
| `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. |
|
||||
| `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,9 +1883,8 @@ 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 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.
|
||||
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.
|
||||
|
||||
### Plugin-backed content editor tabs (API 1.3)
|
||||
|
||||
@@ -1914,10 +1913,7 @@ openidea.postMessage(JSON.stringify({
|
||||
are required. `key` (1–128 characters) defaults to `title` and is scoped to the
|
||||
calling plugin and view; `fileName` (1–256 characters, no path separators) and
|
||||
`language` (1–64 characters) select syntax highlighting and the tab's file icon.
|
||||
A Markdown tab (`language` `markdown`, or a `fileName` ending in `.md`) has the
|
||||
Markdown file editor's layouts (Editor Only, Editor and Preview, Preview Only) and
|
||||
opens on the rendered preview when it is read-only; web links in the preview open
|
||||
in the browser. `readOnly` defaults to `false`. `actions` lists up to 16 toolbar buttons with
|
||||
`readOnly` defaults to `false`. `actions` lists up to 16 toolbar buttons with
|
||||
unique `id`s (1–64 characters), `label`s (1–128 characters), an optional built-in
|
||||
`icon` name, `primary`, and `save` (at most one action may set `save: true`).
|
||||
Invalid requests send `content-tab-error { error }` through `openidea.onMessage`.
|
||||
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
93f5619378f0edaf2e78a95b38e92e6e14ffc4377aab425d575dbbcb30c7c3e4
|
||||
56008cb5a36b35b8975b95da971212c95c165de378b0c8b7f7b428d9d9332ec1
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
007134d609d842c6f57386e35a6725948ad17fdd6458a2e209398ee38d034a23
|
||||
d87e571ebe16283bbffcc7525f69755d5faffb4693ff4a5183de67418976086b
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
01d5abc7a65811684cac58e39d733218d5cde46681b7e57231897f6a07318133
|
||||
254da92cdb20bdf432b5bb4e90ef9bdfaff92eca7195fbff38127f47fa231e6e
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
9b29d2a047e223ecd432fb90914c684f708eb8becba6cc72cd55462064d15956
|
||||
50ea437aa2b99dc28afd51286fbac7e07d8386f826f222c517a8bd6e4f647a1a
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
0c017a96cee53de17cebb7324dde08f9fb932b17e0a077056f1d30d2eafffc9a
|
||||
28584de67687b8e34376cd391a020d4c246fd98a3b904e15f413b56a650b5f06
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
dfdb67dc602c53e5a6ce811d1b1c60de1cc933309270eb71aa2f58fef3d5099c
|
||||
335fa8a14e0d517ef1f735b02c49d8d902a57895c862ca8240854bb758796928
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
9b95c44f257586bd04b5902b152d236c220ce8aac212e2b04ec16b78c8659b43
|
||||
d5ddd6d4b5dc7983945163188c31a844cbcbbdfda3fb893afc5a3acca2e012bb
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
2547ae57a16c7437b94e4d7f66a40d5d45ec417e1a17928d1223c1cc4739045c
|
||||
cdb81586fc7bd1043659a70b73241fa3111b9c86742029f018ca3a362cc3e9c2
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
7807c2988d7ba0350674aeb9be578959eab03bfb65339dec79e7f376636683a8
|
||||
de843867603a4d271af1b7159c3ce927236d1ab7575c5e8f12278b97910c8611
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
0c9539d0e929be694e6ad1116e82600b7f556c4e7866adfeb8432b338afe6d05
|
||||
756eaa234ef62773134d9c69f627c9bff7a537621b0441a65fb19564848cc301
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
68162a1e231ee6802df110fce6699f49e073837ebebc2c5d8412824e49e0045d
|
||||
bb6539e78a31a830edd6c59286c0f01d9b95418a20c8f492c962739e9b5f414a
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
edae1f19c6772d3eb147bcb2a8f6c809ab6c1f26767b3c3b563914b6af5b5648
|
||||
84fce12270a15e21be616d264bd9dd6d515bffd38ec37e992232843c80e7a439
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
c5ac5c59a503e0fd7f4fff7a582e6fc61869c462d3fb33416f216efc568f1a59
|
||||
1e2034c9629187cf72c694ea4afa4e901d1235deb37eaf44a1bb4ef37e2d8fa8
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
9551ec54d3c094cec9648998b03cbeb0176e34c124f5a748e20cac5a1fc3778a
|
||||
69dfc009056d06e0ddc5bbca72171c476a91c6b1a8b1785d10b010c2636ae394
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
1d001f2c36700f767f305521678f43459bc849e74f6c1765a0baeb76d2cfcab4
|
||||
080b26b102929dc4cc12b07b28e39ecb0f1e781efd436663b74d401858ee1d5d
|
||||
@@ -153,8 +153,7 @@ 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 8 MiB (earlier hosts: 1 MiB); a larger
|
||||
/// side fails with `invalid("diff too large: …")`.
|
||||
/// of a window; each side at most 1 MiB.
|
||||
open-diff: func(diff: content-diff, file-name: option<string>) -> result<_, error>;
|
||||
|
||||
/// The view (or every custom editor of that id) shows outdated content:
|
||||
|
||||
@@ -34,7 +34,6 @@ import type { LineEnding } from "@/platform/ipc";
|
||||
import { create } from "zustand";
|
||||
import { maybeEditorService } from "@/workbench/contributions";
|
||||
import { cornerInset } from "@/editor/core/cm/cornerInset";
|
||||
export { iconAreaSource, type IconAreaSource } from "@/editor/core/cm/iconArea";
|
||||
|
||||
/** Documents above this size (UTF-16 units) skip per-line decorations. */
|
||||
export const HEAVY_LIMIT = 8_000_000;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { fireEvent } from "@testing-library/react";
|
||||
import { EditorState, RangeSet } from "@codemirror/state";
|
||||
import { EditorView, GutterMarker } from "@codemirror/view";
|
||||
import { iconAreaExtension, iconAreaSource } from "./iconArea";
|
||||
|
||||
class Dot extends GutterMarker {
|
||||
constructor(readonly name: string) {
|
||||
super();
|
||||
}
|
||||
override eq(other: GutterMarker) {
|
||||
return other instanceof Dot && other.name === this.name;
|
||||
}
|
||||
override toDOM() {
|
||||
const el = document.createElement("span");
|
||||
el.className = `dot dot-${this.name}`;
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
||||
let view: EditorView | null = null;
|
||||
afterEach(() => {
|
||||
view?.destroy();
|
||||
view = null;
|
||||
});
|
||||
|
||||
const DOC = "run()\nclass A implements B {}\n/** doc */\nend";
|
||||
const lineStart = (state: EditorState, line: number) => state.doc.line(line).from;
|
||||
|
||||
function open(extra: Parameters<typeof iconAreaSource.of>[0][]) {
|
||||
view = new EditorView({
|
||||
state: EditorState.create({ doc: DOC, extensions: [iconAreaExtension, ...extra.map((s) => iconAreaSource.of(s))] }),
|
||||
parent: document.body,
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
it("puts every source's icons in one column, in order within a line", () => {
|
||||
const v = open([
|
||||
{
|
||||
order: 50,
|
||||
markers: (view) =>
|
||||
RangeSet.of([new Dot("impl").range(lineStart(view.state, 1)), new Dot("impl").range(lineStart(view.state, 2))]),
|
||||
},
|
||||
{ order: 10, markers: (view) => RangeSet.of([new Dot("run").range(lineStart(view.state, 1))]) },
|
||||
]);
|
||||
expect(v.dom.querySelectorAll(".cm-gutter")).toHaveLength(1);
|
||||
const rows = [...v.dom.querySelectorAll(".cm-openidea-iconArea .cm-gutterElement")].filter((el) =>
|
||||
el.querySelector(".dot"),
|
||||
);
|
||||
expect(rows.map((el) => [...el.querySelectorAll(".dot")].map((d) => d.className))).toEqual([
|
||||
["dot dot-run", "dot dot-impl"],
|
||||
["dot dot-impl"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("routes a press to the source that handles it", () => {
|
||||
const first = vi.fn(() => false);
|
||||
const second = vi.fn(() => true);
|
||||
const v = open([
|
||||
{ order: 1, markers: (view) => RangeSet.of([new Dot("a").range(lineStart(view.state, 1))]), mousedown: first },
|
||||
{ order: 2, markers: () => RangeSet.empty, mousedown: second },
|
||||
]);
|
||||
fireEvent.mouseDown(v.dom.querySelector(".dot-a")!, { button: 0 });
|
||||
expect(first).toHaveBeenCalledTimes(1);
|
||||
expect(second).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("keeps an icon's width only while a source asks for it", () => {
|
||||
const empty = open([{ order: 1, markers: () => RangeSet.empty }]);
|
||||
expect(empty.dom.querySelector(".cm-openidea-iconSpacer")).toBeNull();
|
||||
empty.destroy();
|
||||
const v = open([{ order: 1, markers: () => RangeSet.empty, reserve: () => true }]);
|
||||
expect(v.dom.querySelector(".cm-openidea-iconArea .cm-openidea-iconSpacer")).toBeTruthy();
|
||||
});
|
||||
@@ -1,76 +0,0 @@
|
||||
/**
|
||||
* The gutter's icon area (IDEA's line marker area): run icons, inheritance markers and the
|
||||
* rendered-doc toggle share one column, as wide as the most icons on any line, instead of a
|
||||
* column per kind that stays empty on the lines where another kind has its icon.
|
||||
*/
|
||||
import { Facet, type EditorState, type Extension, type RangeSet } from "@codemirror/state";
|
||||
import { EditorView, GutterMarker, gutter, type BlockInfo, type ViewUpdate, type WidgetType } from "@codemirror/view";
|
||||
|
||||
export interface IconAreaSource {
|
||||
/** Left to right within a line: lower first. */
|
||||
order: number;
|
||||
markers(view: EditorView): RangeSet<GutterMarker>;
|
||||
/** The marker beside a block widget (a rendered doc comment), which has no text line. */
|
||||
widgetMarker?(view: EditorView, widget: WidgetType, block: BlockInfo): GutterMarker | null;
|
||||
/** Markers that changed without `markers` returning a new set (one shown on hover). */
|
||||
lineMarkerChange?(update: ViewUpdate): boolean;
|
||||
/** Keeps one icon of width while true, so icons that come and go don't shift the text. */
|
||||
reserve?(state: EditorState): boolean;
|
||||
/** A press on the area at `block`; true when the source handled it. */
|
||||
mousedown?(view: EditorView, block: BlockInfo, event: MouseEvent): boolean;
|
||||
}
|
||||
|
||||
export const iconAreaSource = Facet.define<IconAreaSource, readonly IconAreaSource[]>({
|
||||
combine: (sources) => [...sources].sort((a, b) => a.order - b.order),
|
||||
});
|
||||
|
||||
/** The width of one icon, for the reserved column. Hidden; not a button. */
|
||||
class IconSpacer extends GutterMarker {
|
||||
override toDOM(): Node {
|
||||
const el = document.createElement("span");
|
||||
el.className = "cm-openidea-iconSpacer";
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
||||
const iconSpacer = new IconSpacer();
|
||||
const noSpacer = new (class extends GutterMarker {})();
|
||||
|
||||
const reserved = (state: EditorState) => state.facet(iconAreaSource).some((s) => s.reserve?.(state));
|
||||
|
||||
const areaGutter = gutter({
|
||||
class: "cm-openidea-iconArea",
|
||||
markers: (view) => view.state.facet(iconAreaSource).map((s) => s.markers(view)),
|
||||
widgetMarker: (view, widget, block) => {
|
||||
for (const s of view.state.facet(iconAreaSource)) {
|
||||
const marker = s.widgetMarker?.(view, widget, block);
|
||||
if (marker) return marker;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
lineMarkerChange: (update) =>
|
||||
update.startState.facet(iconAreaSource) !== update.state.facet(iconAreaSource) ||
|
||||
update.state.facet(iconAreaSource).some((s) => s.lineMarkerChange?.(update)),
|
||||
initialSpacer: (view) => (reserved(view.state) ? iconSpacer : noSpacer),
|
||||
updateSpacer: (_spacer, update) => (reserved(update.state) ? iconSpacer : noSpacer),
|
||||
domEventHandlers: {
|
||||
mousedown: (view, block, event) =>
|
||||
view.state.facet(iconAreaSource).some((s) => s.mousedown?.(view, block, event as MouseEvent) ?? false),
|
||||
},
|
||||
});
|
||||
|
||||
const areaTheme = EditorView.baseTheme({
|
||||
".cm-openidea-iconArea .cm-gutterElement": {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "flex-start",
|
||||
gap: "2px",
|
||||
},
|
||||
// Room around the icons, not the element: an area without icons takes no width.
|
||||
".cm-openidea-iconArea .cm-gutterElement > *": { margin: "0 1px" },
|
||||
".cm-openidea-iconArea .cm-gutterElement > :first-child": { marginLeft: "5px" },
|
||||
".cm-openidea-iconSpacer": { display: "inline-block", width: "14px" },
|
||||
});
|
||||
|
||||
/** Installed in every editor; empty (no width) while no source has markers or reserves room. */
|
||||
export const iconAreaExtension: Extension = [areaGutter, areaTheme];
|
||||
@@ -472,18 +472,13 @@ const noSurround = EditorView.inputHandler.of((view, from, to, text) => {
|
||||
return true;
|
||||
});
|
||||
|
||||
/**
|
||||
* Gutter icon groups of Settings › Editor › General › Gutter Icons. A hidden group sets
|
||||
* `cm-openidea-hideGutter-<id>` on the editor (the theme hides the bookmark, color and
|
||||
* script/compose run columns by it); the icon area's run and inheritance icons read the
|
||||
* setting themselves.
|
||||
*/
|
||||
/** Gutter icon groups of Settings › Editor › General › Gutter Icons (stable gutter classes). */
|
||||
export const GUTTER_ICON_GROUPS = [
|
||||
{ id: "run" },
|
||||
{ id: "bookmarks" },
|
||||
{ id: "inheritors" },
|
||||
{ id: "supers" },
|
||||
{ id: "colors" },
|
||||
{ id: "run", gutterClass: "cm-openidea-gutter-run" },
|
||||
{ id: "bookmarks", gutterClass: "cm-openidea-bookmarks" },
|
||||
{ id: "inheritors", gutterClass: "cm-openidea-gutter-lineMarkers" },
|
||||
{ id: "supers", gutterClass: "cm-openidea-gutter-lineMarkers" },
|
||||
{ id: "colors", gutterClass: "cm-openidea-gutter-colors" },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ import { EditorState } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { java } from "@codemirror/lang-java";
|
||||
import { useI18n } from "@/platform/i18n";
|
||||
import { iconAreaExtension } from "./iconArea";
|
||||
import { renderDocComments, renderedDocsExtension, renderedRanges, toggleRenderedViewAtCaret } from "./renderedDocs";
|
||||
|
||||
let view: EditorView | null = null;
|
||||
@@ -22,7 +21,7 @@ function open(reader: boolean, doc = DOC) {
|
||||
view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc,
|
||||
extensions: [java(), iconAreaExtension, renderedDocsExtension, renderDocComments.of(reader)],
|
||||
extensions: [java(), renderedDocsExtension, renderDocComments.of(reader)],
|
||||
}),
|
||||
parent: document.body,
|
||||
});
|
||||
@@ -39,8 +38,11 @@ async function hover(v: EditorView, line: number) {
|
||||
|
||||
const pressed = (v: EditorView) => toggles(v).map((t) => t.getAttribute("aria-pressed"));
|
||||
|
||||
/** Whether the icon area keeps the toggles an icon's width: its spacer is the icon spacer, else none. */
|
||||
const hasColumn = (v: EditorView) => !!v.dom.querySelector(".cm-openidea-iconArea .cm-openidea-iconSpacer");
|
||||
/** Whether the gutter gives the toggles a column: its spacer has their width, else none. */
|
||||
const hasColumn = (v: EditorView) =>
|
||||
[...v.dom.querySelectorAll<HTMLElement>(".cm-openidea-docToggles .cm-gutterElement span")].some(
|
||||
(el) => el.style.width === "14px",
|
||||
);
|
||||
|
||||
/** Opens the file rendering its comments, then brings this one's source back with its pencil. */
|
||||
async function openFlippedToSource() {
|
||||
|
||||
@@ -51,12 +51,13 @@ import {
|
||||
GutterMarker,
|
||||
ViewPlugin,
|
||||
WidgetType,
|
||||
gutter,
|
||||
type DecorationSet,
|
||||
type ViewUpdate,
|
||||
} from "@codemirror/view";
|
||||
import { syntaxTree } from "@codemirror/language";
|
||||
import { gutterIconMarkup } from "@/ui/icons";
|
||||
import { iconAreaSource } from "./iconArea";
|
||||
import { emptyGutterSpacer } from "@/editor/api";
|
||||
import { tx, useI18n } from "@/platform/i18n";
|
||||
import { loadMarkdown, markupToHtml } from "@/editor/lsp/markdown";
|
||||
import { hasContent, renderDoc, type DocComment, type DocStyle, type RenderedDoc } from "./docRender";
|
||||
@@ -357,6 +358,18 @@ function toggleMarker(rendered: boolean): ToggleMarker {
|
||||
return new ToggleMarker(rendered, tx("Toggle Rendered View"));
|
||||
}
|
||||
|
||||
/** Reserves the toggles' width. Not a `ToggleMarker`: the spacer is in the DOM, hidden, and must not read as a button. */
|
||||
class ToggleSpacer extends GutterMarker {
|
||||
override toDOM(): Node {
|
||||
const el = document.createElement("span");
|
||||
el.style.display = "inline-block";
|
||||
el.style.width = "14px";
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
||||
const toggleSpacer = new ToggleSpacer();
|
||||
|
||||
/** A doc comment, with where its first line starts and its last line ends, and whether it is rendered now. */
|
||||
type PlacedComment = DocComment & { line: number; end: number; rendered: boolean };
|
||||
|
||||
@@ -645,8 +658,8 @@ const docsField = StateField.define<DocsView>({
|
||||
provide: (f) => EditorView.decorations.from(f, (v) => v.decorations),
|
||||
});
|
||||
|
||||
const toggleSource = iconAreaSource.of({
|
||||
order: 90,
|
||||
const toggleGutter = gutter({
|
||||
class: "cm-openidea-docToggles",
|
||||
// Comments left as source: their first line is a text line, which reads these markers.
|
||||
// Asked again on every update, so the icon follows the mouse.
|
||||
markers: (view) => sourceToggle(view.state),
|
||||
@@ -661,21 +674,24 @@ const toggleSource = iconAreaSource.of({
|
||||
lineMarkerChange: (update) =>
|
||||
update.startState.field(hovered) !== update.state.field(hovered) ||
|
||||
update.transactions.some((tr) => tr.effects.some((e) => e.is(relabel))),
|
||||
// A file with doc comments keeps an icon's width while the icon comes and goes, so the
|
||||
// text does not shift; it shares the icon area with the run and inheritance icons.
|
||||
reserve: (state) => placedComments(state).length > 0,
|
||||
mousedown(view, block, event) {
|
||||
const target = event.target instanceof Element ? event.target.closest(".cm-openidea-docToggle") : null;
|
||||
if (event.button !== 0 || !target) return false;
|
||||
// A file that renders none may not have been scanned since its last edit: the flip
|
||||
// must land on where its comment starts now.
|
||||
const comment = active(view.state)
|
||||
? commentOverlapping(view.state, block.from, block.to)
|
||||
: (placeComments(view.state).find((c) => block.from <= c.to && block.to >= c.line)?.from ?? null);
|
||||
if (comment === null) return false;
|
||||
event.preventDefault();
|
||||
view.dispatch({ effects: toggleRenderedView.of(comment) });
|
||||
return true;
|
||||
// A file without doc comments gets no column at all; one with them keeps its column
|
||||
// while the icon comes and goes, so the text does not shift.
|
||||
initialSpacer: (view) => (placedComments(view.state).length ? toggleSpacer : emptyGutterSpacer),
|
||||
updateSpacer: (_spacer, update) => (placedComments(update.state).length ? toggleSpacer : emptyGutterSpacer),
|
||||
domEventHandlers: {
|
||||
mousedown(view, block, event) {
|
||||
const target = event.target instanceof Element ? event.target.closest(".cm-openidea-docToggle") : null;
|
||||
if ((event as MouseEvent).button !== 0 || !target) return false;
|
||||
// A file that renders none may not have been scanned since its last edit: the flip
|
||||
// must land on where its comment starts now.
|
||||
const comment = active(view.state)
|
||||
? commentOverlapping(view.state, block.from, block.to)
|
||||
: (placeComments(view.state).find((c) => block.from <= c.to && block.to >= c.line)?.from ?? null);
|
||||
if (comment === null) return false;
|
||||
event.preventDefault();
|
||||
view.dispatch({ effects: toggleRenderedView.of(comment) });
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -858,15 +874,15 @@ const docsTheme = EditorView.theme({
|
||||
".cm-openidea-renderedDocSections dt": { color: "var(--syn-doc-comment)" },
|
||||
".cm-openidea-renderedDocSections dd": { margin: "0" },
|
||||
".cm-openidea-renderedDocText p": { display: "inline", margin: "0" },
|
||||
".cm-openidea-docToggles .cm-gutterElement": {
|
||||
display: "flex",
|
||||
alignItems: "flex-start",
|
||||
justifyContent: "center",
|
||||
padding: "0 2px",
|
||||
},
|
||||
".cm-openidea-docToggle": {
|
||||
// At the comment's first line, at the right of the icon area (IDEA aligns it right).
|
||||
alignSelf: "flex-start",
|
||||
marginLeft: "auto",
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
// An icon's width, like the other icons of the area, so showing it doesn't widen the area.
|
||||
width: "14px",
|
||||
height: "var(--openidea-editor-line-height, var(--lh-code))",
|
||||
padding: "0",
|
||||
border: "none",
|
||||
@@ -886,7 +902,7 @@ export const renderedDocsExtension: Extension = [
|
||||
hovered,
|
||||
hoverTracker,
|
||||
showSourceAtCaret,
|
||||
toggleSource,
|
||||
toggleGutter,
|
||||
markdownReady,
|
||||
languageWatcher,
|
||||
docMetrics,
|
||||
|
||||
@@ -42,7 +42,6 @@ import { rainbowBrackets } from "./rainbowBrackets";
|
||||
import { stickyMaxLines, stickyScroll } from "./stickyScroll";
|
||||
import { findExtension } from "./find";
|
||||
import { codeLensExtension } from "./codeLens";
|
||||
import { iconAreaExtension } from "./iconArea";
|
||||
import { renderedDocsExtension } from "./renderedDocs";
|
||||
import { caretExtension, fontZoom, methodLinesField, prefsExtension, softWrapActive } from "./prefs";
|
||||
import { commentTokens } from "./languages";
|
||||
@@ -397,7 +396,6 @@ export function baseExtensions(o: SetupOptions): Extension {
|
||||
overviewLane,
|
||||
cornerInset,
|
||||
codeLensExtension,
|
||||
iconAreaExtension,
|
||||
renderedDocsExtension,
|
||||
EditorView.contentAttributes.of({
|
||||
spellcheck: "false",
|
||||
|
||||
@@ -8,7 +8,6 @@ const ipc = vi.hoisted(() => ({
|
||||
docOutline: vi.fn(),
|
||||
lspReferences: vi.fn(),
|
||||
cancelRequest: vi.fn<(id: number) => Promise<void>>(async () => {}),
|
||||
vcsBlame: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/platform/ipc", async (orig) => {
|
||||
const real = await orig<typeof import("@/platform/ipc")>();
|
||||
@@ -103,22 +102,6 @@ describe("usages lens targets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("author hint", () => {
|
||||
it("toggles the blame annotations on every click", async () => {
|
||||
ipc.vcsBlame.mockResolvedValue(ok([{ commit: "c1", author: "Ann", timeMs: 1, summary: "init" }]));
|
||||
useProject.setState({
|
||||
settings: { editor: { inlay: { codeVisionUsages: false, codeVisionAuthor: true } } } as never,
|
||||
});
|
||||
const view = editor();
|
||||
await settle();
|
||||
const author = view.state.facet(codeLenses).find((l) => l.kind === "author")!;
|
||||
expect(author.title).toContain("Ann");
|
||||
author.run!(view, new MouseEvent("click"));
|
||||
author.run!(view, new MouseEvent("click"));
|
||||
expect(executeAction.mock.calls).toEqual([["vcs.annotate"], ["vcs.annotate"]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("background usage counts", () => {
|
||||
it("uses the server's existing scope and leaves full searches to the explicit action", async () => {
|
||||
const view = editor();
|
||||
|
||||
@@ -15,7 +15,7 @@ import { EditorSelection, MapMode, StateEffect, StateField, type Extension, type
|
||||
import { EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
|
||||
import { codeLenses, onEditorEvent, shownAgain, type CodeLens } from "@/editor/api";
|
||||
import { onNavigationProvidersChanged } from "@/editor/navigationProviders";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { executeAction, getAction } from "@/platform/actions";
|
||||
import { commands, nextRequestId, onIdeEvent, type OutlineItem, type RequestId, type SymbolKind } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { debounce, docOf, isUnavailable, lspRequest } from "./lsp";
|
||||
@@ -112,10 +112,10 @@ const lensField = StateField.define<CodeLens[]>({
|
||||
const usagesEnabled = () => editorPrefs().inlay.codeVisionUsages;
|
||||
const authorEnabled = () => editorPrefs().inlay.codeVisionAuthor;
|
||||
|
||||
/** The author hint runs Annotate with Git Blame: it shows the file's annotations, or closes them when shown. */
|
||||
function toggleAnnotations(view: EditorView) {
|
||||
/** The author hint opens the file's blame annotations, and leaves them open when shown. */
|
||||
function showAnnotations(view: EditorView) {
|
||||
view.focus();
|
||||
void executeAction("vcs.annotate");
|
||||
if (!getAction("vcs.annotate")?.toggled?.()) void executeAction("vcs.annotate");
|
||||
}
|
||||
|
||||
function openUsages(view: EditorView, offset: number) {
|
||||
@@ -309,7 +309,7 @@ class UsagesLensPlugin {
|
||||
icon: "user",
|
||||
order: 20,
|
||||
kind: "author",
|
||||
run: toggleAnnotations,
|
||||
run: showAnnotations,
|
||||
});
|
||||
const n = usages ? this.cache.get(key(t)) : undefined;
|
||||
if (n !== undefined) {
|
||||
|
||||
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Заблокувати користувача