Файли
openidea/crates/ide-plugin/tests/fixtures/web-log/src/lib.rs
T
l0ng-ai 2bf412ff0d feat(plugins): let plugin code open streaming log tabs (#2082)
views.open-log-tab(key, title, process-log) (SDK host::open_log_tab) opens the read-only log tab a web view opens with open-log-tab, from a command or event of a window, reusing the Services pane's process-log.

The host checks the process grant and limits when called and remembers what each key runs in that window; the tab starts it by key (plugin_log_tab_spawn) through the web-view PTY checks: pinned program, trusted project, session cap, lifecycle and grant revocation. Remote windows report that these tabs aren't available there yet.
2026-11-08 10:01:35 +08:00

39 рядки
1.2 KiB
Rust

use openidea_plugin::details::ProcessLog;
use openidea_plugin::{Error, Invocation, Plugin, host, register_plugin};
const SCRIPT: &str = r#"i=0
while true; do
i=$((i+1))
printf 'INFO probe line %s — Unicode 日志\n' "$i"
if [ "$1" = "--verbose" ]; then printf 'DEBUG verbose output enabled\n'; fi
read -t 1 ignored || true
done"#;
#[derive(Default)]
struct WebLog;
impl Plugin for WebLog {
fn run_command(&mut self, id: &str, _ctx: &Invocation, _arg: Option<&str>) -> Result<Option<String>, Error> {
match id {
"open" | "denied" => {
host::post_view_message("logs", id)?;
Ok(None)
}
// The same stream as the page's, opened by the plugin's code.
"code" => {
let log = ProcessLog::new("bash", &["--noprofile", "--norc", "-c", SCRIPT, "log-probe"]).toggle(
"verbose",
"Verbose",
&["--verbose"],
);
host::open_log_tab("code", "Probe logs (code)", &log)?;
Ok(None)
}
"ping" => Ok(Some("Web log ready".into())),
_ => Err(Error::NotFound(id.into())),
}
}
}
register_plugin!(WebLog);