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

..
Автор SHA1 Повідомлення Дата
l0ng-ai 21338d557c fix(project-view): paste a clipboard image as img.png
Pasting into the Project view only handled files, so a screenshot on the
clipboard did nothing. With no files to paste, Paste now saves the clipboard
image in the target folder as img.png (img_1.png, img_2.png ... when taken)
and selects it; Paste is enabled while the clipboard holds an image.

The image is read natively: public.png, or public.tiff converted, on macOS;
the registered PNG format, or CF_DIB (24/32-bit) encoded as PNG, on Windows;
GTK on Linux as before.

Fixes #3486
2026-11-15 17:09:42 +08:00
41 змінених файлів з 94 додано та 1839 видалено

No files matched your search

+3 -3
Переглянути файл
@@ -98,10 +98,10 @@ jobs:
# Test fixtures write LF files; keep Git from converting them on checkout.
- run: git config --global core.autocrlf false
- run: cargo nextest run --workspace --no-fail-fast
# nextest ran export_bindings, which rewrites src/bindings.ts and the command snapshot.
- name: Bindings and command snapshot are up to date
# nextest ran export_bindings, which rewrites src/bindings.ts.
- name: Bindings are up to date
if: runner.os == 'Linux'
run: git diff --exit-code src/bindings.ts src-tauri/tests/commands.snap
run: git diff --exit-code src/bindings.ts
# The remote development server ships as a static Linux binary (release-build.yml):
# keep that build working.
-30
Переглянути файл
@@ -325,20 +325,6 @@ pub fn migrate(data: &Path, local: &Path) {
if cfg!(target_os = "windows") && data != local {
migrate_entries(data, local);
}
if cfg!(target_os = "windows") {
relative_tool_shims(&local.join("tools"));
}
}
/// Wrappers written before they named their tool relative to themselves hold its absolute
/// path, which cmd.exe can't find through a non-ASCII user directory (#3338).
fn relative_tool_shims(tools: &Path) {
let Ok(entries) = fs::read_dir(tools) else { return };
for dir in entries.flatten().map(|e| e.path()).filter(|p| p.is_dir()) {
if let Err(error) = relocate_shims(&dir, &dir) {
tracing::warn!(%error, ?dir, "cannot make the tool's wrappers relative");
}
}
}
fn migrate_entries(data: &Path, local: &Path) {
@@ -665,22 +651,6 @@ mod tests {
fs::set_permissions(&dir, fs::Permissions::from_mode(0o755)).unwrap();
}
#[test]
fn installed_tool_wrappers_become_relative() {
let tmp = tempfile::tempdir().unwrap();
let tools = tmp.path().join("tools");
let tool = tools.join("taplo");
fs::create_dir_all(tool.join("bin")).unwrap();
let shim = tool.join("bin/taplo.cmd");
fs::write(&shim, format!("@echo off\r\n\"{}\\taplo.exe\" %*\r\n", tool.display())).unwrap();
// A wrapper the user re-saved in another encoding is left alone.
fs::create_dir_all(tools.join("other/bin")).unwrap();
fs::write(tools.join("other/bin/x.cmd"), b"@echo off\r\n\"C:\\\xd5\xc5\" %*\r\n").unwrap();
relative_tool_shims(&tools);
assert_eq!(fs::read_to_string(&shim).unwrap(), "@echo off\r\n\"%~dp0..\\taplo.exe\" %*\r\n");
relative_tool_shims(&tmp.path().join("missing"));
}
#[test]
fn wrappers_accept_mixed_separators_without_rewriting_neighbor_paths() {
let text = "@echo off\r\n\"C:\\old\\tools/demo\\payload.exe\" \"C:\\old\\tools/demo-other\\x\" %*\r\n";
+30 -141
Переглянути файл
@@ -296,142 +296,39 @@ impl crate::Host {
}
}
/// Commands allowed in Restricted Mode, by exact name: those which only inspect/edit source or
/// operate user-owned application state. A new command is denied until deliberately listed here.
/// Commands which only inspect/edit source or operate user-owned application state.
/// New execution commands are denied until deliberately classified here.
pub fn restricted_command_allowed(cmd: &str) -> bool {
if [
"fs_",
"doc_",
"syntax_",
"search_",
"nav_",
"history_",
"spell_",
"analysis_",
"structural_",
"refactor_",
"bytes_",
"window_",
"window_group_",
"term_",
"settings_",
"project_trust_",
// New Project writes only where the user chose and runs no code of an open project.
"scaffold_",
"ssh_",
"git_credential",
]
.iter()
.any(|p| cmd.starts_with(p))
{
return true;
}
matches!(
cmd,
"fs_compare_directories"
| "fs_copy"
| "fs_copy_merge"
| "fs_create_dir"
| "fs_create_file"
| "fs_create_file_bytes"
| "fs_delete"
| "fs_entry_kind"
| "fs_open_with_system"
| "fs_probe"
| "fs_read_dir"
| "fs_read_image"
| "fs_read_range"
| "fs_read_text"
| "fs_rename"
| "fs_resolve_reference"
| "fs_set_writable"
| "doc_close"
| "doc_edit"
| "doc_folding"
| "doc_highlights"
| "doc_open"
| "doc_open_untitled"
| "doc_open_virtual"
| "doc_outline"
| "doc_python_facts"
| "doc_save"
| "doc_save_as"
| "doc_save_all"
| "doc_selection_ranges"
| "doc_set_bom"
| "doc_set_encoding"
| "doc_set_line_ending"
| "doc_snapshot"
| "doc_sync_from_disk"
| "doc_ui_mode"
| "syntax_errors"
| "syntax_expression_at"
| "syntax_identifiers"
| "syntax_identifiers_in_files"
| "syntax_locals"
| "syntax_node_at"
| "syntax_structural_ranges"
| "syntax_support"
| "search_start"
| "search_validate"
| "nav_index_definitions"
| "nav_inheritance"
| "nav_resolve_module"
| "history_content"
| "history_list"
| "history_list_dir"
| "history_put_label"
| "history_restore"
| "spell_check"
| "spell_suggest"
| "analysis_locate_duplicates"
| "structural_languages"
| "structural_search"
| "structural_validate"
| "refactor_can_undo_file_move"
| "refactor_file_move_edits"
| "refactor_file_move_text_edits"
| "refactor_move_files"
| "refactor_undo_file_move"
| "window_close_context"
| "window_complete_launch"
| "window_cycle"
| "window_flash_taskbar"
| "window_group_cancel_close"
| "window_group_close"
| "window_group_close_tabs"
| "window_group_current"
| "window_group_detach"
| "window_group_merge"
| "window_group_reorder"
| "window_group_restore"
| "window_group_select"
| "window_is_fullscreen"
| "window_new"
| "window_open_comparison"
| "window_open_deployment"
| "window_open_diff"
| "window_open_file_in_new_window"
| "window_open_files"
| "window_open_project"
| "window_open_projects"
| "window_open_remote"
| "window_open_settings"
| "window_set_titlebar_height"
| "window_start_drag"
| "window_take_launch"
| "window_toggle_fullscreen"
| "window_toggle_zoom"
| "term_available_shells"
| "term_default_shell"
| "term_is_busy"
| "term_kill"
| "term_resize"
| "term_spawn"
| "term_store_image"
| "term_write"
| "settings_export"
| "settings_get"
| "settings_get_global"
| "settings_import"
| "settings_list_jetbrains_ides"
| "settings_read_jetbrains"
| "settings_set"
| "project_trust_add_location"
| "project_trust_list"
| "project_trust_remove_location"
| "project_trust_set"
| "project_trust_status"
// New Project writes only where the user chose and runs no code of an open project.
| "scaffold_catalog"
| "scaffold_create"
| "scaffold_options"
| "scaffold_requirements"
| "ssh_askpass_answer"
| "ssh_connected"
| "ssh_disconnect"
| "ssh_needs_secret"
| "ssh_open_terminal"
| "ssh_password_saved"
| "ssh_set_secret"
| "ssh_test"
| "ssh_trust_host"
| "git_credential_forget"
| "git_credentials"
| "app_info"
"app_info"
| "app_build_info"
| "app_cli_install"
| "app_cli_uninstall"
@@ -676,14 +573,6 @@ mod tests {
assert!(super::restricted_command_allowed("clipboard_write_text"));
}
#[test]
fn restricted_mode_denies_new_commands_whatever_their_name() {
for cmd in ["fs_new_command", "term_new_command", "ssh_new_command", "settings_new_command", "git_credential_x"]
{
assert!(!super::restricted_command_allowed(cmd), "{cmd} is allowed without being listed");
}
}
#[test]
fn remote_project_decisions_are_kept_on_this_machine() {
let tmp = tempfile::tempdir().unwrap();
-171
Переглянути файл
@@ -12,7 +12,6 @@ pub(super) fn detect(dir: &Path, out: &mut Vec<RunConfig>) {
let Some(src) = read(&dir.join("build.zig")) else { return };
let src = code_only(&src);
out.push(config(BUILD_ID, "zig build", "zig", "zig", &["build"]));
let roots = test_roots(&src);
for step in steps(&src) {
// `install` is what plain `zig build` runs.
if step == "install" || step == "uninstall" {
@@ -21,9 +20,6 @@ pub(super) fn detect(dir: &Path, out: &mut Vec<RunConfig>) {
let mut c = config(format!("zig:{step}"), format!("zig build {step}"), "zig", "zig", &["build", &step]);
if step == "test" || step.starts_with("test-") || step.starts_with("test_") {
c = c.test();
if let Some((_, root)) = roots.iter().find(|(name, _)| *name == step) {
c.extras.params.insert("testRoot".into(), root.clone());
}
}
out.push(c);
}
@@ -165,137 +161,6 @@ fn executables(src: &str) -> Vec<Executable> {
out
}
/// The call's argument text: from just after its `(` to the matching `)`.
fn call_body(src: &str, start: usize) -> &str {
let (mut depth, mut in_string, mut escaped) = (1usize, false, false);
for (i, c) in src[start..].char_indices() {
if in_string {
match c {
_ if escaped => escaped = false,
'\\' => escaped = true,
'"' => in_string = false,
_ => {}
}
continue;
}
match c {
'"' => in_string = true,
'(' | '{' | '[' => depth += 1,
')' | '}' | ']' => {
depth -= 1;
if depth == 0 {
return &src[start..start + i];
}
}
_ => {}
}
}
src
}
/// The first `.root_source_file = <receiver>.path("…")` in `body`.
fn root_source_file(body: &str) -> Option<String> {
for (i, _) in body.match_indices(".root_source_file") {
let Some(v) = body[i + ".root_source_file".len()..].trim_start().strip_prefix('=') else { continue };
let v = v.trim_start();
if let Some(call) = v.find(".path(")
&& v[..call].chars().all(|c| c.is_alphanumeric() || c == '_')
{
return string_at(&v[call + ".path(".len()..]);
}
}
None
}
/// The identifier assigned just before `at`: `const mod = b.addModule(…` → `mod`.
fn assigned_var(src: &str, at: usize) -> Option<&str> {
let before = src[..at].trim_end();
let before = before.strip_suffix('.')?.trim_end();
// Drop the receiver (`b`) that sits between the `=` and the call.
let receiver =
before.char_indices().rev().take_while(|(_, c)| c.is_alphanumeric() || *c == '_').last().map(|(i, _)| i)?;
let before = before[..receiver].trim_end();
let before = before.strip_suffix('=')?.trim_end();
let start =
before.char_indices().rev().take_while(|(_, c)| c.is_alphanumeric() || *c == '_').last().map(|(i, _)| i)?;
Some(&before[start..])
}
/// The test root behind each test-named step (`zig build <step>`): the step's `dependOn` runs
/// an `addTest` artifact — a variable (`const tests = b.addTest(…)`) or an inline call — whose
/// module's `root_source_file` this resolves (through `addModule`/`createModule` variables).
/// `zig build` forwards no args to the test binary, so rerunning a single failed test goes
/// through a standalone `zig test <root> --test-filter …` on the step's own test module.
fn test_roots(src: &str) -> Vec<(String, String)> {
let mut modules: Vec<(String, String)> = Vec::new();
for key in ["addModule(", "createModule("] {
for (i, _) in src.match_indices(key) {
let Some(root) = root_source_file(call_body(src, i + key.len())) else { continue };
if let Some(var) = assigned_var(src, i)
&& !modules.iter().any(|(m, _)| *m == var)
{
modules.push((var.to_owned(), root));
}
}
}
let module_root = |body: &str| -> Option<String> {
root_source_file(body).or_else(|| {
let at = body.find(".root_module")?;
let v = body[at + ".root_module".len()..].trim_start().strip_prefix('=')?.trim_start();
let var: String = v.chars().take_while(|c| c.is_alphanumeric() || *c == '_').collect();
modules.iter().find(|(m, _)| *m == var).map(|(_, root)| root.clone())
})
};
let mut tests: Vec<(String, String)> = Vec::new();
for (i, _) in src.match_indices("addTest(") {
let Some(root) = module_root(call_body(src, i + "addTest(".len())) else { continue };
if let Some(var) = assigned_var(src, i)
&& !tests.iter().any(|(v, _)| *v == var)
{
tests.push((var.to_owned(), root));
}
}
let mut steps: Vec<(String, String)> = Vec::new();
for (i, _) in src.match_indices(".step(\"") {
let Some(name) = string_at(&src[i + ".step(".len()..]) else { continue };
// The match includes the dot, so the assignment ends one character earlier.
if let Some(var) = assigned_var(src, i + 1) {
steps.push((var.to_owned(), name));
}
}
let mut out: Vec<(String, String)> = Vec::new();
for (i, _) in src.match_indices(".dependOn(&") {
let Some(step) = receiver_var(src, i + 1) else { continue };
let Some((_, name)) = steps.iter().find(|(v, _)| v == step) else { continue };
let after = &src[i + ".dependOn(&".len()..];
let artifact = if let Some(at) = after.find("addRunArtifact(") {
let v = &after[at + "addRunArtifact(".len()..];
let var: String = v.chars().take_while(|c| c.is_alphanumeric() || *c == '_').collect();
tests.iter().find(|(v, _)| *v == var).map(|(_, root)| root.clone())
} else if let Some(at) = after.find("addTest(") {
module_root(call_body(after, at + "addTest(".len()))
} else {
None
};
if let Some(root) = artifact
&& name.starts_with("test")
&& !out.iter().any(|(n, _)| n == name)
{
out.push((name.clone(), root));
}
}
out
}
/// The identifier a method is called on just before `at`: `test_step.dependOn(…` → `test_step`.
fn receiver_var(src: &str, at: usize) -> Option<&str> {
let before = src[..at].trim_end();
let before = before.strip_suffix('.')?;
let start =
before.char_indices().rev().take_while(|(_, c)| c.is_alphanumeric() || *c == '_').last().map(|(i, _)| i)?;
Some(&before[start..])
}
#[cfg(test)]
mod tests {
use super::*;
@@ -325,9 +190,7 @@ pub fn build(b: *std.Build) void {
}) });
_ = tool;
const run_step = b.step("run", "Run the app");
const tests = b.addTest(.{ .root_module = mod });
const test_step = b.step("test", "Run tests");
test_step.dependOn(&b.addRunArtifact(tests).step);
const docs = b.step("docs", "Generate docs // not a comment");
_ = .{ run_step, test_step, docs };
}
@@ -365,39 +228,5 @@ pub fn build(b: *std.Build) void {
assert_eq!(app.extras.before_launch[0].kind, "run");
assert_eq!(app.extras.before_launch[0].target, BUILD_ID);
assert_eq!(app.extras.params.get("source").map(String::as_str), Some("src/main.zig"));
assert_eq!(test.extras.params.get("testRoot").map(String::as_str), Some("src/root.zig"));
}
const TEST_ROOTS: &str = r#"const std = @import("std");
pub fn build(b: *std.Build) void {
const tally = b.addModule("tally", .{ .root_source_file = b.path("src/tally.zig") });
const unit = b.addTest(.{ .root_module = tally });
const test_step = b.step("test", "Run the unit tests");
test_step.dependOn(&b.addRunArtifact(unit).step);
const failing = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/failing.zig"),
}) });
const test_failing_step = b.step("test-failing", "Run the failing tests");
test_failing_step.dependOn(&b.addRunArtifact(failing).step);
const direct = b.addTest(.{ .root_source_file = b.path("src/direct.zig") });
const test_direct_step = b.step("test-direct", "Run the direct tests");
test_direct_step.dependOn(&b.addRunArtifact(direct).step);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&b.addRunArtifact(unit).step);
}
"#;
#[test]
fn test_roots_come_from_the_step_s_own_artifact() {
let src = code_only(TEST_ROOTS);
assert_eq!(
test_roots(&src),
[
("test".to_owned(), "src/tally.zig".to_owned()),
("test-failing".to_owned(), "src/failing.zig".to_owned()),
("test-direct".to_owned(), "src/direct.zig".to_owned()),
]
);
}
}
+3 -28
Переглянути файл
@@ -331,8 +331,8 @@ pub fn env_wrapper(bin_dir: &Path, command: &str, target: &Path, env: &[(&str, &
#[cfg(not(unix))]
{
let link = bin_dir.join(format!("{command}.cmd"));
let vars: String = env.iter().map(|(k, v)| format!("set \"{k}={}\"\r\n", cmd_path(bin_dir, v))).collect();
fs::write(&link, format!("@echo off\r\nsetlocal\r\n{vars}\"{}\" %*\r\n", cmd_path(bin_dir, target)))?;
let vars: String = env.iter().map(|(k, v)| format!("set \"{k}={}\"\r\n", v.display())).collect();
fs::write(&link, format!("@echo off\r\nsetlocal\r\n{vars}\"{}\" %*\r\n", target.display()))?;
Ok(link)
}
}
@@ -357,25 +357,11 @@ pub fn link_executable(bin_dir: &Path, command: &str, target: &Path) -> IdeResul
{
let link = bin_dir.join(format!("{command}.cmd"));
let runner = if target.extension().is_some_and(|e| e == "js") { "node " } else { "" };
fs::write(&link, format!("@echo off\r\n{runner}\"{}\" %*\r\n", cmd_path(bin_dir, target)))?;
fs::write(&link, format!("@echo off\r\n{runner}\"{}\" %*\r\n", target.display()))?;
Ok(link)
}
}
/// `path` as a `.cmd` shim in `bin_dir` names it: relative to the shim (`%~dp0..\…`) when it
/// is in the tool's own directory. cmd.exe reads a batch file in the console's code page, so
/// an absolute path through a non-ASCII user directory, written as UTF-8, isn't found (#3338).
#[cfg_attr(unix, allow(dead_code))]
fn cmd_path(bin_dir: &Path, path: &Path) -> String {
match bin_dir.parent().and_then(|tool| path.strip_prefix(tool).ok()) {
Some(rest) => {
let rest: Vec<_> = rest.components().map(|c| c.as_os_str().to_string_lossy()).collect();
format!("%~dp0..\\{}", rest.join("\\"))
}
None => path.display().to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
@@ -757,17 +743,6 @@ mod tests {
assert!(found.ends_with("server/com.microsoft.java.debug.plugin-0.53.2.jar"));
}
#[test]
fn windows_shims_name_the_tool_relative_to_themselves() {
let tool = Path::new("/Users/张三/AppData/Local/ai.l0ng.openidea/tools/taplo");
let bin = tool.join("bin");
assert_eq!(cmd_path(&bin, &tool.join("taplo.exe")), "%~dp0..\\taplo.exe");
assert_eq!(cmd_path(&bin, &tool.join("gems/bin/solargraph")), "%~dp0..\\gems\\bin\\solargraph");
// Outside the tool's directory (a system SDK) stays absolute.
let sdk = Path::new("/usr/local/share/dotnet");
assert_eq!(cmd_path(&bin, sdk), sdk.display().to_string());
}
#[cfg(unix)]
#[test]
fn wrapper_runs_target() {
+2 -2
Переглянути файл
@@ -197,5 +197,5 @@ You don't write anything special for remote development. In a remote window, `sr
1. Put the logic in the owning crate; convert errors to `IdeError` at its edge; use IPC coordinates.
2. Add the shared implementation to `ide-host::ops::<domain>` if it touches a project; register it with the remote dispatcher if remote windows need it.
3. Add the `#[tauri::command] #[specta::specta]` adapter in `src-tauri/src/commands/<domain>.rs` and list it in `collect_commands!`.
4. Decide its trust class: list it by exact name in `restricted_command_allowed` (also in Restricted Mode) or `projectless_command_allowed` (also with no project open), or leave it out to require a trusted project. There are no name prefixes; if it executes anything, leave it out.
5. `pnpm gen:bindings`, then call it with `call(commands.yourCommand(...))`. It also rewrites `src-tauri/tests/commands.snap`; check that the new line shows the trust class and placement you meant.
4. If it executes anything, leave it out of the restricted-mode allowlist (it is denied in untrusted projects by default).
5. `pnpm gen:bindings`, then call it with `call(commands.yourCommand(...))`.
+1 -1
Переглянути файл
@@ -31,7 +31,7 @@ Opening a project folder can run code that the project controls: language server
- When a project that hasn't been decided opens, the **Trust and Open Project?** dialog offers **Trust Project**, **Preview in Restricted Mode** and **Don't Open**. Decisions and trusted locations are managed on Settings' **Project Trust** page (group **Security**), and **Revoke Trust** is an action.
- Trust is user-owned state (`crates/ide-host/src/trust.rs`). **Project settings never grant trust.**
- Enforcement is in the backend, not the UI: every IPC command passes `Host::authorize_command` in the Tauri invoke handler (`src-tauri/src/lib.rs`) before it runs. In an untrusted project only commands on an explicit allowlist (`restricted_command_allowed`) run: reading and editing files and documents, syntax, search, navigation, local history, spelling, analysis, refactoring, settings and similar.
- The allowlist is a default-deny list of exact names: **a new command that executes anything is denied in restricted mode until you deliberately classify it there.** Don't add an execution command to the allowlist to make a feature "work" in restricted mode. `src-tauri/tests/commands.snap` lists every command's trust class, so a change shows up in review.
- The allowlist is a default-deny list: **a new command that executes anything is denied in restricted mode until you deliberately classify it there.** Don't add an execution command to the allowlist to make a feature "work" in restricted mode.
- Below the command layer, language servers don't start (`LspManager` execution switch), and git runs with execution disabled and without the project's `git` executable setting until the project is trusted. Project plugins (`.openidea/plugins/`) load only for trusted projects.
- In a remote window the desktop checks the remote project's trust before forwarding a command, and `openidea-server` authorizes every `invoke` again.
+6 -6
Переглянути файл
@@ -7,12 +7,12 @@ Smoke tests check each language end to end with the real tools the IDE uses: lan
They are not part of `cargo nextest run` or `pnpm test`, because they need the tools installed. CI runs them in the **Language smoke** workflow with pinned versions.
| Suite | What it checks | Languages |
| ----------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| `crates/ide-host/tests/language_smoke.rs` | Code intelligence through the `ops` the app's commands call | typescript, python, rust, go, java, kotlin, php |
| `crates/ide-host/tests/project_smoke.rs` | Opening a fixture with its build tool and SDK | `maven_sync`, `jdk`, `gradle_sync`, `python_venv` |
| `smoke/run.test.ts` | Run and test configurations through the run store and a real `openidea-server` | typescript, python, rust, go, java, kotlin, php, zig |
| `smoke/debug.test.ts` | Debugging the entry point with the debugger the IDE installs | typescript, python, rust, go, java, kotlin, c, cpp, zig, php |
| Suite | What it checks | Languages |
| ----------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------- |
| `crates/ide-host/tests/language_smoke.rs` | Code intelligence through the `ops` the app's commands call | typescript, python, rust, go, java, kotlin, php |
| `crates/ide-host/tests/project_smoke.rs` | Opening a fixture with its build tool and SDK | `maven_sync`, `jdk`, `gradle_sync`, `python_venv` |
| `smoke/run.test.ts` | Run and test configurations through the run store and a real `openidea-server` | typescript, python, rust, go, java, kotlin, php |
| `smoke/debug.test.ts` | Debugging the entry point with the debugger the IDE installs | typescript, python, rust, go, java, kotlin, c, cpp, php |
## Language smoke
+2 -2
Переглянути файл
@@ -197,5 +197,5 @@ onIdeEvent("projectTrustChanged", (e) => {
1. 逻辑放在所属的 crate 里;在其边界把错误转成 `IdeError`;使用 IPC 坐标。
2. 如果涉及项目,把共享实现加到 `ide-host::ops::<domain>`;远程窗口需要的话,注册到远程 dispatcher。
3. 在 `src-tauri/src/commands/<domain>.rs` 添加 `#[tauri::command] #[specta::specta]` 适配函数,并加入 `collect_commands!`。
4. 决定它的信任级别:在 `restricted_command_allowed`(受限模式下也可运行)或 `projectless_command_allowed`(未打开项目时也可运行)中按完整名称列出它,或者不列出,即需要受信任的项目。没有名称前缀规则;会执行任何东西的命令不要列出。
5. 运行 `pnpm gen:bindings`,然后用 `call(commands.yourCommand(...))` 调用。它也会重写 `src-tauri/tests/commands.snap`;检查新增的那一行是否是你想要的信任级别和运行位置。
4. 如果它会执行任何东西,不要把它加进受限模式白名单(未受信任的项目里默认拒绝)。
5. 运行 `pnpm gen:bindings`,然后用 `call(commands.yourCommand(...))` 调用。
+1 -1
Переглянути файл
@@ -28,7 +28,7 @@ description: "如何报告漏洞,以及贡献者需要维护的安全模型:
- 打开一个尚未做过决定的项目时,会弹出 **信任并打开项目?** 对话框,提供 **信任项目**、**以受限模式预览** 和 **不打开**。已有决定和受信任的位置在设置的 **项目信任** 页面(**安全** 分组)里管理,**撤销信任** 是一个 action。
- 信任是用户自己的状态(`crates/ide-host/src/trust.rs`)。**项目设置永远不能授予信任。**
- 拦截在后端而不是 UI:每个 IPC 命令执行前,都要在 Tauri 的 invoke handler(`src-tauri/src/lib.rs`)里经过 `Host::authorize_command`。未受信任的项目里,只有显式白名单(`restricted_command_allowed`)中的命令能运行:读写文件和文档、语法、搜索、导航、本地历史、拼写、分析、重构、设置等。
- 这份白名单按完整名称列出,默认拒绝:**新增的任何会执行东西的命令,在你有意识地把它归类之前,受限模式下一律拒绝。** 不要为了让某个功能在受限模式下“能用”就把执行类命令加进白名单。`src-tauri/tests/commands.snap` 列出每个命令的信任级别,改动会出现在审查的 diff 里。
- 这份白名单是默认拒绝的:**新增的任何会执行东西的命令,在你有意识地把它归类之前,受限模式下一律拒绝。** 不要为了让某个功能在受限模式下“能用”就把执行类命令加进白名单。
- 在命令层之下,项目受信任之前语言服务器不会启动(`LspManager` 的执行开关),git 以禁止执行的方式运行,也不使用项目里配置的 `git` 可执行文件。项目插件(`.openidea/plugins/`)只在受信任的项目中加载。
- 远程窗口中,桌面端在转发命令前会先确认远程项目是否受信任,`openidea-server` 对每个 `invoke` 还会再校验一次。
+6 -6
Переглянути файл
@@ -7,12 +7,12 @@ description: "在 fixtures 示例项目上,用真实语言服务器跑语言
由于需要安装这些工具,冒烟测试不包含在 `cargo nextest run` 或 `pnpm test` 中。CI 在 **Language smoke** 工作流里用固定版本运行它们。
| 套件 | 检查内容 | 语言 |
| ----------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| `crates/ide-host/tests/language_smoke.rs` | 经由应用命令所调用的 `ops` 检查代码智能 | typescript、python、rust、go、java、kotlin、php |
| `crates/ide-host/tests/project_smoke.rs` | 用构建工具和 SDK 打开示例项目 | `maven_sync`、`jdk`、`gradle_sync`、`python_venv` |
| `smoke/run.test.ts` | 通过 run store 和真实的 `openidea-server` 执行运行与测试配置 | typescript、python、rust、go、java、kotlin、php、zig |
| `smoke/debug.test.ts` | 用 IDE 安装的调试器调试入口点 | typescript、python、rust、go、java、kotlin、c、cpp、zig、php |
| 套件 | 检查内容 | 语言 |
| ----------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------- |
| `crates/ide-host/tests/language_smoke.rs` | 经由应用命令所调用的 `ops` 检查代码智能 | typescript、python、rust、go、java、kotlin、php |
| `crates/ide-host/tests/project_smoke.rs` | 用构建工具和 SDK 打开示例项目 | `maven_sync`、`jdk`、`gradle_sync`、`python_venv` |
| `smoke/run.test.ts` | 通过 run store 和真实的 `openidea-server` 执行运行与测试配置 | typescript、python、rust、go、java、kotlin、php |
| `smoke/debug.test.ts` | 用 IDE 安装的调试器调试入口点 | typescript、python、rust、go、java、kotlin、c、cpp、php |
## 语言冒烟测试
+2 -64
Переглянути файл
@@ -174,36 +174,12 @@ test("⌘R replaces every match in the file", async ({ workbench: page }) => {
await expect(editor.locator(".cm-line", { hasText: "OrderDto" })).toHaveCount(2);
});
test("Markdown preview highlights ⌘F matches, selected words and scales diagrams with font zoom", async ({
workbench: page,
}) => {
await page.evaluate(async () => {
const svg =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 96" width="320" height="96"><!-- svg-source:excalidraw --><rect width="320" height="96"/></svg>';
const url = `data:image/svg+xml;base64,${btoa(svg)}`;
const routeModule = "/src/platform/tauriCore.ts";
const { setInvokeRoute } = await import(/* @vite-ignore */ routeModule);
setInvokeRoute((cmd: string) => (cmd === "fs_read_image" ? Promise.resolve(url) : null));
});
test("Markdown preview highlights ⌘F matches and selected word occurrences", async ({ workbench: page }) => {
const editor = await openFromTree(page, "README.md");
const content = editor.locator(".cm-content");
await content.click();
await page.keyboard.press("Meta+a");
await page.keyboard.insertText(
[
"# Order Service",
"",
"Manage **Order** items and `Order` status.",
"",
"```mermaid",
"flowchart LR",
" A --> B",
"```",
"",
"![Diagram](./arch.excalidraw.svg)",
].join("\n"),
);
await page.keyboard.insertText("# Order Service\n\nManage **Order** items and `Order` status.\n");
const preview = page.getByRole("document", { name: "Markdown preview" });
await expect(preview).toContainText("Manage Order items");
@@ -233,44 +209,6 @@ test("Markdown preview highlights ⌘F matches, selected words and scales diagra
})),
)
.toEqual({ current: ["Order"], other: ["Order", "Order"] });
const mermaidSvg = preview.locator(".mermaid-output svg");
const excalidrawImg = preview.locator('img[alt="Diagram"]');
await expect(mermaidSvg).toBeVisible();
await expect(excalidrawImg).toHaveAttribute("src", /^data:image\/svg\+xml/);
const widths = async () => ({
mermaid: (await mermaidSvg.boundingBox())!.width,
excalidraw: (await excalidrawImg.boundingBox())!.width,
});
const base = await widths();
expect(base.mermaid).toBeGreaterThan(50);
expect(base.excalidraw).toBeCloseTo(320, 0);
const runAction = (id: string, times = 1) =>
page.evaluate(
async ({ id, times }) => {
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
for (let i = 0; i < times; i++) await executeAction(id);
},
{ id, times },
);
await runAction("editor.increaseFontSize", 4);
const zoomedIn = await widths();
expect(zoomedIn.mermaid / base.mermaid).toBeCloseTo(17 / 13, 2);
expect(zoomedIn.excalidraw / base.excalidraw).toBeCloseTo(17 / 13, 2);
await runAction("editor.decreaseFontSize", 6);
const zoomedOut = await widths();
expect(zoomedOut.mermaid / base.mermaid).toBeCloseTo(11 / 13, 2);
expect(zoomedOut.excalidraw / base.excalidraw).toBeCloseTo(11 / 13, 2);
await runAction("editor.resetFontSize");
const reset = await widths();
expect(reset.mermaid).toBeCloseTo(base.mermaid, 1);
expect(reset.excalidraw).toBeCloseTo(base.excalidraw, 1);
});
test("the bookmark gutter takes no width until the file has a bookmark", async ({ workbench: page }) => {
-7
Переглянути файл
@@ -28,11 +28,4 @@ pub fn build(b: *std.Build) void {
const tests = b.addTest(.{ .root_module = tally });
const test_step = b.step("test", "Run the tests");
test_step.dependOn(&b.addRunArtifact(tests).step);
const failing_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/failing.zig"),
.target = target,
}) });
const test_failing_step = b.step("test-failing", "Run the tests that fail on purpose");
test_failing_step.dependOn(&b.addRunArtifact(failing_tests).step);
}
-5
Переглянути файл
@@ -1,5 +0,0 @@
//! Fails on purpose: the `test-failing` step, for checking that a run's failure shows up
//! in the test tree and Rerun Failed Tests re-runs it alone.
test "intentionally fails" {
return error.OpenideaFail;
}
+1 -2
Переглянути файл
@@ -3,8 +3,7 @@ const tally = @import("tally");
pub fn main() !void {
const prices = [_]u32{ 4999, 2499, 5999 };
const sum = tally.total(&prices);
const sum = tally.total(&prices); // Set a breakpoint here
var buf: [16]u8 = undefined;
// Set a breakpoint here (QA: debugger) and inspect `sum`.
std.debug.print("Total: {s}\n", .{try tally.format(&buf, sum)});
}
-11
Переглянути файл
@@ -164,17 +164,6 @@ const CASES: Record<string, Case> = {
variable: "line",
evaluate: ["print line", / = /],
},
// Zig ships no debugger of its own: CodeLLDB debugs the binary `zig build` produces.
// The breakpoint lands on the last use of `sum`: zig's debuginfo gives a const local a
// location only within its live range, so `prices` (used earlier) is not in the frame.
zig: {
fixture: "zig-app",
tools: ["codelldb"],
adapter: "codelldb",
file: "src/main.zig",
variable: "sum",
evaluate: ["sum", /13497/],
},
php: {
fixture: "php-app",
setup: (root) =>
-13
Переглянути файл
@@ -135,19 +135,6 @@ const CASES: Record<string, Case> = {
file: "ThresholdCustomsTest.php",
},
},
// The failing run uses the fixture's dedicated `test-failing` step (`zig build` forwards
// no args to the test binary, so a failing test can't be switched on through the config).
zig: {
fixture: "zig-app",
run: { config: "zig:run", prints: "Total: $134.97" },
tests: {
config: "zig:test-failing",
failing: (c) => c,
passed: 0,
failed: "intentionally fails",
file: "src/failing.zig",
},
},
};
let server: Server | null = null;
-698
Переглянути файл
@@ -1,698 +0,0 @@
# Generated by `pnpm gen:bindings`; do not edit. One line per command:
# name, trust class, placement in a remote window, in bindings.ts, how Tauri runs it.
agent_accept_changes trusted project_host bindings async
agent_archive always project_host bindings sync
agent_base_text trusted project_host bindings async
agent_cancel always project_host bindings sync
agent_changes trusted project_host bindings async
agent_commands always project_host bindings async
agent_create trusted project_host bindings async
agent_create_ephemeral trusted desktop bindings async
agent_custom_import trusted desktop bindings sync
agent_custom_remove trusted desktop bindings sync
agent_custom_save trusted desktop bindings sync
agent_delete trusted project_host bindings async
agent_entries always project_host bindings sync
agent_external_sessions trusted project_host bindings async
agent_fork trusted project_host bindings async
agent_grouped_changes trusted project_host bindings async
agent_import_session trusted project_host bindings async
agent_mcp_import always project_host bindings sync
agent_mcp_list always project_host bindings sync
agent_mcp_remove always project_host bindings sync
agent_mcp_save always project_host bindings sync
agent_mcp_set_enabled always project_host bindings sync
agent_probe trusted project_host bindings async
agent_prompt trusted project_host bindings async
agent_providers trusted project_host bindings sync
agent_refresh_models trusted project_host bindings sync
agent_registry_install always project_host bindings async
agent_registry_list always project_host bindings async
agent_registry_remove always project_host bindings async
agent_rename trusted project_host bindings sync
agent_respond trusted project_host bindings sync
agent_rollback trusted project_host bindings async
agent_rollback_changes trusted project_host bindings async
agent_send_queued_now trusted project_host bindings sync
agent_set_command trusted project_host bindings sync
agent_set_config trusted project_host bindings async
agent_set_env trusted project_host bindings sync
agent_stop_background always project_host bindings async
agent_subscribe always project_host bindings sync
agent_unarchive always project_host bindings sync
agent_unqueue always project_host bindings sync
analysis_locate_duplicates always project_host bindings async
android_devices trusted desktop bindings async
android_logcat trusted desktop bindings async
app_build_info always desktop bindings sync
app_cancel_quit always desktop bindings sync
app_check_update always desktop bindings async
app_cli_install always desktop bindings async
app_cli_uninstall always desktop bindings async
app_info always desktop bindings sync
app_install_update always desktop bindings async
app_log_location always desktop bindings sync
app_metrics always desktop bindings async
app_quit always desktop bindings sync
app_release_notes trusted desktop bindings async
app_restart always desktop bindings sync
app_update_announcement always desktop bindings sync
app_update_status always desktop bindings sync
app_update_window_ready always desktop bindings sync
apply_workspace_edit always project_host bindings async
build_compile_file trusted project_host bindings async
build_model trusted project_host bindings async
build_run trusted project_host bindings async
build_sync trusted project_host bindings async
caches_local_data_info trusted desktop bindings sync
caches_schedule_invalidation always desktop bindings sync
caches_set_local_data_dir trusted desktop bindings sync
cancel_request always project_host bindings sync
cancel_task always project_host bindings sync
clear_caches always desktop bindings async
clipboard_file_list always desktop bindings async
clipboard_has_files always desktop bindings sync
clipboard_image always desktop bindings async
clipboard_set_file_list always desktop bindings async
clipboard_text trusted desktop bindings async
clipboard_write_text always desktop bindings async
close_project always project_host bindings spawn
coverage_collect trusted project_host bindings async
coverage_import always project_host bindings async
coverage_prepare trusted project_host bindings async
db_apply_edits trusted project_host bindings async
db_completion trusted project_host bindings async
db_connect trusted project_host bindings async
db_connected trusted project_host bindings sync
db_console_path always project_host bindings sync
db_consoles always project_host bindings sync
db_database_catalog trusted project_host bindings async
db_databases trusted project_host bindings async
db_ddl trusted project_host bindings async
db_disconnect trusted project_host bindings async
db_execute trusted project_host bindings async
db_explain trusted project_host bindings async
db_export_file always desktop bindings async
db_finish_transaction trusted project_host bindings async
db_history trusted project_host bindings async
db_object_ddl trusted project_host bindings async
db_remove_history trusted project_host bindings async
db_retain_catalog trusted project_host bindings async
db_save_sources trusted project_host bindings async
db_saved_catalog trusted project_host bindings async
db_schema_objects trusted project_host bindings async
db_schemas trusted project_host bindings async
db_session_context trusted project_host bindings async
db_set_manual_commit trusted project_host bindings async
db_set_password trusted project_host bindings async
db_set_ssh_secret trusted project_host bindings async
db_sources trusted project_host bindings sync
db_statements trusted project_host bindings sync
db_table_details trusted project_host bindings async
db_table_page trusted project_host bindings async
db_tables trusted project_host bindings async
db_test trusted project_host bindings async
db_test_tunnel trusted project_host bindings async
db_trust_ssh_host trusted project_host bindings async
debug_attachable_processes always project_host bindings async
debug_breakpoint_states trusted project_host bindings sync
debug_capabilities trusted project_host bindings sync
debug_completions trusted project_host bindings async
debug_data_breakpoint_info trusted project_host bindings async
debug_evaluate trusted project_host bindings async
debug_evaluate_in trusted project_host bindings async
debug_exception_filters trusted project_host bindings sync
debug_force_step_over trusted project_host bindings async
debug_free_port trusted project_host bindings async
debug_heap_capture trusted project_host bindings async
debug_heap_classes trusted project_host bindings async
debug_heap_close trusted project_host bindings async
debug_heap_compare trusted project_host bindings async
debug_heap_dominators trusted project_host bindings async
debug_heap_open trusted project_host bindings async
debug_heap_path trusted project_host bindings async
debug_heap_save trusted project_host bindings async
debug_hot_reload trusted desktop bindings async
debug_hot_restart trusted desktop bindings async
debug_js_custom_breakpoints trusted project_host bindings async
debug_js_response_body trusted project_host bindings async
debug_js_response_overrides trusted project_host bindings async
debug_js_start_profile trusted project_host bindings async
debug_js_stop_profile trusted project_host bindings async
debug_jvm_memory_classes trusted project_host bindings async
debug_jvm_memory_fields trusted project_host bindings async
debug_jvm_memory_instances trusted project_host bindings async
debug_jvm_memory_referrers trusted project_host bindings async
debug_listen_for_jvm trusted project_host bindings async
debug_pause trusted project_host bindings async
debug_redefine_classes trusted project_host bindings async
debug_restart_frame trusted project_host bindings async
debug_resume trusted project_host bindings async
debug_run_to trusted project_host bindings async
debug_scopes trusted project_host bindings async
debug_send_input trusted project_host bindings async
debug_sessions always project_host bindings sync
debug_set_breakpoints trusted project_host bindings async
debug_set_data_breakpoints trusted project_host bindings async
debug_set_exception_breakpoints trusted project_host bindings async
debug_set_function_breakpoints trusted project_host bindings async
debug_set_variable trusted project_host bindings async
debug_stack_trace trusted project_host bindings async
debug_start trusted project_host bindings async
debug_step trusted project_host bindings async
debug_step_in_target trusted project_host bindings async
debug_step_in_targets trusted project_host bindings async
debug_stop always project_host bindings async
debug_threads trusted project_host bindings async
debug_variables trusted project_host bindings async
dependency_versions trusted project_host bindings async
deploy_compare trusted project_host bindings async
deploy_coverage always project_host bindings async
deploy_delete_remote trusted project_host bindings async
deploy_download trusted project_host bindings async
deploy_info trusted project_host bindings async
deploy_server_root trusted project_host bindings async
deploy_sync trusted project_host bindings async
deploy_test_connection always project_host bindings async
deploy_upload trusted project_host bindings async
doc_close always project_host bindings async
doc_edit always project_host bindings async
doc_folding always project_host bindings async
doc_highlights always project_host bindings async
doc_open always project_host bindings async
doc_open_untitled always project_host bindings async
doc_open_virtual always project_host bindings async
doc_outline always project_host bindings async
doc_python_facts always project_host bindings async
doc_save always project_host bindings async
doc_save_all always project_host bindings async
doc_save_as always project_host bindings async
doc_selection_ranges always project_host bindings async
doc_set_bom always project_host bindings async
doc_set_encoding always project_host bindings async
doc_set_line_ending always project_host bindings async
doc_snapshot always project_host bindings async
doc_sync_from_disk always project_host bindings async
doc_ui_mode always project_host bindings async
docker_compose_op trusted desktop bindings async
docker_container_op trusted desktop bindings async
docker_container_stats trusted desktop bindings async
docker_container_top trusted desktop bindings async
docker_events trusted desktop bindings async
docker_image_history trusted desktop bindings async
docker_inspect trusted desktop bindings async
docker_logs trusted desktop bindings async
docker_prune trusted desktop bindings async
docker_pull trusted desktop bindings async
docker_registry_login trusted desktop bindings async
docker_remove trusted desktop bindings async
docker_run_env always project_host bindings async
docker_save_settings always desktop bindings async
docker_set_registry_password always desktop bindings async
docker_settings always desktop bindings async
docker_snapshot trusted desktop bindings async
end_process trusted desktop bindings async
env_reload always project_host bindings async
file_dialog_needs_gtk trusted desktop bindings async
find_dirs always project_host bindings sync
find_files always project_host bindings sync
find_files_named always project_host bindings async
find_symbols always project_host bindings sync
fs_compare_directories always project_host bindings async
fs_copy always project_host bindings async
fs_copy_merge always project_host bindings async
fs_create_dir always project_host bindings sync
fs_create_file always project_host bindings sync
fs_create_file_bytes always project_host bindings async
fs_delete always project_host bindings async
fs_entry_kind always project_host bindings async
fs_open_with_system always desktop bindings async
fs_probe always project_host bindings async
fs_read_dir always project_host bindings async
fs_read_image always project_host bindings async
fs_read_range always project_host bindings async
fs_read_text always project_host bindings async
fs_rename always project_host bindings async
fs_resolve_reference always project_host bindings async
fs_set_writable always project_host bindings sync
gh_account_repos trusted desktop bindings async
gh_api trusted desktop bindings async
gh_availability trusted desktop bindings async
gh_pr_checkout trusted desktop bindings async
gh_pr_comment trusted desktop bindings async
gh_pr_create trusted desktop bindings async
gh_pr_list trusted desktop bindings async
gh_pr_prepare_diff trusted desktop bindings async
gh_pr_review trusted desktop bindings async
gh_pr_review_comments trusted desktop bindings async
gh_pr_view trusted desktop bindings async
git_credential_forget always desktop bindings sync
git_credentials always desktop bindings sync
gradle_dependencies trusted project_host bindings async
gradle_link_projects trusted project_host bindings async
gradle_published_catalog trusted project_host bindings async
gradle_unlink_projects trusted project_host bindings async
gtk_pick_paths trusted desktop bindings async
history_content always project_host bindings async
history_list always project_host bindings async
history_list_dir always project_host bindings async
history_put_label always project_host bindings sync
history_restore always project_host bindings async
http_curl trusted desktop bindings async
http_environment_file trusted desktop bindings async
http_environments trusted desktop bindings async
http_execute trusted desktop bindings async
http_from_curl trusted desktop bindings sync
http_history trusted desktop bindings sync
http_history_clear trusted desktop bindings sync
http_history_get trusted desktop bindings sync
http_requests trusted desktop bindings sync
http_variable_definitions trusted desktop bindings async
index_file_extensions always project_host bindings sync
index_status always project_host bindings sync
inspect_code trusted project_host bindings async
java_build_workspace trusted project_host bindings async
java_debug_server trusted project_host bindings async
java_resolve_launch trusted project_host bindings async
jdk_download always project_host bindings async
jdk_download_location always project_host bindings sync
jdk_download_releases always project_host bindings async
jdk_download_vendors always project_host bindings sync
jdtls_required_java always project_host bindings async
jvm_file_presentations always project_host bindings async
languages always desktop bindings sync
light_edit_open always desktop bindings async
light_edit_open_untitled always desktop bindings async
log_frontend always desktop bindings sync
lsp_apply_code_action trusted project_host bindings async
lsp_call_hierarchy trusted project_host bindings async
lsp_can_download_sources trusted project_host bindings async
lsp_code_action_query trusted project_host bindings async
lsp_code_actions trusted project_host bindings async
lsp_code_lens trusted project_host bindings async
lsp_completion trusted project_host bindings async
lsp_document_highlights trusted project_host bindings async
lsp_document_links trusted project_host bindings async
lsp_execute_code_action trusted project_host bindings async
lsp_execute_command trusted project_host bindings async
lsp_format trusted project_host bindings async
lsp_goto trusted project_host bindings async
lsp_goto_implementation trusted project_host bindings async
lsp_hierarchy_members trusted project_host bindings async
lsp_hierarchy_refactor trusted project_host bindings async
lsp_hover trusted project_host bindings async
lsp_implementations trusted project_host bindings async
lsp_inlay_hints trusted project_host bindings async
lsp_inline_completion trusted project_host bindings async
lsp_library_sources trusted project_host bindings async
lsp_prepare_rename trusted project_host bindings async
lsp_prepare_type_hierarchy trusted project_host bindings async
lsp_references trusted project_host bindings async
lsp_rename trusted project_host bindings async
lsp_resend_diagnostics always project_host bindings sync
lsp_resolve_class_file trusted project_host bindings async
lsp_resolve_code_action trusted project_host bindings async
lsp_resolve_command trusted project_host bindings async
lsp_resolve_completion trusted project_host bindings async
lsp_restart trusted project_host bindings async
lsp_restart_named trusted desktop bindings async
lsp_semantic_tokens trusted project_host bindings async
lsp_servers always project_host bindings sync
lsp_signature_help trusted project_host bindings async
lsp_type_hierarchy trusted project_host bindings async
lsp_virtual_document trusted project_host bindings async
lsp_workspace_symbols trusted project_host bindings async
mark_recent always project_host bindings sync
maven_dependency_completion trusted project_host bindings async
maven_dependency_declaration trusted project_host bindings async
maven_exclude_dependency trusted project_host bindings async
maven_goto_declaration trusted project_host bindings async
mcp_agent_run_closed trusted desktop bindings sync
mcp_regenerate_token trusted desktop bindings sync
mcp_report_problems trusted project_host bindings sync
mcp_respond trusted desktop bindings sync
mcp_server_status trusted desktop bindings sync
mcp_set_focused_editor trusted project_host bindings sync
mcp_set_open_editors trusted project_host bindings sync
mcp_ui_ready trusted desktop bindings sync
menu_configure always desktop bindings sync
menu_model always desktop bindings sync
menu_refresh always desktop bindings sync
menu_set_disabled always desktop bindings sync
nav_index_definitions always project_host bindings async
nav_inheritance always project_host bindings async
nav_resolve_module always project_host bindings async
notebook_cell_docs trusted project_host bindings sync
notebook_close always project_host bindings async
notebook_edit always project_host bindings async
notebook_execute trusted project_host bindings async
notebook_get always project_host bindings sync
notebook_interrupt always project_host bindings async
notebook_open always project_host bindings async
notebook_redo always project_host bindings async
notebook_reload always project_host bindings async
notebook_restart trusted project_host bindings async
notebook_save always project_host bindings async
notebook_undo always project_host bindings async
open_project always project_host bindings async
path_completions always project_host bindings async
plugin_activation_event trusted desktop bindings async
plugin_answer_command trusted project_host bindings sync
plugin_answer_commit trusted project_host bindings sync
plugin_answer_prompt trusted project_host bindings sync
plugin_answer_run_target trusted project_host bindings async
plugin_assets always desktop bindings async
plugin_cancel_task trusted project_host bindings sync
plugin_catalog always desktop bindings async
plugin_choose_program outside_restricted project_host bindings async
plugin_color_presentations trusted project_host bindings async
plugin_commit_checks trusted project_host bindings async
plugin_content_tab_action trusted project_host bindings sync
plugin_context_keys trusted project_host bindings sync
plugin_debug_attach_target trusted project_host bindings async
plugin_decoration_sets trusted project_host bindings sync
plugin_endpoints trusted project_host bindings async
plugin_event_kinds trusted project_host bindings async
plugin_finish_operation trusted project_host bindings sync
plugin_formatters trusted project_host bindings sync
plugin_grant outside_restricted desktop bindings async
plugin_install_dir outside_restricted desktop bindings async
plugin_installed_intellij_themes always desktop bindings async
plugin_language_visuals trusted project_host bindings async
plugin_line_markers trusted project_host bindings async
plugin_link trusted desktop bindings async
plugin_list always desktop bindings async
plugin_log_tab_spawn trusted desktop bindings async
plugin_market always desktop bindings async
plugin_market_download always desktop bindings async
plugin_market_url always desktop bindings sync
plugin_navigation_files trusted project_host bindings async
plugin_navigation_goto trusted project_host bindings async
plugin_navigation_index trusted project_host bindings async
plugin_navigation_invalidate trusted project_host bindings sync
plugin_navigation_markers trusted project_host bindings async
plugin_parse_test_results trusted project_host bindings async
plugin_post_events trusted project_host bindings sync
plugin_prepare_debug_run trusted project_host bindings async
plugin_preview_install always desktop bindings async
plugin_program outside_restricted project_host bindings async
plugin_read_intellij_theme always desktop bindings async
plugin_reload outside_restricted desktop bindings async
plugin_revoke_net_host outside_restricted desktop bindings async
plugin_roll_back outside_restricted desktop bindings async
plugin_run_command trusted project_host bindings async
plugin_run_targets trusted project_host bindings async
plugin_secrets trusted desktop bindings sync
plugin_select_tests trusted project_host bindings async
plugin_service_detail trusted project_host bindings async
plugin_service_log trusted project_host bindings async
plugin_set_active_file always project_host bindings sync
plugin_set_capability outside_restricted desktop bindings async
plugin_set_enabled outside_restricted desktop bindings async
plugin_set_market_url always desktop bindings sync
plugin_set_secret trusted desktop bindings sync
plugin_set_theme always desktop bindings sync
plugin_set_theme_frame always desktop bindings sync
plugin_set_ui_locale always project_host bindings async
plugin_stage_package always desktop bindings async
plugin_status_items trusted project_host bindings sync
plugin_subscribe always desktop bindings sync
plugin_sync_languages trusted project_host - -
plugin_sync_packages trusted project_host - -
plugin_terminal_session_close trusted project_host bindings sync
plugin_terminal_session_spawn trusted project_host bindings async
plugin_uninstall outside_restricted desktop bindings async
plugin_unlink trusted desktop bindings async
plugin_unpack_package always desktop bindings async
plugin_view_event trusted project_host bindings async
plugin_view_render trusted project_host bindings async
plugin_web_page trusted desktop bindings sync
plugin_web_pty_spawn trusted desktop bindings async
plugin_web_read_file trusted desktop bindings async
plugin_web_save_file trusted desktop bindings async
prepare_workspace_edit always project_host bindings async
profiler_collect trusted desktop bindings async
profiler_gc_before_stop trusted desktop bindings async
profiler_prepare trusted desktop bindings async
project_current always project_host bindings sync
project_rename always desktop bindings sync
project_roots always project_host bindings sync
project_trust_add_location always desktop bindings async
project_trust_list always project_host bindings sync
project_trust_remove_location always project_host bindings async
project_trust_set always project_host bindings async
project_trust_status always project_host bindings sync
proxy_check_connection always desktop bindings async
recent_files always project_host bindings sync
recent_project_groups always desktop bindings sync
recent_projects always desktop bindings async
redo_workspace_edit always project_host bindings async
refactor_can_undo_file_move always project_host bindings sync
refactor_file_move_edits always project_host bindings async
refactor_file_move_text_edits always project_host bindings async
refactor_move_files always project_host bindings async
refactor_undo_file_move always project_host bindings async
remote_bootstrap_list always desktop bindings async
remote_connect always desktop bindings async
remote_current always desktop bindings sync
remote_delete trusted project_host bindings async
remote_disconnect always desktop bindings sync
remote_download_into trusted project_host bindings async
remote_forward_port trusted desktop bindings async
remote_forwarded_ports trusted desktop bindings sync
remote_import_local trusted desktop bindings async
remote_invoke always desktop bindings async
remote_list always project_host bindings async
remote_mkdir trusted project_host bindings async
remote_of always project_host bindings sync
remote_open always project_host bindings async
remote_rename trusted project_host bindings async
remote_stop_forwarding trusted desktop bindings async
remote_trust_set always desktop bindings sync
remote_trust_status always desktop bindings sync
remove_recent always project_host bindings sync
remove_recent_project always desktop bindings sync
replace_in_files trusted project_host bindings async
replace_preview trusted project_host bindings async
run_application_build trusted project_host bindings async
run_application_publish trusted project_host bindings async
run_apply_settings trusted project_host bindings async
run_close_stdin trusted project_host bindings sync
run_configs trusted project_host bindings async
run_dotnet_resolve trusted project_host bindings async
run_env_files trusted project_host bindings async
run_gradle_init_script trusted project_host bindings async
run_gradle_jvm_args_script always project_host bindings async
run_import_configs trusted project_host bindings async
run_import_sources trusted project_host bindings async
run_list always project_host bindings sync
run_resize trusted project_host bindings sync
run_save_configs trusted project_host bindings async
run_save_templates trusted project_host bindings async
run_start trusted project_host bindings async
run_stdin trusted project_host bindings sync
run_stop always project_host bindings sync
run_system_env always project_host bindings sync
run_templates trusted project_host bindings async
run_test_reports trusted project_host bindings async
run_tomcat_artifacts trusted project_host bindings async
run_tomcat_build trusted project_host bindings async
run_tomcat_home trusted project_host bindings async
run_tomcat_installations trusted project_host bindings async
run_tomcat_sync trusted project_host bindings async
run_tomcat_update trusted project_host bindings async
run_without_derived trusted project_host bindings async
scaffold_catalog always project_host bindings sync
scaffold_create always project_host bindings async
scaffold_options always project_host bindings async
scaffold_requirements always project_host bindings async
sdk_container_python trusted project_host bindings sync
sdk_container_python_refresh trusted project_host bindings async
sdk_detect trusted project_host bindings async
sdk_locate_tools trusted project_host bindings async
sdk_php_composer_install trusted project_host bindings async
sdk_php_effective trusted project_host bindings sync
sdk_php_language_level trusted project_host bindings async
sdk_php_xdebug trusted project_host bindings async
sdk_project_libraries trusted project_host bindings async
sdk_python_create_venv trusted project_host bindings async
sdk_python_effective trusted project_host bindings sync
sdk_python_interpreter trusted project_host bindings async
sdk_python_packages trusted project_host bindings async
sdk_python_pip trusted project_host bindings async
sdk_python_project_interpreters trusted project_host bindings async
search_start always project_host bindings async
search_validate always project_host bindings sync
set_recent_project_groups always desktop bindings sync
settings_export always desktop bindings async
settings_get always project_host bindings sync
settings_get_global always desktop bindings sync
settings_import always desktop bindings async
settings_list_jetbrains_ides always desktop bindings async
settings_read_jetbrains always desktop bindings async
settings_set always project_host bindings sync
spell_check always project_host bindings async
spell_suggest always project_host bindings async
spring_route_sources trusted desktop bindings sync
ssh_askpass_answer always desktop bindings sync
ssh_connected always project_host bindings sync
ssh_disconnect always project_host bindings sync
ssh_needs_secret always project_host bindings sync
ssh_open_terminal always desktop bindings async
ssh_password_saved always project_host bindings sync
ssh_set_secret always project_host bindings sync
ssh_test always project_host bindings async
ssh_trust_host always project_host bindings async
structural_languages always project_host bindings async
structural_search always project_host bindings async
structural_validate always project_host bindings async
syntax_errors always project_host bindings async
syntax_expression_at always project_host bindings async
syntax_identifiers always project_host bindings async
syntax_identifiers_in_files always project_host bindings async
syntax_locals always project_host bindings async
syntax_node_at always project_host bindings async
syntax_structural_ranges always project_host bindings async
syntax_support always project_host bindings sync
system_font_families always desktop bindings async
system_probe_hotkeys trusted desktop bindings sync
term_available_shells always project_host bindings sync
term_default_shell always project_host bindings sync
term_is_busy always project_host bindings async
term_kill always project_host bindings sync
term_resize always project_host bindings sync
term_spawn always project_host bindings async
term_store_image always project_host bindings async
term_write always project_host bindings sync
tools_install trusted project_host bindings async
tools_list trusted project_host bindings async
tools_uninstall trusted project_host bindings async
tools_updates trusted project_host bindings async
undo_workspace_edit always project_host bindings async
user_font_data always desktop - async
vcs_add_to_ignore trusted project_host bindings async
vcs_add_worktree trusted project_host bindings async
vcs_apply_patch trusted project_host bindings async
vcs_blame always project_host bindings async
vcs_block_history always project_host bindings async
vcs_branch_info always project_host bindings async
vcs_branches always project_host bindings async
vcs_changelists_load always project_host bindings async
vcs_changelists_save trusted project_host bindings sync
vcs_checkout trusted project_host bindings async
vcs_clone always project_host bindings async
vcs_commit trusted project_host bindings async
vcs_commit_files always project_host bindings async
vcs_commits_changes always project_host bindings async
vcs_compare_paths always project_host bindings async
vcs_compare_scope always project_host bindings async
vcs_config_get always project_host bindings async
vcs_conflict_versions always project_host bindings async
vcs_create_branch trusted project_host bindings async
vcs_create_patch trusted project_host bindings async
vcs_create_tag trusted project_host bindings async
vcs_delete_branch trusted project_host bindings async
vcs_delete_tag trusted project_host bindings async
vcs_detected_git always project_host bindings sync
vcs_diff_hunks always project_host bindings async
vcs_diff_numstat always project_host bindings async
vcs_diff_revisions always project_host bindings async
vcs_diff_text always project_host bindings async
vcs_diff_with_worktree always project_host bindings async
vcs_discard trusted project_host bindings async
vcs_edit_remote trusted project_host bindings async
vcs_file_at always project_host bindings async
vcs_file_mode trusted project_host bindings async
vcs_git_version trusted project_host bindings async
vcs_has_hook always project_host bindings async
vcs_ignore_blame_revision trusted project_host bindings async
vcs_init always project_host bindings async
vcs_line_hunks always project_host bindings async
vcs_log always project_host bindings async
vcs_log_details always project_host bindings async
vcs_log_details_batch always project_host bindings async
vcs_log_refs always project_host bindings async
vcs_log_users always project_host bindings async
vcs_merge trusted project_host bindings async
vcs_merge_base always project_host bindings async
vcs_merge_with trusted project_host bindings async
vcs_move_worktree trusted project_host bindings async
vcs_open_external_log always project_host bindings async
vcs_operation trusted project_host bindings async
vcs_patch_preview trusted project_host bindings async
vcs_rebase trusted project_host bindings async
vcs_rebase_with trusted project_host bindings async
vcs_remote trusted project_host bindings async
vcs_remotes always project_host bindings async
vcs_remove_worktree trusted project_host bindings async
vcs_rename_branch trusted project_host bindings async
vcs_restore_branch trusted project_host bindings async
vcs_restore_head trusted project_host bindings async
vcs_restore_tag trusted project_host bindings async
vcs_revision_children always project_host bindings async
vcs_revision_files always project_host bindings async
vcs_reword trusted project_host bindings async
vcs_roots always project_host bindings sync
vcs_shelf_delete trusted project_host bindings async
vcs_shelf_diff trusted project_host bindings async
vcs_shelf_import trusted project_host bindings async
vcs_shelf_patch always project_host bindings async
vcs_shelf_rename trusted project_host bindings async
vcs_shelve trusted project_host bindings async
vcs_shelves always project_host bindings async
vcs_stage trusted project_host bindings async
vcs_stage_hunks trusted project_host bindings async
vcs_stage_patch trusted project_host bindings async
vcs_stash_apply trusted project_host bindings async
vcs_stash_drop trusted project_host bindings async
vcs_stash_push trusted project_host bindings async
vcs_stashes always project_host bindings async
vcs_status always project_host bindings async
vcs_status_paths always project_host bindings async
vcs_tags always project_host bindings async
vcs_undo_commit trusted project_host bindings async
vcs_unshelve trusted project_host bindings async
vcs_unstage trusted project_host bindings async
vcs_worktrees always project_host bindings async
vcs_write_patch always project_host bindings async
web_browsers always desktop bindings async
web_goto always project_host bindings async
web_open always desktop bindings async
web_serves_page trusted desktop bindings async
web_unresolved_references always project_host bindings async
web_url always project_host bindings async
window_close_context always desktop bindings sync
window_complete_launch always desktop bindings sync
window_cycle always desktop bindings sync
window_flash_taskbar always desktop bindings sync
window_group_cancel_close always desktop bindings sync
window_group_close always desktop bindings sync
window_group_close_tabs always desktop bindings sync
window_group_current always desktop bindings sync
window_group_detach always desktop bindings async
window_group_merge always desktop bindings async
window_group_reorder always desktop bindings async
window_group_restore always desktop bindings async
window_group_select always desktop bindings async
window_is_fullscreen always desktop bindings sync
window_new always desktop bindings async
window_open_comparison always desktop bindings async
window_open_deployment always desktop bindings async
window_open_diff always desktop bindings async
window_open_file_in_new_window always desktop bindings async
window_open_files always desktop bindings async
window_open_project always desktop bindings async
window_open_projects always desktop bindings sync
window_open_remote always desktop bindings async
window_open_settings always desktop bindings async
window_set_titlebar_height always desktop bindings sync
window_start_drag always desktop bindings sync
window_take_launch always desktop bindings sync
window_toggle_fullscreen always desktop bindings sync
window_toggle_zoom always desktop bindings sync
workspace_attach always desktop bindings async
workspace_create always desktop bindings async
workspace_discover_projects always desktop bindings async
workspace_update always desktop bindings async
wsl_distros always desktop bindings async
wsl_resolve always desktop bindings sync
+2 -93
Переглянути файл
@@ -1,98 +1,7 @@
//! `cargo test -p openidea --test export_bindings` regenerates `src/bindings.ts` and
//! `src-tauri/tests/commands.snap` without launching the app (used by `pnpm gen:bindings`
//! and CI drift checks).
use ide_host::trust::{projectless_command_allowed, restricted_command_allowed};
use std::collections::{BTreeMap, BTreeSet};
use std::path::Path;
use tauri_specta::{BuilderConfiguration, LanguageExt};
//! `cargo test -p openidea --test export_bindings` regenerates `src/bindings.ts`
//! without launching the app (used by `pnpm gen:bindings` and CI drift checks).
#[test]
fn export_bindings() {
openidea_lib::export_bindings(&openidea_lib::specta_builder());
}
/// Commands registered outside tauri-specta (`src-tauri/src/lib.rs`), with how Tauri runs them.
const RAW_COMMANDS: &[(&str, &str)] = &[("user_font_data", "async")];
/// Every command, one line each: its trust class, where a remote window runs it, whether it is
/// in `bindings.ts`, and how Tauri runs it. A change to any of these shows up in this file's diff.
#[test]
fn export_command_snapshot() {
let target = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/commands.snap");
let fresh = std::env::temp_dir().join(format!("openidea-commands-{}.snap", std::process::id()));
openidea_lib::specta_builder().export(CommandSnapshot, &fresh).expect("command snapshot");
let text = std::fs::read(&fresh).expect("exported command snapshot");
let _ = std::fs::remove_file(&fresh);
if std::fs::read(&target).ok().as_deref() != Some(text.as_slice()) {
std::fs::write(&target, text).expect("failed to write the command snapshot");
}
}
struct CommandSnapshot;
impl LanguageExt for CommandSnapshot {
type Error = std::io::Error;
fn export(self, cfg: &BuilderConfiguration, path: &Path) -> std::io::Result<()> {
let spawned = spawned_commands();
let mut modes: BTreeMap<&str, &str> = cfg
.commands
.iter()
.map(|f| {
let mode = if spawned.contains(f.name()) {
"spawn"
} else if f.asyncness() {
"async"
} else {
"sync"
};
(f.name(), mode)
})
.collect();
let in_bindings: BTreeSet<&str> = modes.keys().copied().collect();
modes.extend(RAW_COMMANDS.iter().copied());
let routed: BTreeSet<&str> = ide_host::rpc::client_commands().into_iter().collect();
let names: BTreeSet<&str> = modes.keys().chain(&routed).copied().collect();
let mut out = String::from(
"# Generated by `pnpm gen:bindings`; do not edit. One line per command:\n\
# name, trust class, placement in a remote window, in bindings.ts, how Tauri runs it.\n",
);
for name in names {
let trust = if restricted_command_allowed(name) {
"always"
} else if projectless_command_allowed(name) {
"outside_restricted"
} else {
"trusted"
};
let placement = if routed.contains(name) { "project_host" } else { "desktop" };
let bindings = if in_bindings.contains(name) { "bindings" } else { "-" };
let mode = modes.get(name).copied().unwrap_or("-");
out.push_str(&format!("{name:<44} {trust:<18} {placement:<12} {bindings:<8} {mode}\n"));
}
std::fs::write(path, out)
}
}
/// Sync commands declared `#[tauri::command(async)]`, which Tauri runs off the main thread.
fn spawned_commands() -> BTreeSet<String> {
let mut out = BTreeSet::new();
let mut dirs = vec![Path::new(env!("CARGO_MANIFEST_DIR")).join("src")];
while let Some(dir) = dirs.pop() {
for entry in std::fs::read_dir(&dir).unwrap() {
let path = entry.unwrap().path();
if path.is_dir() {
dirs.push(path);
continue;
}
let source = std::fs::read_to_string(&path).unwrap_or_default();
for (_, rest) in source.match_indices("#[tauri::command(async)]").map(|(i, _)| source.split_at(i)) {
let name = rest.split("fn ").nth(1).and_then(|s| s.split('(').next());
out.insert(name.expect("a function after #[tauri::command(async)]").trim().to_owned());
}
}
}
out
}
+1 -25
Переглянути файл
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { DocModel } from "./model/document";
import { offerMakeWritable, readOnlyQuestion, toggleReadOnly } from "./fileAttributes";
import { readOnlyQuestion, toggleReadOnly } from "./fileAttributes";
function model(readOnly: boolean, extra: Partial<{ virtual: boolean; banner: string | null }> = {}) {
const meta = { readOnly, banner: extra.banner ?? (readOnly ? "readOnly" : null) };
@@ -43,27 +43,3 @@ describe("Toggle Read-only Attribute", () => {
expect(readOnlyQuestion("a.txt", false).confirm).toBe("Make Read-only");
});
});
describe("editing a read-only file", () => {
it("offers to make it writable once, then lets edits through", async () => {
const m = model(true);
answer = true;
expect(offerMakeWritable(m)).toBe(true);
expect(offerMakeWritable(m)).toBe(true);
expect(confirm).toHaveBeenCalledTimes(1);
expect(confirm).toHaveBeenCalledWith(expect.objectContaining({ title: "Make File Writable" }));
await vi.waitFor(() => expect(m.setReadOnly).toHaveBeenCalledWith(false));
expect(offerMakeWritable(m)).toBe(false);
});
it("refuses edits without asking for library, binary and too-large documents", () => {
for (const m of [
model(true, { virtual: true }),
model(true, { banner: "binary" }),
model(true, { banner: "tooLarge" }),
])
expect(offerMakeWritable(m)).toBe(true);
expect(confirm).not.toHaveBeenCalled();
expect(offerMakeWritable(model(false))).toBe(false);
});
});
+1 -21
Переглянути файл
@@ -1,8 +1,7 @@
/**
* File › File Properties › Make File Read-only / Writable (IDEA's "Toggle
* Read-only Attribute", also the status bar lock): asks, then flips the
* file's writable bit and the open document's editability. Typing into a file
* whose read-only attribute is set asks the same (IDEA's Clear Read-Only Status).
* file's writable bit and the open document's editability.
*/
import { call, commands, isTauri } from "@/platform/ipc";
import { basename } from "@/platform/project";
@@ -42,22 +41,3 @@ export function toggleReadOnly(model: DocModel) {
(ok) => ok && void setFileWritable(model, meta.readOnly),
);
}
let asking: DocModel | null = null;
/**
* An edit was attempted in `model`. When only the file's read-only attribute is in the
* way (not a binary, too large or library file), offers to make it writable, once at a
* time. Returns whether the edit was refused: the caller drops it either way.
*/
export function offerMakeWritable(model: DocModel): boolean {
const meta = model.getMeta();
if (!meta.readOnly) return false;
if (model.virtual || meta.banner !== "readOnly" || asking) return true;
asking = model;
const q = readOnlyQuestion(basename(model.path), true);
void confirm({ title: q.title, message: q.message, ok: q.confirm })
.then((ok) => ok && model.getMeta().readOnly && setFileWritable(model, true))
.finally(() => (asking = null));
return true;
}
-11
Переглянути файл
@@ -34,7 +34,6 @@ import {
import { showContextMenu } from "@/ui";
import { baseExtensions, compartments, contributionExtensions } from "../cm/setup";
import { gutterMenuItems, inGutterMenuArea } from "../gutterMenu";
import { offerMakeWritable } from "../fileAttributes";
import type { DocModel } from "./document";
import type { WorkspaceHistoryTarget } from "./workspaceHistory";
import { isNavigation } from "./navHistory";
@@ -148,12 +147,6 @@ export class EditorSlot {
return this.state;
}
private refuseReadOnlyEdit(e: Event): boolean {
if (!offerMakeWritable(this.model)) return false;
e.preventDefault();
return true;
}
private slotExtensions() {
return [
this.model.manager.workspaceHistory.extension(this.historyTarget),
@@ -176,10 +169,6 @@ export class EditorSlot {
this.host.onContextMenu(this, e);
return true;
},
// Typing, pasting or dropping into a read-only file offers to make it writable.
beforeinput: (e) => this.refuseReadOnlyEdit(e),
paste: (e) => this.refuseReadOnlyEdit(e),
drop: (e) => this.refuseReadOnlyEdit(e),
}),
ViewPlugin.define((view) => {
// Gutters sit outside the content DOM. Gutter extensions with their own menu (breakpoints,
-25
Переглянути файл
@@ -372,31 +372,6 @@ describe("run config → launch config", () => {
},
);
it("Zig under CodeLLDB: no source-language mode, so evaluation stays LLDB's own", () => {
const exe = launchConfigFor(
rc({ kind: "zig-application", command: "./zig-out/bin/app", debugAdapter: "codelldb" }),
"/p",
)!;
expect(exe.adapter).toBe("codelldb");
expect(extra(exe)).toEqual({ sourceLanguages: [] });
const single = launchConfigFor(
rc({
kind: "native",
command: "/tmp/openidea-run/calc-1",
debugAdapter: "codelldb",
params: { language: "zig" },
}),
"/p",
)!;
expect(extra(single)).toEqual({ sourceLanguages: [] });
// Rust-compiled binaries keep CodeLLDB's default (Rust) source mode.
const rust = launchConfigFor(
rc({ kind: "native", command: "/tmp/openidea-run/app-1", debugAdapter: "codelldb" }),
"/p",
)!;
expect(rust.extraJson).toBeNull();
});
it("Godot: the editor's adapter plays the main scene or the chosen one of the project", () => {
const project = rc({
kind: "godot",
-4
Переглянути файл
@@ -359,10 +359,6 @@ function nativeLaunch(rc: RunConfig, cwd: string, adapter: string): LaunchConfig
env: Object.entries(rc.env).map(([k, v]) => `${k}=${v}`),
...(from && to && from !== to ? { sourceMap: [[from, to]] } : {}),
});
} else if (rc.kind === "zig-application" || rc.params?.language === "zig") {
// Zig under CodeLLDB: without a source language, evaluation stays LLDB's own
// (the default Rust mode would shape `Evaluate Expression` as Rust).
out.extraJson = JSON.stringify({ sourceLanguages: [] });
}
return out;
}
+1 -1
Переглянути файл
@@ -33,7 +33,7 @@
font-size: var(--fs-small, var(--fs-ui));
}
.button:hover,
.button.text:hover,
.button[aria-expanded="true"] {
background-color: var(--bg-toolbar-hover);
}
+3 -105
Переглянути файл
@@ -1,36 +1,15 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { RunConfig } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { menuGroupItems, registerMenuGroup } from "@/workbench/contributions";
import type { MenuItem } from "@/ui";
import { canDebugProduced, choiceItems, compiledDebugPlan, contextMenuItems } from "./contextRun";
import { OPTIMISTIC, produceContextChoices, type ToolEnv } from "./producers";
import { canDebugProduced, choiceItems, contextMenuItems } from "./contextRun";
import { OPTIMISTIC, produceContextChoices } from "./producers";
import { gutterTestState, markerIcon, targetMenuItems } from "./runGutter";
import { useRun } from "./store";
import type { RunTarget } from "./targets";
import { TestResults } from "./testing";
import { clearTestStates, recordTestStates } from "./testing/states";
import { setInvokeRoute } from "@/platform/tauriCore";
const mocks = vi.hoisted(() => ({
tauri: { value: false },
read: { value: null as string | null },
toolEnv: { value: null as ((...args: unknown[]) => unknown) | null },
}));
vi.mock("@/platform/ipc", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/platform/ipc")>();
return { ...actual, isTauri: () => mocks.tauri.value };
});
vi.mock("./runtimes", async (importOriginal) => {
const actual = await importOriginal<typeof import("./runtimes")>();
return {
...actual,
toolEnv: (...args: Parameters<typeof actual.toolEnv>) =>
mocks.toolEnv.value ? mocks.toolEnv.value(...args) : actual.toolEnv(...args),
};
});
const ROOT = "/work/app";
const SCRATCHES = "/Users/me/scratches";
@@ -224,23 +203,6 @@ describe("run gutter popup", () => {
describe("Debug entry", () => {
const config = (c: Partial<RunConfig>) =>
({ id: "c", name: "c", command: "", args: [], cwd: "", env: {}, ...c }) as RunConfig;
const MAIN_ZIG = [
'const std = @import("std");',
"pub fn main() !void {",
' std.debug.print("hi\\n", .{});',
"}",
].join("\n");
const CALC_ZIG = [
'const std = @import("std");',
'test "adds two numbers" {',
" try std.testing.expect(true);",
"}",
].join("\n");
const zigEnv: ToolEnv = {
tool: (n) => (n === "zig" ? { path: "/bin/zig", version: "0.17.1" } : null),
compileDir: "/tmp/openidea-run",
};
it("is offered for Maven and Gradle tests, which run with a JDWP agent", () => {
const mavenTest = config({ kind: "maven", command: "mvn", args: ["test", "-Dtest=A#b"], isTest: true });
expect(canDebugProduced({ name: "A.b", scope: "element", config: mavenTest })).toBe(true);
@@ -255,70 +217,6 @@ describe("Debug entry", () => {
canDebugProduced({ name: "lint", scope: "file", config: config({ kind: "npm", args: ["run", "lint"] }) }),
).toBe(false);
});
beforeEach(() => {
useProject.setState({ project: { name: "app", root: ROOT, trusted: true, isGit: false, settings: {} } as never });
useRun.setState({ configs: [], loaded: true });
mocks.tauri.value = true;
mocks.toolEnv.value = () => zigEnv;
// Bindings' `typedError` wraps the raw invoke result: `fs_read_text` resolves to its text.
setInvokeRoute((cmd) =>
cmd === "fs_read_text" ? Promise.resolve(mocks.read.value) : Promise.reject(new Error("not stubbed")),
);
});
afterEach(() => {
mocks.tauri.value = false;
mocks.read.value = null;
mocks.toolEnv.value = null;
setInvokeRoute(null);
useProject.setState({ project: null });
useRun.setState({ configs: [], loaded: false });
});
it("re-debug of a saved zig file config rebuilds the build-then-debug plan", async () => {
mocks.read.value = MAIN_ZIG;
const saved = config({
id: "context:file:src/main.zig",
kind: "zig",
command: "zig",
args: ["run", "src/main.zig"],
cwd: null,
});
const plan = await compiledDebugPlan(saved);
expect(plan?.debug).toBeTruthy();
expect(plan!.debug!.build.command).toMatch(
/zig build-exe src\/main\.zig -femit-bin=\/tmp\/openidea-run\/main-\w+$/,
);
expect(plan!.debug!.config).toMatchObject({
kind: "native",
debugAdapter: "codelldb",
params: { language: "zig" },
});
});
it("re-debug of a saved zig test config re-targets its test", async () => {
mocks.read.value = CALC_ZIG;
const saved = config({
id: "context:file:src/calc.zig#adds two numbers",
kind: "zig",
command: "zig",
args: ["test", "src/calc.zig", "--test-filter", "adds two numbers"],
cwd: null,
});
const plan = await compiledDebugPlan(saved);
expect(plan?.debug).toBeTruthy();
expect(plan!.debug!.build.command).toMatch(
/zig test src\/calc\.zig --test-filter 'adds two numbers' --test-no-exec/,
);
expect(plan!.debug!.config.args).toEqual([]);
});
it("leaves other configurations alone", async () => {
expect(await compiledDebugPlan(config({ id: "c", kind: "shell", command: "make" }))).toBeNull();
expect(
await compiledDebugPlan(config({ id: "user:x", kind: "zig", command: "zig", args: ["run", "x.zig"], cwd: null })),
).toBeNull();
});
});
describe("Run with Fuzzing", () => {
+3 -3
Переглянути файл
@@ -197,9 +197,9 @@ export async function compiledDebugPlan(config: RunConfig): Promise<Produced | n
const input: ContextInput = { ...projectContext(), root, path, content };
const env = await toolEnv(neededTools(input), path, root, false);
if (m[2]) {
// A test: find the target by name again (targets and the id carry the unescaped name).
// A test: find the target by name again.
if (config.kind === "zig") {
const test = zigTargets(content ?? "").find((t) => t.name === m[2]);
const test = zigTargets(content ?? "").find((t) => t.name.replace(/\\(.)/g, "$1") === m[2]);
return test ? produceContext({ ...input, line: test.line }, env) : null;
}
const lines = (content ?? "").split("\n");
@@ -365,7 +365,7 @@ function peekContent(path: string): string | undefined {
/** Whether the file's runnability depends on its text (`package main`, `fn main`, `#!`…). */
function needsContent(path: string): boolean {
const name = path.slice(path.lastIndexOf("/") + 1);
return /\.(go|rs|java|kt|c|cpp|cc|cxx|zig)$/.test(name) || !name.includes(".");
return /\.(go|rs|java|kt|c|cpp|cc|cxx)$/.test(name) || !name.includes(".");
}
export async function prepareMenu(_menu: ContextMenuId, ctx: MenuGroupContext): Promise<void> {
+1 -1
Переглянути файл
@@ -185,7 +185,7 @@ async function debugConfig(config: RunConfig, chain: readonly string[] = [], sho
await executeAction("debug.startConfig", show === false ? { config, show: false } : config);
return;
}
// A single compiled file (rustc / clang / zig): build with debug info, then debug the binary.
// A single compiled file (rustc / clang): build with debug info, then debug the binary.
const compiled = await compiledDebugPlan(config);
if (compiled?.debug) {
await launchProduced(compiled, true, show);
+1 -6
Переглянути файл
@@ -424,12 +424,7 @@ describe("single-file producers (scratches)", () => {
expect(main.debug!.build.command).toMatch(
/^mkdir -p \/tmp\/openidea-run && \/bin\/zig build-exe calc\.zig -femit-bin=\/tmp\/openidea-run\/calc-\w+$/,
);
expect(main.debug!.config).toMatchObject({
kind: "native",
debugAdapter: "codelldb",
args: [],
params: { language: "zig" },
});
expect(main.debug!.config).toMatchObject({ kind: "native", debugAdapter: "codelldb", args: [] });
const test = produceContext(scratch("calc.zig", src, 3), e)!;
expect(test).toMatchObject({ name: "adds two numbers", scope: "element" });
+1 -9
Переглянути файл
@@ -660,15 +660,7 @@ function zigFile(input: ContextInput, env: ToolEnv, s: FileSite, test?: { name:
isTest: false,
debugAdapter: null,
};
const binary: RunConfig = {
...config,
kind: "native",
command: out,
args: [],
isTest: false,
// Marks the debugged program as Zig: CodeLLDB's source mode stays off (see nativeLaunch).
params: { language: "zig" },
};
const binary: RunConfig = { ...config, kind: "native", command: out, args: [], isTest: false };
return { name, scope, config, debug: { build: buildConfig, config: binary } };
}
-24
Переглянути файл
@@ -167,30 +167,6 @@ describe("rerunFailedConfig", () => {
expect(new Set(configs.map((config) => config.id)).size).toBe(2);
});
it("zig: --test-filter per failed test, straight for `zig test` and via the module root for `zig build`", async () => {
expect(
(await rerunFailedConfig(cfg("zig", "zig", ["test", "src/calc.zig"]), [
["calc", "adds"],
["calc", "subs"],
]))!.args,
).toEqual(["test", "src/calc.zig", "--test-filter", "adds", "--test-filter", "subs"]);
// Existing filters are replaced, not stacked.
expect(
(await rerunFailedConfig(cfg("zig", "zig", ["test", "src/calc.zig", "--test-filter", "adds"]), [
["calc", "subs"],
]))!.args,
).toEqual(["test", "src/calc.zig", "--test-filter", "subs"]);
// `zig build` forwards no args to the test binary: rerun goes through the module root
// the detection recorded.
expect(
(await rerunFailedConfig({ ...cfg("zig", "zig", ["build", "test"]), params: { testRoot: "src/tally.zig" } }, [
["tally", "subs"],
]))!.args,
).toEqual(["test", "src/tally.zig", "--test-filter", "subs"]);
// Without a recorded root a build-based run can't narrow.
expect(await rerunFailedConfig(cfg("zig", "zig", ["build", "test"]), [["tally", "subs"]])).toBeNull();
});
it("gradle and maven filters", async () => {
expect((await rerunFailedConfig(cfg("gradle", "./gradlew", ["test"]), [["com.a.FooTest", "bar()"]]))!.args).toEqual(
["test", "--tests", "com.a.FooTest.bar"],
+11 -10
Переглянути файл
@@ -250,17 +250,18 @@ function builtinTestsConfig(config: RunConfig, paths: string[][], name: string):
args = goArgs(config.args, paths, config.params?.scope === "file" ? config.params.target : undefined);
break;
case "zig": {
// `zig test <file>` filters directly. A build-based run (`zig build test`) forwards no
// args to the test binary, so it re-runs through the module root the detection recorded
// — exact for projects whose tests live in one module's import graph.
const file = config.args[0] === "test" ? config.args[1] : config.params?.testRoot;
// Only a standalone `zig test <file>` can filter: `zig build` forwards no args to the test binary.
const file = config.args[0] === "test" ? config.args[1] : undefined;
const names = unique(paths.map((p) => p[p.length - 1]!).filter(Boolean));
if (!file || !names.length) {
args = null;
break;
}
const rest = dropFlag(config.args[0] === "test" ? config.args.slice(2) : [], ["--test-filter"]);
args = ["test", file, ...rest, ...names.flatMap((n) => ["--test-filter", n])];
args =
file && names.length
? [
config.args[0]!,
file,
...dropFlag(config.args.slice(2), ["--test-filter"]),
...names.flatMap((n) => ["--test-filter", n]),
]
: null;
break;
}
case "jvm":
+2 -14
Переглянути файл
@@ -130,11 +130,7 @@
margin: 1.5em 0;
}
.preview :global(img) {
max-width: calc(100% * var(--markdown-zoom-scale, 1));
}
.preview :global(img[data-natural-width]) {
width: calc(min(var(--image-width), 100%) * var(--markdown-zoom-scale, 1));
height: auto;
max-width: 100%;
}
.preview :global(ul.contains-task-list) {
list-style: none;
@@ -159,18 +155,10 @@
display: none;
}
.preview :global(.mermaid-output) {
overflow-x: auto;
overflow-y: hidden;
overflow: hidden;
text-align: center;
}
.preview :global(.mermaid-output svg[data-natural-width]) {
display: block;
margin: 0 auto;
width: calc(min(var(--diagram-width), 100%) * var(--markdown-zoom-scale, 1));
height: auto;
}
.preview :global(.mermaid-output[data-zoomed="true"]) {
overflow: hidden;
cursor: grab;
touch-action: none;
user-select: none;
+4 -30
Переглянути файл
@@ -51,7 +51,6 @@ import {
resolveLink,
slugify,
} from "./render";
import { applyImageZoomWidth, svgDataUrlSize } from "./svgSize";
import styles from "./Markdown.module.css";
import { tx } from "@/platform/i18n";
@@ -111,7 +110,6 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
const text = useLiveMarkdown((s) => s[path]?.text);
const fontZoom = useLiveMarkdown((s) => s[path]?.fontZoom ?? 0);
const fontSize = useMarkdownPreviewFontSize();
const zoomScale = Number((Math.max(4, fontSize + fontZoom) / fontSize).toFixed(4));
const topLine = useLiveMarkdown((s) => s[path]?.topLine ?? 0);
const scrollSeq = useLiveMarkdown((s) => s[path]?.scrollSeq ?? 0);
const caretLine = useLiveMarkdown((s) => s[path]?.caretLine ?? 0);
@@ -163,32 +161,10 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
const root = ref.current;
if (!root) return;
let live = true;
const bindImageUrl = (img: HTMLImageElement, url: string, asyncLoad: boolean) => {
const svgSize = svgDataUrlSize(url);
if (svgSize && applyImageZoomWidth(img, svgSize) && asyncLoad) {
setDiagramsDrawn((n) => n + 1);
}
img.onload = () => {
if (!live) return;
if (!img.hasAttribute("data-natural-width") && img.naturalWidth > 0 && img.naturalHeight > 0) {
if (applyImageZoomWidth(img, { w: img.naturalWidth, h: img.naturalHeight })) {
setDiagramsDrawn((n) => n + 1);
}
} else if (asyncLoad) {
setDiagramsDrawn((n) => n + 1);
}
};
img.src = url;
if (!img.hasAttribute("data-natural-width") && img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
applyImageZoomWidth(img, { w: img.naturalWidth, h: img.naturalHeight });
}
};
const imgs = [...root.querySelectorAll<HTMLImageElement>("img[data-src]")];
imgs.forEach((img) => {
applyImageZoomWidth(img);
root.querySelectorAll<HTMLImageElement>("img[data-src]").forEach((img) => {
const src = img.dataset.src ?? "";
if (/^data:image\//i.test(src)) {
bindImageUrl(img, src, false);
img.src = src;
return;
}
const target = resolveLink(path, src);
@@ -198,7 +174,7 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
return;
}
imageUrl(target.path).then(
(url) => live && bindImageUrl(img, url, true),
(url) => live && (img.src = url),
() => live && img.classList.add(styles.blocked!),
);
});
@@ -211,7 +187,6 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
});
return () => {
live = false;
for (const img of imgs) img.onload = null;
};
}, [html, path]);
@@ -220,7 +195,7 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
const root = ref.current;
if (!root || !sync) return;
root.scrollTop = topLine <= 0 ? 0 : previewOffsetForLine(blocksOf(root), topLine, root.scrollHeight);
}, [html, topLine, scrollSeq, sync, diagramsDrawn, fontZoom, fontSize]);
}, [html, topLine, scrollSeq, sync, diagramsDrawn]);
// The preview's own scroll offset: tab switches and mode toggles unmount the
// preview, so Preview Only would otherwise start over at the top. Writes made
@@ -401,7 +376,6 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
{
"--markdown-preview-font-size": `${fontSize}px`,
"--markdown-font-zoom": `${fontZoom}px`,
"--markdown-zoom-scale": String(zoomScale),
} as CSSProperties
}
tabIndex={-1}
-9
Переглянути файл
@@ -396,15 +396,6 @@ describe("mermaid in the markdown preview", () => {
expect(root.querySelector("[data-mermaid]")?.getAttribute("data-mermaid-state")).toBe("pending");
});
it("records a diagram's natural width so preview font zoom scales it without clamping", async () => {
const svg = await renderedSvg(
'<svg id="openidea-mermaid-1" width="100%" style="max-width: 540px;" viewBox="0 0 540 320"><text>flow</text></svg>',
);
expect(svg.hasAttribute("data-natural-width")).toBe(true);
expect(svg.style.getPropertyValue("--diagram-width")).toBe("540px");
expect(svg.style.maxWidth).toBe("calc(min(var(--diagram-width), 100%) * var(--markdown-zoom-scale, 1))");
});
it("puts full-screen and download tools on a drawn diagram", async () => {
const root = preview(SEQ);
await renderMermaidIn(root).done;
+1 -10
Переглянути файл
@@ -11,7 +11,6 @@ import { attachPanZoom } from "../panZoom";
import { attachDiagramTools, TOOLS_ATTR } from "./mermaidTools";
import { localSvg } from "./localSvg";
import { reid } from "./svgIds";
import { svgElementSize } from "./svgSize";
export const MERMAID_SELECTOR = "[data-mermaid]";
const OUTPUT_CLASS = "mermaid-output";
@@ -251,15 +250,7 @@ function show(block: HTMLElement, result: Result | null, stale?: Node) {
if (block.getAttribute(RENDERED_ATTR) === "ok") {
attachPanZoom(out);
const svg = out.querySelector("svg");
if (svg) {
const size = svgElementSize(svg);
if (size) {
svg.dataset.naturalWidth = "";
svg.style.setProperty("--diagram-width", `${Number(size.w.toFixed(2))}px`);
svg.style.maxWidth = "calc(min(var(--diagram-width), 100%) * var(--markdown-zoom-scale, 1))";
}
attachDiagramTools(block, svg);
}
if (svg) attachDiagramTools(block, svg);
}
}
+5 -3
Переглянути файл
@@ -11,7 +11,6 @@ import { openLayer, trapTab } from "@/ui/popupState";
import { notifications } from "@/workbench/contributions";
import { attachPanZoom } from "../panZoom";
import { reid } from "./svgIds";
import { svgElementSize } from "./svgSize";
import styles from "./MermaidTools.module.css";
/** Marks the tool strip, so a redrawing block replaces it rather than stacking one. */
@@ -162,8 +161,11 @@ function fittedCopy(svg: SVGSVGElement, availW: number, availH: number): SVGSVGE
}
function naturalSize(svg: SVGSVGElement): { w: number; h: number } {
const declared = svgElementSize(svg);
if (declared) return declared;
const box = (svg as SVGSVGElement & { viewBox?: SVGAnimatedRect }).viewBox?.baseVal;
if (box && box.width > 0 && box.height > 0) return { w: box.width, h: box.height };
const width = Number(svg.getAttribute("width"));
const height = Number(svg.getAttribute("height"));
if (width > 0 && height > 0) return { w: width, h: height };
const rect = svg.getBoundingClientRect();
return { w: rect.width > 0 ? rect.width : 800, h: rect.height > 0 ? rect.height : 600 };
}
-147
Переглянути файл
@@ -1,147 +0,0 @@
/**
* Intrinsic CSS pixel dimensions of SVGs and Markdown preview images, so
* diagrams and embedded `.svg` / raster assets scale with `--markdown-zoom-scale`.
*/
const UNIT_PX: Record<string, number> = {
"": 1,
px: 1,
pt: 96 / 72,
pc: 16,
in: 96,
cm: 96 / 2.54,
mm: 96 / 25.4,
};
/** Parses an absolute SVG/HTML length into CSS pixels (ignoring `%`, `em`, etc.). */
export function parseLengthPx(raw: string | null | undefined): number | null {
if (!raw) return null;
const m = /^\s*(\d+(?:\.\d+)?|\.\d+)\s*([a-z%]*)\s*$/i.exec(raw);
if (!m) return null;
const factor = UNIT_PX[m[2]!.toLowerCase()];
if (!factor) return null;
const n = Number(m[1]) * factor;
return Number.isFinite(n) && n > 0 ? n : null;
}
function parsePercent(raw: string | null | undefined): number | null {
if (!raw) return null;
const m = /^\s*(\d+(?:\.\d+)?|\.\d+)%\s*$/.exec(raw);
if (!m) return null;
const n = Number(m[1]);
return Number.isFinite(n) && n > 0 ? n : null;
}
/** Parses `viewBox="minX minY width height"` into `{ w, h }`. */
export function parseViewBoxSize(raw: string | null | undefined): { w: number; h: number } | null {
if (!raw) return null;
const parts = raw
.trim()
.split(/[\s,]+/)
.map(Number);
if (parts.length !== 4) return null;
const w = parts[2]!;
const h = parts[3]!;
return Number.isFinite(w) && Number.isFinite(h) && w > 0 && h > 0 ? { w, h } : null;
}
function resolveSvgDims(
style: string | null | undefined,
widthAttr: string | null | undefined,
heightAttr: string | null | undefined,
viewBoxAttr: string | null | undefined,
): { w: number; h: number } | null {
const vb = parseViewBoxSize(viewBoxAttr);
const storedW = parseLengthPx(/(?:^|;)\s*--diagram-width\s*:\s*([^;]+)/i.exec(style ?? "")?.[1]);
const inlineMaxW = parseLengthPx(/(?:^|;)\s*max-width\s*:\s*([^;]+)/i.exec(style ?? "")?.[1]);
const attrW = parseLengthPx(widthAttr);
const attrH = parseLengthPx(heightAttr);
const w = storedW ?? inlineMaxW ?? attrW ?? (attrH && vb ? (attrH * vb.w) / vb.h : (vb?.w ?? null));
if (!w) return null;
const h = attrH ?? (vb ? (w * vb.h) / vb.w : w * 0.75);
return { w, h };
}
/** Intrinsic CSS pixel size of an in-DOM `<svg>`, when declared on the element. */
export function svgElementSize(svg: SVGSVGElement): { w: number; h: number } | null {
const fromAttrs = resolveSvgDims(
svg.getAttribute("style"),
svg.getAttribute("width"),
svg.getAttribute("height"),
svg.getAttribute("viewBox"),
);
if (fromAttrs) return fromAttrs;
const box = (svg as SVGSVGElement & { viewBox?: SVGAnimatedRect }).viewBox?.baseVal;
if (box && box.width > 0 && box.height > 0) return { w: box.width, h: box.height };
return null;
}
function readAttr(tag: string, name: string): string | null {
const re = new RegExp(`(?:^|\\s)${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i");
const m = re.exec(tag);
return m ? (m[1] ?? m[2] ?? m[3] ?? null) : null;
}
/**
* Intrinsic CSS pixel size of a `data:image/svg+xml` URL from its `<svg>` header.
* Decodes only the leading chunk so large `.excalidraw.svg` scenes stay cheap.
*/
export function svgDataUrlSize(url: string): { w: number; h: number } | null {
const comma = url.indexOf(",");
if (comma < 0) return null;
const header = url.slice(0, comma);
if (!/^data:image\/svg\+xml\b/i.test(header)) return null;
const payload = url.slice(comma + 1, comma + 1 + 16384);
let head: string;
try {
if (/;base64\b/i.test(header)) {
const clean = payload.replace(/\s+/g, "");
const aligned = clean.slice(0, clean.length - (clean.length % 4));
head = atob(aligned);
} else {
const safe = payload.replace(/%[0-9a-f]?$/i, "");
head = decodeURIComponent(safe);
}
} catch {
return null;
}
const withoutComments = head.replace(/<!--[\s\S]*?-->/g, "");
const open = /<svg\b((?:"[^"]*"|'[^']*'|[^'">])*)>/i.exec(withoutComments);
if (!open) return null;
const attrs = open[1]!;
return resolveSvgDims(
readAttr(attrs, "style"),
readAttr(attrs, "width"),
readAttr(attrs, "height"),
readAttr(attrs, "viewBox"),
);
}
const formatPx = (n: number) => `${Number(n.toFixed(2))}px`;
/**
* Sets an `<img>`'s 1× base width so CSS scales it by `--markdown-zoom-scale`,
* respecting explicit HTML `width` / `height` attributes when present.
*/
export function applyImageZoomWidth(img: HTMLImageElement, intrinsic?: { w: number; h: number } | null): boolean {
const rawWidth = img.getAttribute("width");
const pct = parsePercent(rawWidth);
if (pct !== null) {
img.style.width = `calc(${pct}% * var(--markdown-zoom-scale, 1))`;
img.style.height = "auto";
return true;
}
const attrW = parseLengthPx(rawWidth);
if (attrW !== null) {
img.style.setProperty("--image-width", formatPx(attrW));
img.dataset.naturalWidth = "";
return true;
}
if (!intrinsic || intrinsic.w <= 0 || intrinsic.h <= 0) return false;
const attrH = parseLengthPx(img.getAttribute("height"));
const baseW = attrH !== null ? (attrH * intrinsic.w) / intrinsic.h : intrinsic.w;
img.style.setProperty("--image-width", formatPx(baseW));
img.dataset.naturalWidth = "";
return true;
}
-88
Переглянути файл
@@ -101,102 +101,14 @@ describe("editor font size actions", () => {
);
const preview = screen.getByRole("document", { name: "Markdown preview" });
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("0px");
expect(preview.style.getPropertyValue("--markdown-zoom-scale")).toBe("1");
await act(() => executeAction("editor.increaseFontSize"));
await act(() => executeAction("editor.increaseFontSize"));
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("2px");
expect(preview.style.getPropertyValue("--markdown-zoom-scale")).toBe("1.1538");
await act(() => executeAction("editor.decreaseFontSize"));
await act(() => executeAction("editor.decreaseFontSize"));
await act(() => executeAction("editor.decreaseFontSize"));
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("-1px");
expect(preview.style.getPropertyValue("--markdown-zoom-scale")).toBe("0.9231");
await act(() => executeAction("editor.resetFontSize"));
expect(zoom(md)).toBe(0);
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("0px");
expect(preview.style.getPropertyValue("--markdown-zoom-scale")).toBe("1");
});
it("sizes embedded excalidraw.svg, graph SVGs and raster images so they scale with font zoom", async () => {
const excalidrawSvg =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 940" width="1280" height="940"><!-- svg-source:excalidraw --></svg>';
const excalidrawUrl = `data:image/svg+xml;base64,${btoa(excalidrawSvg)}`;
const graphvizUrl = `data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="300pt" height="150pt" viewBox="0 0 300 150"></svg>')}`;
const wordmarkUrl = `data:image/svg+xml;base64,${btoa('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 56"></svg>')}`;
const pngUrl = "data:image/png;base64,iVBORw0KGgo=";
const ipc = await import("@/platform/ipc");
const fsReadImage = vi.spyOn(ipc.commands, "fsReadImage").mockImplementation(async (p: string) => {
if (p.endsWith("architecture.excalidraw.svg")) return { status: "ok", data: excalidrawUrl };
if (p.endsWith("wordmark.svg")) return { status: "ok", data: wordmarkUrl };
if (p.endsWith("shot.png")) return { status: "ok", data: pngUrl };
return { status: "error", error: { kind: "notFound", message: p } } as never;
});
try {
const doc = [
"![Architecture](./architecture.excalidraw.svg)",
"",
`![Graph](${graphvizUrl})`,
"",
'<img src="./wordmark.svg" alt="Wordmark" height="56">',
"",
'<img src="./wordmark.svg" alt="Icon" width="80">',
"",
"![Shot](./shot.png)",
].join("\n");
const live = editorContributions().find((c) => c.id === "viewers.markdownLive")!;
const view = new EditorView({
state: EditorState.create({ doc, extensions: [fontZoom, live.extensions(mdCtx)] }),
});
const handle = { view, ctx: mdCtx };
_addEditor(handle);
disposers.push(() => _removeEditor(handle));
views.push(view);
activate(view);
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
render(
<MarkdownEditor path={mdCtx.path} tabId="t">
<div />
</MarkdownEditor>,
);
const preview = screen.getByRole("document", { name: "Markdown preview" });
await vi.waitFor(() => {
const arch = preview.querySelector<HTMLImageElement>('img[alt="Architecture"]');
expect(arch?.getAttribute("src")).toBe(excalidrawUrl);
});
const arch = preview.querySelector<HTMLImageElement>('img[alt="Architecture"]')!;
expect(arch.hasAttribute("data-natural-width")).toBe(true);
expect(arch.style.getPropertyValue("--image-width")).toBe("1280px");
const graph = preview.querySelector<HTMLImageElement>('img[alt="Graph"]')!;
expect(graph.hasAttribute("data-natural-width")).toBe(true);
expect(graph.style.getPropertyValue("--image-width")).toBe("400px");
const wordmark = preview.querySelector<HTMLImageElement>('img[alt="Wordmark"]')!;
expect(wordmark.hasAttribute("data-natural-width")).toBe(true);
expect(wordmark.style.getPropertyValue("--image-width")).toBe("280px");
const icon = preview.querySelector<HTMLImageElement>('img[alt="Icon"]')!;
expect(icon.hasAttribute("data-natural-width")).toBe(true);
expect(icon.style.getPropertyValue("--image-width")).toBe("80px");
const shot = preview.querySelector<HTMLImageElement>('img[alt="Shot"]')!;
Object.defineProperty(shot, "naturalWidth", { value: 960, configurable: true });
Object.defineProperty(shot, "naturalHeight", { value: 600, configurable: true });
act(() => {
shot.dispatchEvent(new Event("load"));
});
expect(shot.hasAttribute("data-natural-width")).toBe(true);
expect(shot.style.getPropertyValue("--image-width")).toBe("960px");
} finally {
fsReadImage.mockRestore();
}
});
it("scales a configured editor font size", () => {
-5
Переглянути файл
@@ -50,11 +50,6 @@ export function attachPanZoom(viewport: HTMLElement, options: PanZoomOptions = {
(e) => {
if (!(e.metaKey || e.ctrlKey) || !e.deltaY) return;
e.preventDefault();
if (view.z === origin.z && (viewport.scrollLeft || viewport.scrollTop)) {
view = { ...view, x: view.x - viewport.scrollLeft, y: view.y - viewport.scrollTop };
viewport.scrollLeft = 0;
viewport.scrollTop = 0;
}
const rect = viewport.getBoundingClientRect();
// One wheel notch (~100 px, 3 lines or a page) zooms about 15%; a trackpad
// sends small pixel deltas, so zooming follows the gesture continuously.
-4
Переглянути файл
@@ -146,10 +146,6 @@
background: transparent;
color: var(--fg-secondary);
}
.mainMenuButton:hover,
.mainMenuButton[aria-expanded="true"] {
background: var(--bg-toolbar-hover);
}
.mainMenuButton:focus-visible,
.menuTitle:focus-visible,
.caption:focus-visible {