mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
A command is now declared once, on the fn that implements it. A project-host command is an ide-host fn with #[command(trust = …)] listed in its module's domain!; its Tauri adapter, bindings entry, JSON-RPC handler, trust class and remote routing are derived from that declaration. Desktop-only commands keep their Tauri fn and add #[desktop_command(trust = …)]. This removes the hand-written pass-through adapters, collect_commands!, the per-domain register fns and the trust tables in trust.rs. The invoke handler looks up each command's declared trust class; a name nothing declares is denied. A remote window routes the project-host commands of the desktop's own build. Duplicate names are a compile error. CI runs ide-command's compile_fail doctests. Part of #3344. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
//! Tauri runs a sync command on the main thread, so disk I/O or a large diff there freezes the
|
|
//! window (input, painting, every other IPC call).
|
|
|
|
use ide_host::catalogue::Mode;
|
|
|
|
/// Commands that read or write project files, Local History or `.env` files, diff two
|
|
/// arbitrary texts, or scan the project index in parallel: they must do that work off the
|
|
/// main thread.
|
|
const OFF_MAIN_THREAD: &[&str] = &[
|
|
"history_list",
|
|
"history_content",
|
|
"find_files",
|
|
"find_dirs",
|
|
"find_symbols",
|
|
"vcs_diff_hunks",
|
|
"vcs_shelves",
|
|
"vcs_shelf_delete",
|
|
"vcs_shelf_rename",
|
|
"vcs_shelf_patch",
|
|
"vcs_changelists_load",
|
|
"run_save_configs",
|
|
"run_templates",
|
|
"run_save_templates",
|
|
"run_import_sources",
|
|
"run_import_configs",
|
|
"run_env_files",
|
|
];
|
|
|
|
#[test]
|
|
fn disk_and_diff_commands_stay_off_the_main_thread() {
|
|
let declarations = openidea_lib::declarations();
|
|
let on_main: Vec<_> = OFF_MAIN_THREAD
|
|
.iter()
|
|
.filter(|name| {
|
|
let declared = declarations.iter().find(|c| c.name == **name);
|
|
declared.unwrap_or_else(|| panic!("no command {name}")).mode == Mode::Sync
|
|
})
|
|
.collect();
|
|
assert!(on_main.is_empty(), "synchronous commands run on the main thread: {on_main:?}");
|
|
}
|