Порівняти коміти

..
Автор SHA1 Повідомлення Дата
l0ng-ai ce8f0711cd fix(editor): run icons, inheritance markers and the doc toggle share one gutter column
Each kind of gutter icon had its own column: a file with doc comments kept an
empty column for the rendered-view toggle (shown on hover) beside the
inheritance markers, and run icons took a third, so the gutter looked twice
as wide as its icons.

A shared icon area (`iconAreaSource`, in core) now holds run icons, the
implements/overrides markers and the rendered-doc toggle in one column, as
wide as the most icons on any line; an area without icons takes no width.
Sources supply their markers, an optional reserved icon width (so icons that
come and go don't shift the text) and their own press handling. Hiding run
icons in Settings › Gutter Icons now drops them from the area instead of
hiding a column.
2026-11-15 03:54:51 +08:00
l0ng-ai 009e61d27b fix(editor): clicking the author hint again closes the blame annotations (#3448)
The Code Vision author hint ran Annotate with Git Blame only while the annotations were hidden, so a second click left them open. It now runs vcs.annotate on every click, toggling the annotations like the action itself.
2026-11-15 03:46:11 +08:00
l0ng-ai a89c0dd229 feat(ui): small raster data-URI images as icons (#3446)
Icon draws a raster data: URI (PNG, JPEG, GIF or WebP, base64, at most 64 KiB) as an image of the icon's size, so plugin view items and buttons can show avatars and status badges the plugin fetched with its net grant; the UI never loads URLs for icons, and older hosts show the file icon. Documented in the views guide.
2026-11-15 03:33:29 +08:00
l0ng-ai ea644dcdb0 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.
2026-11-15 03:32:29 +08:00
l0ng-ai 519c8ad8fc feat(plugins): Markdown preview for Markdown content tabs (#3442)
A Markdown content tab (language markdown, or a .md file name) gets the Markdown editor's layouts (Editor Only / Editor and Preview / Preview Only) and opens on the preview when read-only. The preview uses the editor's sanitized Markdown pipeline, highlights fenced code, follows reloaded content and opens web links in the browser. No API change; documented in the plugin README and views guide.
2026-11-15 03:30:52 +08:00
110 змінених файлів з 639 додано та 163 видалено

No files matched your search

+37 -2
Переглянути файл
@@ -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"))
);
}
}
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
e616b87b24371581ad648f9c7072259de7732d122b5887b488f7bd480ebd69c2
0b77e7a414ec3b0dd1f41e5658b981f059dd842743dbe2f06e5d428f5b9570f9
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
75eeecc467bff141bda14f1f080633348af348f7259e793be81e6548d2008669
6f7d6527837c8e5c86c377479cceef5116decd61666b28f36dd11332e36e9934
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
4aaf7754e895f022d34dad05bd2b8018e3a61ba18771b8c95d9f070cb212530c
c1ac86a5b4d45b55013e6e00dcb83deda33b759ecc366c3fdf57739bdd22cbff
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
e573144879a7caa0975e17b233476eb317ff54bef23fd8fa64280d3649bad700
e4d8d8f5f5849b912b2c0ebee6b91d60796c3070929d7698323e8ce4f200a38a
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
36dd40ef751a617f1ad59491312889c12481b05666e580f21f7c2552df76edbc
e2e2fc44ad9cae9cf26a5bf706768d3786502f23db6994dc29695deb249ed73f
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
724ed3bbd828e4fc1925c1b555bdaec9268633cb587806a661f8838e5a540545
61e1f0c43bbfddc35dcf40685169eb273777ddca13da534626e1699b47e8eac3
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
1a3685234f1b3b0957184c44c603c0eefe7e3084b88d0df32da268b29292ee92
2ea1c1693db8638db996c9c47597f0c1635ef0a9c7dfb33685c515b7af95e6a6
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
4283de821d69a18438f58062e4bc28b63ba5025cc5f9fa51f21ff475b677a6a5
3c788f6092b229484a5d94fd0e6f4651afc88dd0ab1b22b067d84614a6a0c85e
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
0f25487b8e488e5ec01fabd2951bdb03d80bc26e4e9aa508394a7f9cd09d1759
18273599cc459833d6a30185a5f0ba127cdb4e22bc054a973571e530eb3a85ca
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
80f9dc28e4f168dd22ccee1c53e1f6b08c446622eb10f07de29be5fc45e9fb1c
c9fafba362fa0745d7ee1685efe5582d432510003c04c98100eddd557bd1e2cf
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
5355cb4ef373eba3c54806eb00294fcd5fccb3cf05dae3e1c2a4ad45ab958f03
4121009913709edeca8c5cb52d88dfcc2b16867bc06859768f73c17cf9c456a2
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
fc75ede42e6db7619fa28fc8999f091d39e3c1ed401356db3a3f07de54287c99
b55bd202a06f5643c4f70abb6fb473fbe53af657f4e21a6d13581a23a726e085
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
8793601496f1727cf912e4cdf86ec48fc340a17585098e98dee52a125cb8a16d
11a12228df67f9b94bd52375b5dddb2d955f7e5f88d7f9ea0a430b1db128f6ca
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
fb2db14a645cad42941d20a25a3ff87ca6fdee635fdb40953383ff30ce16af8a
553ce6c57052f8ff2ea2526e88762d5a0aee2489cda192fc7ab708766078ccf7
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
fc66b3b56a1ab1c9d547e3efe6bb4693dca908bb18be8b8ebd26f2fb41e4436c
7b43f8a2a06d7b2952f8d46727a4cce524fb2bdecee1035dad9c767261d276d0
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
c76830df9dee3caba932ffaddaabce88ac7ef23b3957b3e8e570b4939dd58d9d
e994c69fda5eef94ae85d6dac5aec3d04fb6811c35c446c9d33236a449bd1c6c
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
3a41a06d54939a9e85fcf6b0bf15b336f928a3caf66576bd2da62c5b8b177c1d
c37f6a7ea9018ca636d0fd486a9d91cd397158615410de9b837ca9b8f9f593b7
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
f30a8c0a7893519872628c001314efd567f87f4dfaf718a737ea3631b55881b0
1b298dfa5c1f2163d609ef0ccc3d42fafe78e69326002effe53abc4b82974749
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
cb65533984ffd8684c9e9f5ddeef92a8f387735c12310b25282ee7bbf2d73cd7
1e11a95e0909d18308d21a9a8448f8b2e427d240d5d8cd13d8ddbe6ba5009237
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
d11f9cb1130f3f3aaa89514bf47ec8ece9b2ca0edf1d82c11f80b262325f16be
d5cd77130cc97cffdbc742f04e3e1196f14160107b636806c6ef3c9b40724e84
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
48ea4414469ebd70a89da8a5df7b7bddc4d32f5c50f1759ee3cea14558073c92
a0f74430b0a7d9ff48524d7aae4f8a0bd0fc60511e2a951dde9991b9bf7d15a9
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
0c02303182be04ed3776fb532fd8b72e6057aa0fdb92b7d235000146fef4120e
65508f6e25bd0efc85820ae7d0f9037b58c778fa61e8498c5b9a5055cc38f6fc
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
8162a70e848172663463119e6357984a73e54bc71a99b2845621d0733cf9333e
c86ed41d68c132f72eb8b5794f31b975492e5ad42e41b7823d1bf28ba118a262
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
4524cab0ceac631153a945f6b76f7d40efd3c854740ae22c64580381e9532397
3da1a09906d803234016b3f9c30a88b9b40bf3187fc73840ff60a2e05f504b48
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
a92f4def072ca4cc805414516ab4f046fc54bcf11394a5413a27ea151c156174
39e7a805120ce6433750c32b1d670b3caba990f7b15aea866a29c23b01cba708
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
994fca61bc5a10f0229301406af76c188a9cb2f593db85a403c1ece746e9f7b5
5ec9be607955ce2aa4d921884df17c49af3ce98945f8fa641cec9a7f1b4d8384
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
48eaf97f57cc08c3854a1effa37ebf29defca4782f76c7de1da6ef9a02c23441
f05df5c2faf1718ba9702be4d979c367ea8445a854794bb21e8e36b211f18122
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
b896043cf261ff4bb19977f4648a736907fa897b8d4f0804077678a5895d1845
548cb8321b63b0685049fcf796dbc8390fcb22f3c1ffcfa09452e5a63382d27d
+4
Переглянути файл
@@ -369,6 +369,10 @@ 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
+2
Переглянути файл
@@ -331,6 +331,8 @@ host::open_content_tab(&ContentTab {
})?;
```
Markdown 标签页(`language` 为 `markdown`,或 `file_name` 以 `.md` 结尾)提供与 Markdown 编辑器相同的布局(仅编辑器、编辑器和预览、仅预览),只读时直接打开渲染后的预览,适合合并请求的描述这类内容。预览中的网页链接在浏览器中打开。
## 装饰
装饰(API 1.4,WIT `decorations.wit`)用于在编辑器和项目树中添加标注。需要 `project.read`,路径必须在打开的项目内。
+9 -5
Переглянути файл
@@ -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)
@@ -1913,7 +1914,10 @@ 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.
`readOnly` defaults to `false`. `actions` lists up to 16 toolbar buttons with
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
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
Переглянути файл
@@ -1 +1 @@
56008cb5a36b35b8975b95da971212c95c165de378b0c8b7f7b428d9d9332ec1
93f5619378f0edaf2e78a95b38e92e6e14ffc4377aab425d575dbbcb30c7c3e4
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
d87e571ebe16283bbffcc7525f69755d5faffb4693ff4a5183de67418976086b
007134d609d842c6f57386e35a6725948ad17fdd6458a2e209398ee38d034a23
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
254da92cdb20bdf432b5bb4e90ef9bdfaff92eca7195fbff38127f47fa231e6e
01d5abc7a65811684cac58e39d733218d5cde46681b7e57231897f6a07318133
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
50ea437aa2b99dc28afd51286fbac7e07d8386f826f222c517a8bd6e4f647a1a
9b29d2a047e223ecd432fb90914c684f708eb8becba6cc72cd55462064d15956
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
28584de67687b8e34376cd391a020d4c246fd98a3b904e15f413b56a650b5f06
0c017a96cee53de17cebb7324dde08f9fb932b17e0a077056f1d30d2eafffc9a
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
335fa8a14e0d517ef1f735b02c49d8d902a57895c862ca8240854bb758796928
dfdb67dc602c53e5a6ce811d1b1c60de1cc933309270eb71aa2f58fef3d5099c
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
d5ddd6d4b5dc7983945163188c31a844cbcbbdfda3fb893afc5a3acca2e012bb
9b95c44f257586bd04b5902b152d236c220ce8aac212e2b04ec16b78c8659b43
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
cdb81586fc7bd1043659a70b73241fa3111b9c86742029f018ca3a362cc3e9c2
2547ae57a16c7437b94e4d7f66a40d5d45ec417e1a17928d1223c1cc4739045c
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
de843867603a4d271af1b7159c3ce927236d1ab7575c5e8f12278b97910c8611
7807c2988d7ba0350674aeb9be578959eab03bfb65339dec79e7f376636683a8
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
756eaa234ef62773134d9c69f627c9bff7a537621b0441a65fb19564848cc301
0c9539d0e929be694e6ad1116e82600b7f556c4e7866adfeb8432b338afe6d05
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
bb6539e78a31a830edd6c59286c0f01d9b95418a20c8f492c962739e9b5f414a
68162a1e231ee6802df110fce6699f49e073837ebebc2c5d8412824e49e0045d
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
84fce12270a15e21be616d264bd9dd6d515bffd38ec37e992232843c80e7a439
edae1f19c6772d3eb147bcb2a8f6c809ab6c1f26767b3c3b563914b6af5b5648
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
1e2034c9629187cf72c694ea4afa4e901d1235deb37eaf44a1bb4ef37e2d8fa8
c5ac5c59a503e0fd7f4fff7a582e6fc61869c462d3fb33416f216efc568f1a59
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
69dfc009056d06e0ddc5bbca72171c476a91c6b1a8b1785d10b010c2636ae394
9551ec54d3c094cec9648998b03cbeb0176e34c124f5a748e20cac5a1fc3778a
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
080b26b102929dc4cc12b07b28e39ecb0f1e781efd436663b74d401858ee1d5d
1d001f2c36700f767f305521678f43459bc849e74f6c1765a0baeb76d2cfcab4
+2 -1
Переглянути файл
@@ -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:
+1
Переглянути файл
@@ -34,6 +34,7 @@ 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;
+75
Переглянути файл
@@ -0,0 +1,75 @@
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();
});
+76
Переглянути файл
@@ -0,0 +1,76 @@
/**
* 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];
+11 -6
Переглянути файл
@@ -472,13 +472,18 @@ const noSurround = EditorView.inputHandler.of((view, from, to, text) => {
return true;
});
/** Gutter icon groups of Settings › Editor › General › Gutter Icons (stable gutter classes). */
/**
* 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.
*/
export const GUTTER_ICON_GROUPS = [
{ 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" },
{ id: "run" },
{ id: "bookmarks" },
{ id: "inheritors" },
{ id: "supers" },
{ id: "colors" },
] as const;
/**
+4 -6
Переглянути файл
@@ -5,6 +5,7 @@ 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;
@@ -21,7 +22,7 @@ function open(reader: boolean, doc = DOC) {
view = new EditorView({
state: EditorState.create({
doc,
extensions: [java(), renderedDocsExtension, renderDocComments.of(reader)],
extensions: [java(), iconAreaExtension, renderedDocsExtension, renderDocComments.of(reader)],
}),
parent: document.body,
});
@@ -38,11 +39,8 @@ async function hover(v: EditorView, line: number) {
const pressed = (v: EditorView) => toggles(v).map((t) => t.getAttribute("aria-pressed"));
/** 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",
);
/** 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");
/** Opens the file rendering its comments, then brings this one's source back with its pencil. */
async function openFlippedToSource() {
+25 -41
Переглянути файл
@@ -51,13 +51,12 @@ import {
GutterMarker,
ViewPlugin,
WidgetType,
gutter,
type DecorationSet,
type ViewUpdate,
} from "@codemirror/view";
import { syntaxTree } from "@codemirror/language";
import { gutterIconMarkup } from "@/ui/icons";
import { emptyGutterSpacer } from "@/editor/api";
import { iconAreaSource } from "./iconArea";
import { tx, useI18n } from "@/platform/i18n";
import { loadMarkdown, markupToHtml } from "@/editor/lsp/markdown";
import { hasContent, renderDoc, type DocComment, type DocStyle, type RenderedDoc } from "./docRender";
@@ -358,18 +357,6 @@ 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 };
@@ -658,8 +645,8 @@ const docsField = StateField.define<DocsView>({
provide: (f) => EditorView.decorations.from(f, (v) => v.decorations),
});
const toggleGutter = gutter({
class: "cm-openidea-docToggles",
const toggleSource = iconAreaSource.of({
order: 90,
// 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),
@@ -674,24 +661,21 @@ const toggleGutter = gutter({
lineMarkerChange: (update) =>
update.startState.field(hovered) !== update.state.field(hovered) ||
update.transactions.some((tr) => tr.effects.some((e) => e.is(relabel))),
// 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;
},
// 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;
},
});
@@ -874,15 +858,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",
@@ -902,7 +886,7 @@ export const renderedDocsExtension: Extension = [
hovered,
hoverTracker,
showSourceAtCaret,
toggleGutter,
toggleSource,
markdownReady,
languageWatcher,
docMetrics,
+2
Переглянути файл
@@ -42,6 +42,7 @@ 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";
@@ -396,6 +397,7 @@ export function baseExtensions(o: SetupOptions): Extension {
overviewLane,
cornerInset,
codeLensExtension,
iconAreaExtension,
renderedDocsExtension,
EditorView.contentAttributes.of({
spellcheck: "false",
+17
Переглянути файл
@@ -8,6 +8,7 @@ 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")>();
@@ -102,6 +103,22 @@ 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();
+5 -5
Переглянути файл
@@ -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, getAction } from "@/platform/actions";
import { executeAction } 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 opens the file's blame annotations, and leaves them open when shown. */
function showAnnotations(view: EditorView) {
/** The author hint runs Annotate with Git Blame: it shows the file's annotations, or closes them when shown. */
function toggleAnnotations(view: EditorView) {
view.focus();
if (!getAction("vcs.annotate")?.toggled?.()) void executeAction("vcs.annotate");
void executeAction("vcs.annotate");
}
function openUsages(view: EditorView, offset: number) {
@@ -309,7 +309,7 @@ class UsagesLensPlugin {
icon: "user",
order: 20,
kind: "author",
run: showAnnotations,
run: toggleAnnotations,
});
const n = usages ? this.cache.get(key(t)) : undefined;
if (n !== undefined) {
Loaded 100 of 110 files, more files were not shown because too many files have changed in this diff. Show more