feat(plugins): one-shot timers a plugin sets for itself (API 1.21) (#8239)

events.schedule(id, after-ms) wakes the plugin once with a timer event in the window of the call that set it; the same id replaces it, so retries and backoff stay the plugin's own, and events.cancel-schedule drops it. 250 ms to 24 h, at most 16 pending, no capability. Timers activate an idle plugin, survive idle reclaim and end with the window, its project or the plugin. SDK: host::schedule, host::cancel_schedule, Event::Timer, MockHost timers. Components rebuilt.

Closes #8195
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-05 22:31:19 +08:00
1 джерело eefe6cc9c8
коміт 3f74972f11
152 files changed
+896 -131

No files matched your search

+56
Переглянути файл
@@ -314,6 +314,16 @@ const DEFAULT_STREAM_BUFFER: usize = 256 << 10;
const DEFAULT_STREAM_MAX_TOTAL: usize = 32 << 20;
/// Most processes one plugin keeps running at once.
const MAX_PROCESSES: usize = 8;
/// Pending `events.schedule` timers per plugin.
const MAX_TIMERS: usize = 16;
/// A pending `events.schedule` timer: fires `id` in window `client` at `due`.
#[derive(Clone, Debug)]
pub(super) struct Timer {
pub id: String,
pub due: Instant,
pub client: Option<String>,
}
/// Most output one stream of a handle holds until the plugin reads it.
const MAX_PENDING: usize = 1 << 20;
/// Most files `find-files` walks before giving up.
@@ -810,6 +820,8 @@ pub(super) struct Shared {
pub subscriptions: Mutex<super::event_paths::Subscriptions>,
/// Paths outside their project that plugins watch (kept across idle reclaim).
pub(super) external_watches: super::external_watch::ExternalWatches,
/// plugin → its pending `events.schedule` timers (kept across idle reclaim).
pub(super) timers: Mutex<HashMap<String, Vec<Timer>>>,
/// plugin → files it shows problems for, withdrawn when it stops.
diagnostics: Mutex<HashMap<String, BTreeSet<PathBuf>>>,
project_generations: Mutex<HashMap<PathBuf, u64>>,
@@ -918,6 +930,7 @@ impl Shared {
closed_clients: Mutex::default(),
subscriptions: Mutex::default(),
external_watches: Default::default(),
timers: Mutex::default(),
diagnostics: Mutex::default(),
project_generations: Mutex::default(),
log_tabs: Mutex::default(),
@@ -1064,6 +1077,9 @@ impl Shared {
self.prompts.lock().retain(|_, entry| entry.client != client);
drop(closed);
self.contexts.lock().retain(|(scope, ..), _| scope.as_deref() != Some(client));
for timers in self.timers.lock().values_mut() {
timers.retain(|t| t.client.as_deref() != Some(client));
}
self.loopbacks.read().forget_window(client);
self.window_status.lock().retain(|(window, ..), _| window != client);
self.view_badges.lock().retain(|(window, ..), _| window != client);
@@ -1120,6 +1136,24 @@ impl Shared {
.retain(|(p, w), _| plugin.is_some_and(|plugin| plugin != p) || window.is_some_and(|window| window != w));
}
/// Removes the timers due at `now`: (plugin, window, id), earliest first.
pub(super) fn take_due_timers(&self, now: Instant) -> Vec<(String, Option<String>, String)> {
let mut due = Vec::new();
let mut all = self.timers.lock();
for (plugin, timers) in all.iter_mut() {
timers.retain(|t| {
if t.due > now {
return true;
}
due.push((t.due, plugin.clone(), t.client.clone(), t.id.clone()));
false
});
}
all.retain(|_, timers| !timers.is_empty());
due.sort_by_key(|(at, ..)| *at);
due.into_iter().map(|(_, plugin, client, id)| (plugin, client, id)).collect()
}
pub fn client_closed(&self, client: &str) -> bool {
self.closed_clients.lock().contains(client)
}
@@ -1224,6 +1258,7 @@ impl Shared {
}
if subscriptions {
self.external_watches.remove_plugin(plugin);
self.timers.lock().remove(plugin);
}
if subscriptions && self.subscriptions.lock().remove(plugin) {
self.sink.emit(None, PluginEvent::SubscriptionsChanged);
@@ -3825,6 +3860,27 @@ impl HostApi for PluginApi {
self.shared.sink.emit(None, PluginEvent::SubscriptionsChanged);
}
}
fn schedule(&self, client: Option<&str>, id: &str, after: Duration) -> Result<(), HostError> {
if client.is_some_and(|c| self.shared.client_closed(c)) {
return Err(HostError::Cancelled);
}
let mut timers = self.shared.timers.lock();
let mine = timers.entry(self.id().to_owned()).or_default();
mine.retain(|t| t.id != id);
if mine.len() >= MAX_TIMERS {
return Err(HostError::Invalid(format!("at most {MAX_TIMERS} timers may be pending: cancel one first")));
}
mine.push(Timer { id: id.to_owned(), due: Instant::now() + after, client: client.map(str::to_owned) });
Ok(())
}
fn cancel_schedule(&self, id: &str) {
let mut timers = self.shared.timers.lock();
if let Some(mine) = timers.get_mut(self.id()) {
mine.retain(|t| t.id != id);
}
}
fn start_process(&self, cmd: ProcessCommand, cwd: Option<&Path>, client: Option<&str>) -> Result<u64, HostError> {
self.start_process_stream(cmd, cwd, client, None)
}
+2 -1
Переглянути файл
@@ -480,7 +480,8 @@ mod tests {
#[test]
fn every_runtime_event_has_a_matching_manifest_activation() {
for kind in ide_plugin::EventKind::ALL {
if kind != ide_plugin::EventKind::Scheduled {
// `on-schedule` and `events.schedule` timers activate the plugin themselves.
if !matches!(kind, ide_plugin::EventKind::Scheduled | ide_plugin::EventKind::Timer) {
assert!(ide_extension::EVENT_KINDS.contains(&kind.name()));
}
}
+32 -1
Переглянути файл
@@ -2144,6 +2144,10 @@ impl PluginHost {
pub fn project_closed(&self, root: &Path, window: &str) {
self.shared.close_project_generation(root);
self.shared.external_watches.remove_project(root);
// Timers set for the window's project don't outlive it.
for timers in self.shared.timers.lock().values_mut() {
timers.retain(|t| t.client.as_deref() != Some(window));
}
self.withdraw_project_run_targets(root);
self.shared.run_configurations.write().retain(|(_, r), _| r != root);
@@ -2359,6 +2363,28 @@ impl PluginHost {
}
}
/// Queues the `events.schedule` timers due at `now` for their plugin and window.
fn queue_due_timers(&self, now: Instant) {
let due = self.shared.take_due_timers(now);
if due.is_empty() {
return;
}
let mut queues = self.queues.lock();
for (plugin, client, id) in due {
if client.as_deref().is_some_and(|c| self.shared.client_closed(c)) {
continue;
}
let queue = queues.entry((plugin, client)).or_insert_with(|| EventQueue {
since: now,
last_event: now,
events: Vec::new(),
files_source: None,
});
queue.last_event = now;
queue.events.push(WorkbenchEvent::Timer(id));
}
}
pub fn post_events(&self, client: Option<&str>, events: Vec<WorkbenchEvent>) {
self.post_events_from(client, events, None);
}
@@ -2446,6 +2472,7 @@ impl PluginHost {
| WorkbenchEvent::RunExited(_)
| WorkbenchEvent::TerminalExited(_)
| WorkbenchEvent::ContentTabAction(_)
| WorkbenchEvent::Timer(_)
)
{
remaining -= 1;
@@ -2470,6 +2497,7 @@ impl PluginHost {
pub fn flush_events_at(&self, now: Instant) {
self.reload_changed_links();
self.queue_watched_changes(now);
self.queue_due_timers(now);
let running: BTreeSet<String> = self
.plugins
.read()
@@ -2494,7 +2522,9 @@ impl PluginHost {
let (id, _client) = key;
let running = running.contains(id);
let has_files = q.events.iter().any(|e| matches!(e, WorkbenchEvent::FilesChanged(_)));
let has_scheduled = q.events.iter().any(|e| matches!(e, WorkbenchEvent::Scheduled));
// Due now: a timer was set for this moment, an `on-schedule` period elapsed.
let has_scheduled =
q.events.iter().any(|e| matches!(e, WorkbenchEvent::Scheduled | WorkbenchEvent::Timer(_)));
// Already debounced by the watcher, like project file changes.
let has_watched = q.events.iter().any(|e| matches!(e, WorkbenchEvent::WatchedFilesChanged(_)));
let debounce = debounces.get(id).copied();
@@ -2680,6 +2710,7 @@ impl PluginHost {
| EventKind::RunExited
| EventKind::TerminalExited
| EventKind::ContentTabAction
| EventKind::Timer
)
})
{
+1
Переглянути файл
@@ -57,6 +57,7 @@ mod plugin_semantic_tokens;
mod plugin_server_commands;
mod plugin_symbols;
mod plugin_syntax_decorations;
mod plugin_timers;
mod plugin_view_badge;
mod plugin_watch_paths;
mod plugin_workbench;
+80
Переглянути файл
@@ -0,0 +1,80 @@
//! `events.schedule` (API 1.21): one-shot timers a plugin sets for itself, fired in the
//! window that set them, replaced by id, cancelled, and dropped with the window.
use ide_host::plugins::{Consent, PluginHost};
use ide_plugin::{Invocation, Limits};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Duration, Instant};
const ID: &str = "timers";
fn fixture() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../ide-plugin/tests/fixtures/timers")
}
struct Setup {
_tmp: tempfile::TempDir,
host: PluginHost,
}
fn setup() -> Setup {
let tmp = tempfile::tempdir().unwrap();
let base = dunce::canonicalize(tmp.path()).unwrap();
let host = PluginHost::new(base.join("plugins"), Arc::new(|_: Option<&str>, _| {}), Limits::default()).unwrap();
host.load_all();
host.startup_finished();
host.install_from_dir(&fixture(), &Consent::all()).unwrap();
Setup { _tmp: tmp, host }
}
impl Setup {
fn run(&self, command: &str, arg: &str) -> Result<Option<String>, String> {
let inv = Invocation { client: Some("main".into()), ..Default::default() };
self.host.run_command(ID, command, Some(arg), inv).map_err(|e| e.message)
}
/// Delivers what is due `after` from now, then what the plugin received.
fn fired_after(&self, after: Duration) -> Vec<String> {
self.host.flush_events_at(Instant::now() + after);
assert!(self.host.wait_events(Duration::from_secs(10)));
let stored = self.run("fired", "").unwrap();
stored.map(|s| serde_json::from_str(&s).unwrap()).unwrap_or_default()
}
}
#[test]
fn a_timer_fires_once_when_due_and_the_same_id_replaces_it() {
let s = setup();
s.run("schedule", "retry 300").unwrap();
s.run("schedule", "later 300").unwrap();
s.run("schedule", "later 60000").unwrap();
assert!(s.fired_after(Duration::ZERO).is_empty(), "nothing is due yet");
assert_eq!(s.fired_after(Duration::from_secs(2)), ["retry"]);
assert_eq!(s.fired_after(Duration::from_secs(2)), ["retry"], "a timer fires once");
assert_eq!(s.fired_after(Duration::from_secs(61)), ["retry", "later"]);
}
#[test]
fn cancelled_timers_and_those_of_a_closed_window_never_fire() {
let s = setup();
s.run("schedule", "cancelled 300").unwrap();
s.run("cancel", "cancelled").unwrap();
s.run("cancel", "unknown").unwrap();
s.run("schedule", "closed 300").unwrap();
s.host.forget_client("main");
s.host.reopen_client("main");
assert!(s.fired_after(Duration::from_secs(2)).is_empty());
}
#[test]
fn schedule_checks_its_bounds() {
let s = setup();
for arg in ["x 249", "x 86400001", " 1000"] {
assert!(s.run("schedule", arg).unwrap_err().contains("timer"), "{arg}");
}
for i in 0..16 {
s.run("schedule", &format!("t{i} 1000")).unwrap();
}
assert!(s.run("schedule", "t16 1000").unwrap_err().contains("at most 16"));
s.run("schedule", "t0 2000").unwrap();
}
+11
Переглянути файл
@@ -693,6 +693,13 @@ pub trait HostApi: Send + Sync {
Err(HostError::Failed("watching paths is unavailable here".into()))
}
fn unsubscribe(&self, kind: &str);
/// Wakes this plugin with a `timer` event `id` after `after`, in window `client`
/// (API 1.21); replaces a pending timer with the same id. `id` and `after` are checked.
fn schedule(&self, _client: Option<&str>, _id: &str, _after: std::time::Duration) -> Result<(), HostError> {
Err(HostError::Failed("timers are unavailable here".into()))
}
/// Cancels this plugin's pending timer `id`, if any (API 1.21).
fn cancel_schedule(&self, _id: &str) {}
/// Starts `cmd` and returns the handle to it without waiting.
fn start_process(&self, cmd: ProcessCommand, cwd: Option<&Path>, client: Option<&str>) -> Result<u64, HostError>;
/// Starts `cmd` with streaming options (API 1.15).
@@ -1275,6 +1282,10 @@ fn event_to_wit(e: WorkbenchEvent) -> wit_events::Event {
data: serde_json::to_string(&p).expect("path serializes"),
}),
WorkbenchEvent::Scheduled => wit_events::Event::Scheduled,
WorkbenchEvent::Timer(id) => wit_events::Event::Other(wit_types::Extension {
kind: "timer".into(),
data: serde_json::to_string(&id).expect("id serializes"),
}),
WorkbenchEvent::ActionPerformed(a) => wit_events::Event::ActionPerformed(wit_events::ActionPerformed {
action: a.action,
title: a.title,
+9 -1
Переглянути файл
@@ -240,10 +240,12 @@ pub enum EventKind {
/// Paths outside the project watched with `events.watch-paths` changed (API 1.18).
WatchedFilesChanged,
Scheduled,
/// A timer the plugin set with `events.schedule` fired (API 1.21); delivered without subscribing.
Timer,
}
impl EventKind {
pub const ALL: [Self; 22] = [
pub const ALL: [Self; 23] = [
Self::DocumentChanged,
Self::WebsocketReady,
Self::FileClosed,
@@ -266,6 +268,7 @@ impl EventKind {
Self::ProjectClosed,
Self::WatchedFilesChanged,
Self::Scheduled,
Self::Timer,
];
pub fn name(self) -> &'static str {
@@ -292,6 +295,7 @@ impl EventKind {
Self::ProjectClosed => "project-closed",
Self::WatchedFilesChanged => "watched-files-changed",
Self::Scheduled => "scheduled",
Self::Timer => "timer",
}
}
@@ -306,6 +310,7 @@ impl EventKind {
Self::ActionPerformed | Self::InputModeChanged => Some(ide_extension::Capability::InputEvents),
Self::RunOutput => Some(ide_extension::Capability::RunOutput),
Self::Scheduled
| Self::Timer
| Self::RunStarted
| Self::RunExited
| Self::TerminalExited
@@ -485,6 +490,8 @@ pub enum WorkbenchEvent {
/// `project` is the project the watch belongs to, `generation` is unset.
WatchedFilesChanged(FilesChanged),
Scheduled,
/// A timer this plugin set with `events.schedule` fired (API 1.21): its id.
Timer(String),
}
impl WorkbenchEvent {
@@ -512,6 +519,7 @@ impl WorkbenchEvent {
Self::ProjectClosed(_) => EventKind::ProjectClosed,
Self::WatchedFilesChanged(_) => EventKind::WatchedFilesChanged,
Self::Scheduled => EventKind::Scheduled,
Self::Timer(_) => EventKind::Timer,
}
}
}
+29
Переглянути файл
@@ -1895,6 +1895,32 @@ impl events::Host for StoreData {
Ok(())
}
fn schedule(&mut self, id: String, after_ms: u32) -> Fallible<()> {
if let Err(e) = self.host.require_api("events.schedule", 21) {
return Ok(Err(to_wit(e)));
}
if id.is_empty() || id.len() > 128 || id.chars().any(char::is_control) {
return Ok(Err(wit::Error::Invalid("timer id must be 1-128 bytes without control characters".into())));
}
if !(MIN_TIMER_MS..=MAX_TIMER_MS).contains(&after_ms) {
return Ok(Err(wit::Error::Invalid(format!(
"a timer fires {MIN_TIMER_MS} ms to {MAX_TIMER_MS} ms from now"
))));
}
let client = self.client().map(str::to_owned);
Ok(self
.host
.schedule(client.as_deref(), &id, std::time::Duration::from_millis(u64::from(after_ms)))
.map_err(to_wit))
}
fn cancel_schedule(&mut self, id: String) -> wasmtime::Result<()> {
if self.host.require_api("events.schedule", 21).is_ok() {
self.host.cancel_schedule(&id);
}
Ok(())
}
fn watch_paths(&mut self, paths: Vec<String>) -> Fallible<()> {
if let Err(e) = self.require(Capability::Events) {
return Ok(Err(e));
@@ -1934,6 +1960,9 @@ impl events::Host for StoreData {
/// The most paths one plugin watches outside one project (`events.watch-paths`).
const MAX_WATCHED_PATHS: usize = 32;
/// Bounds of `events.schedule`: the event loop's own period, and a day.
const MIN_TIMER_MS: u32 = 250;
const MAX_TIMER_MS: u32 = 24 * 60 * 60 * 1000;
impl tasks::Host for StoreData {
fn begin(&mut self, title: String, cancellable: bool) -> wasmtime::Result<Resource<TaskRes>> {
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
0db78244977b314a99277abd9259edbfc62c304e97a39d46fda547069c5186c1
8fe67be847a6bd86dd288aa678357fd2caf28b4aa74e7067efd07961ab37ffa0
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
4e7ceccb5ef879e0124f2717ae29ee7c241330a085f1628a7ea775078cddebfb
e562434a35eca32556c79381eacd380f101f03009a6aeae0d34db893bf93ba75
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
1034c381a884838c3ba6516c947ce6824c06f0dc9740a6aac9c43874649f5dd8
3f2459f0b4b016ad28aaf4e157e43a25cda92b325ee09fbb37cccc8daa34df6b
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
40d95bcd5086e5a20bc23d130b960e87a7c13c065d06cc05edcad931cd0d7f33
286012eeb2145fbc92c7648e7759f1ada45e347b5421c1917cd944fc063e1863
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
9b6b716f511497a37d37bdde39b8d669f78cb440ada45cdffe9dfe453bbaf930
4fade1b835a8823e505e195b8a616093126ef670de2618ec54baac1fcbb60ce6
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
c4100a64064acf9d51de0eed6b3232102df06d70eb7d3ea4793228be84e5a00d
bdff2d28e51e8c1eacc92a19b2a4e28581a9c5a895359187d83fecb5be3d3a85
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
457306cdbd68b2b0aaa7073a9574d966deeb54993192f1935c1e4d0d92520d9f
e594c6b4a22cb97c7355793c3d294b966ba10b5a79cc847e47f6019489369fde
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
b10e885276249c17d2a41f2cc4cf7c1452eaefd2f9c2c4d1e2037f311ea0171e
af09884fe417936b2a76a6c22842630f661e3575c3862e31cad4867a4b9f9e56
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
2de813834872315bac348dbbc1f44d9e67ca3fbccf24f3d6ac2e0404d4632652
ec069a728a1f3e914e7708f579fd1f7ce2dbd29e1483453696b15b75906be10e
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
dfbb456cb19f79cf4bde2961434193602659f3b357a09aa42b2c5647350a70b8
9ee77f07270b33457abb1acca9430b83c3b8a2cd21e02e82a541e65cfa60b05d
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
2afe22a19f5d3ce2a47476de1421240dbb89a43a1b90d4e21b681be447587459
035cb92e3fcc09302d302243f65183d1173bd04c415e2a8c5b67494ea964da26
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
da12c11b71b954be2e4526aa48300194d85b5f16657dcaf56400ddc08b3a2146
4aef5fd2f4eb1e47877f70b752764f1d1c7345abde8722ebc314748c3b9b41d2
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
53788d2cc83b5fe02839175dc3b4a3640bf1c925eb031f9c555b60539005e84e
1e96fa8cfefd02b486c3abc060784f703529d1b7635c4b527c4ab0717cf29146
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
d467c8dcdda58f2d83c46c259c790789747f1ca408cb7ddcef8c800dd2d57599
35fd22ae39343dc0a606d6f31149fced471397eafe713e519a1d8b3f44805948
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
27601dc768aa92cbdd014312031c5ccd29f771a65d955733f75dbdcb4d6847df
f70d9de39765ff84cca47030c9d7a8bca1caaadceb70d526e44821a5cbfbf6be
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
997876fd37f0c2596de5af907ae126eeaa8be97ce12fc7fd5559d2fda71feb7c
64140ad91c947d9b672eef867e8ce86a1fa254cf41de8786c26aa64879cc69bb
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
5f9c258237bd2a038a0fe6559f1b6cddfb45c3c23ca9738768849b52b07c0540
8daca93352b13cd876045913eed114a43b66d9f4b0ec48f2992f67f1a60ac65d
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
6ec2d8b7c841c62d2a5d34c237ca255acc19eb8839b40fcb954896f858b785d0
2990b5753169d476afd5be487cfdc26d4ffc66487a51a7a99ccd1e07c3cbd21c
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
702515bbdf2889c96c18e88d55cbbf427c59dfcbd74a855ee0564fe69321f0e3
67233a03c58b09682303da49f3d6f209857f2ef3e910c2533a5055e233ff6096
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
e9a13db283bb5996428ec5d8c02b71960df37e09c7096544984aa74569cd3f9b
d2f812daeae98c466e7b23450d86e583ed2db8bf7e39cd6e6005be4a0b1a08d1
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
a21246e41ea373db2a4076dfe58e5f93f5c2493d5af330c14a9d19b9d8519ec7
ac7fdaffaef9f364997ce3434410f22b776e47aa98df78febad213c1a0dda2dc
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
719a9fbd852fa437bce882ea74eab5ec98484ecac3cb41cf3ec03aa7188753c1
1b54498a31ffc6c373769f780c7f8510ca62787f6d0d5eafa904dd834bcadc5b
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
60c315d025f21d8767ecd014c8279ebe5ffae2ab21e04b8f2e7b02b9eaea4a08
286c6f6253d58245102b9797c0d80f54749bdb51e458156f79fe54885b6a76d3
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
3eee6f098f4555b6572b52c92fbb727179cd0ef8a3a5a3a4f7ca56f808a108cf
67584a6306508021b9dd9453ce687b8dd73dd5c0577524172bb6ef2a506a4c86
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
8852afa6aa3175cd0f229aa23a17ba99ecfb9dcc30e1d22e79bfbfc78a993821
983f6a29e1bc6a0535cb9aea23216505f81e85f32b7497b5366568e04ccc81fd
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
f121c229c3c859d1c653c52cb9920598e4ccb76dccf0b2171c5e8cd806287887
483cf0a847b27bd107f385b9e256b184579d798b8e9a15dd383a938f71a94d2b
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
1520af95c95473e62fc65a7d7b0c9cd0d0be63e6427e0bce8f61076a8ca36abc
9a3f69e9f7779e91106107b1fa34c13944058b8543330d55df0cc8b415d7b480
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
4371ff5140e1ba6a6f977236c3ae0f16f7d1d9866157d6d32edc6252b39dcf55
5b208da2e34ba9e2ce7653b2692586e8705fd5eb1466ce996a71882998ebb249
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
751cfd926cc911aa2e0e08a263ab0162ef9c9a7cb10ccc4e589b1a7ec6952def
cd715076bcce3606ec3bfadee5964a28e668f652c4c5219185aee05f5908b346
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
57409ecf10f15f49b0b87ad8908d3491b7cc26c8997d21400ee0bed23631a83e
d77ce6b138dbba4184e63bb178147f86fc9beae2a8dd24bba28ae696e49133a4
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
afda156cd79a5b76b1507e40cfd2ab2f948bf7d82bf7a3564317c62d34c47bef
dfbb9da1f64f162a77feba37001b1574f785603a475365450707c615d3b8e174
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
af4c36aa2ccbaa4d96b6e285527d4d9de9c55da5844cda32d24e692d69668058
9da9f094dad19091682682a241d17e4206738f2b832f4e603d8a51a54d63b701
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
72a56aaf416dba436b6e3675529d25eac1f861c774ab5e8899a9a5bd37f8f1a3
796e5d8bfe42c668d2688a72c2ad50053cde7f82888ac33e32f52ab4fec60be6
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
7918542fd905ee16fa2633f3cfcc404f7a882669d3b30c927028c70c58b78542
5ff1341eac1f6703edbf557b0b6b6d6046078c00f163f7140fe987cce7715348
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
aa0af7349bea316c75febc01bdac68c0ca9bfc78192df276e129044cd762306d
afa7550aef81aae6bc27229bed4d9b6ab4a5280c0321434954facd9bfb54a36e
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
a560827089dada8f1484242969088c505f7ee486ab5f82551c800f70a6637c9c
cf4df7af53ca6a333452a3fee0bf0687eef608dace6b70a69bfe9172f9046ad5
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
b334bf475c86c7a5bf89b8dcb7838610c9ba81fdc389473e0a0716e37e0ad0f6
ff3a5044cd50e6020ad73877e162047d2219649361480ec6ecf03267e32c5af0
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
7c1d4bd1b2fde8d3e110b3b7d383cf4a2df387a2414a34f91b8d711285b280f5
2d2e5aad65cc1c3ac1c89762dc304e4905259d6ef864f91edf2b74c80b2073e5
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
13fa1388bfe546450b2ac30fecf69c6b0cde7fb937ed73ad7fc5c240708a1820
93f7cb61f482db2032ff1aa1cc3f7dd4078be13fcd579e439da0f2b7670eba18
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
3bc1b36422bf070db59c4f2e8ed80370af220b8516e48f99bcb7f0c73ce06cf7
9f7553a1db7109d654f0a92714ccd61e1d06cd6e4603aa5fcd5262391f2635d4
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
70e0d484e345cd18c9d19ff2246a949d20d013231f8e8221e71bb42187352a54
4a99c00d8b1db2fe44cef75b0f07c03766aca5cc42f7ad0d3d8b562961d617d3
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
f2dc5445b02f4a8e3ec602695c0ec39176a6d744c0874ed32450c6e9747e702c
d800c982b3f3bba00f73a93464694ba41799e36490b8d67868f75c72390b3af0
Бінарний файл не відображається.
+1 -1
Переглянути файл
@@ -1 +1 @@
29a7eb777cce864cc12198b00fd07f39383931dd512e66c2cc3f31ffb5095f40
66408b8c3fb5272aeba999d4dfdf49f6080abadd83268b66365ea4a655465f1d
+337
Переглянути файл
@@ -0,0 +1,337 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anyhow"
version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
[[package]]
name = "bitflags"
version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "foldhash"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]]
name = "hashbrown"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc"
dependencies = [
"foldhash",
]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "id-arena"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
"serde",
"serde_core",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "leb128fmt"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
name = "log"
version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
[[package]]
name = "macro-string"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e7b3a5bbb2f63aaa223a671ea1bd0e7bc16bd30ce387324cf63995deaddbbd2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "openidea-plugin"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
"wit-bindgen",
]
[[package]]
name = "openidea-test-timers"
version = "0.1.0"
dependencies = [
"openidea-plugin",
"serde_json",
]
[[package]]
name = "prettyplease"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "wasm-encoder"
version = "0.262.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4495a6f85dd94c411c749303efcbc5defade0b0cbdbc0541495241ab917a9b5a"
dependencies = [
"leb128fmt",
"wasmparser",
]
[[package]]
name = "wasm-metadata"
version = "0.262.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c86ff6668190d9fb70372b306b4f9fe8930f0e2f57ce72e4922bf2f117900949"
dependencies = [
"anyhow",
"indexmap",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.262.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "974d643b125b272607e2fff8012ea14a8328acd7621e4bafa7afb32500052b1b"
dependencies = [
"bitflags",
"hashbrown",
"indexmap",
"semver",
]
[[package]]
name = "wit-bindgen"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b85a987ab61d365382d25c7d47e26edd48941b3bf6e3fbf76eff918bc71dab06"
dependencies = [
"bitflags",
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775e122e390603abfacd548027016cd0113a6e2bf2f8ce6bdd3658b013456ea8"
dependencies = [
"anyhow",
"heck",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84e26e13b9d972026778d2ffb7985736de116026fdc8d9464f966e12df2eb240"
dependencies = [
"anyhow",
"heck",
"indexmap",
"prettyplease",
"syn",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a008a0d6b4840677326beb4edbeb210a2f1b7d0183fb7cc33f466b90fd7fb6"
dependencies = [
"anyhow",
"macro-string",
"prettyplease",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
]
[[package]]
name = "wit-component"
version = "0.262.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078def49fdb49cab405c3006e05793b3fdaf7069126ba6b9c97d01ec8c98fe4c"
dependencies = [
"anyhow",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.262.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00f0dc051466ffe46787721fca3d088536f158ae400be044f1b1c386ba9397ad"
dependencies = [
"anyhow",
"hashbrown",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-ident",
"wasmparser",
]
[[package]]
name = "zmij"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+21
Переглянути файл
@@ -0,0 +1,21 @@
[package]
name = "openidea-test-timers"
version = "0.1.0"
edition = "2024"
publish = false
[workspace]
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
openidea-plugin = { path = "../../../../../sdk/rust/openidea-plugin" }
serde_json = "1"
[profile.release]
opt-level = "s"
lto = true
strip = true
codegen-units = 1
panic = "abort"
Бінарний файл не відображається.
+1
Переглянути файл
@@ -0,0 +1 @@
c18e21c5a77a5ed36aad3ed2471077f72572ebaa41bd0dc70ee61754d6d61b2a
+21
Переглянути файл
@@ -0,0 +1,21 @@
id = "timers"
name = "Timers test"
version = "0.1.0"
engines.openidea = "^1.21"
wasm = "dist/plugin.wasm"
activation = ["on-command:*"]
[capabilities]
required = ["storage"]
[[contributes.commands]]
id = "schedule"
title = "Set the timer given as `<id> <ms>`"
[[contributes.commands]]
id = "cancel"
title = "Cancel the timer given"
[[contributes.commands]]
id = "fired"
title = "Read the ids of the timers that fired"
+35
Переглянути файл
@@ -0,0 +1,35 @@
use openidea_plugin::{Error, Event, Invocation, Plugin, host, register_plugin};
#[derive(Default)]
struct Timers;
impl Plugin for Timers {
fn run_command(&mut self, id: &str, _ctx: &Invocation, arg: Option<&str>) -> Result<Option<String>, Error> {
match id {
"schedule" => {
let (timer, ms) = arg.unwrap_or_default().split_once(' ').ok_or(Error::Invalid("<id> <ms>".into()))?;
host::schedule(timer, ms.parse().map_err(|_| Error::Invalid(ms.into()))?)?;
Ok(None)
}
"cancel" => {
host::cancel_schedule(arg.unwrap_or_default());
Ok(None)
}
"fired" => host::storage::get("fired"),
_ => Err(Error::NotFound(id.into())),
}
}
fn handle_events(&mut self, events: &[Event], _ctx: &Invocation) {
let mut fired: Vec<String> =
host::storage::get("fired").unwrap().map(|s| serde_json::from_str(&s).unwrap()).unwrap_or_default();
for event in events {
if let Event::Timer(id) = event {
fired.push(id.clone());
}
}
host::storage::set("fired", &serde_json::to_string(&fired).unwrap()).unwrap();
}
}
register_plugin!(Timers);
Loaded 100 of 152 files, more files were not shown because too many files have changed in this diff. Show more