Files
openidea/sdk/rust/openidea-plugin/src/commit.rs
l0ng-ai d235c432ec
CI / Rust (macos-latest) (push) Canceled after 0s
CI / Rust (windows-latest) (push) Canceled after 0s
Language smoke / Language smoke (typescript) (push) Failing after 3s
CI / Plugins (SDK, official, fixtures) (push) Failing after 58s
CI / Changes (push) Successful in 1s
CI / Rust (ubuntu-22.04) (push) Failing after 43s
CI / Cargo deny (push) Failing after 5s
Language smoke / Language smoke (java) (push) Failing after 7s
Language smoke / Language smoke (kotlin) (push) Failing after 6s
CI / Remote server (linux musl) (push) Failing after 6m45s
CI / E2E (push) Failing after 18m9s
Language smoke / Language smoke (go) (push) Failing after 7s
CI / Frontend (push) Successful in 26m13s
Language smoke / Language smoke (python) (push) Failing after 4s
Language smoke / Language smoke (rust) (push) Failing after 4s
feat(plugins): commit workflow API for plugins (#1941)
Plugin API 1.3 adds what commit-message generators and before-commit checks need:

- `menu = "commit.message"`: a plugin command, with the plugin's icon, in the toolbar above the commit message of the Commit tool window and the Commit dialog.
- `commit.pending-commit()` (`vcs.read`): what Commit would commit right now, per file its repository, path, status and a `git diff` of only the included files and changed blocks against HEAD (1 MiB in all), plus the message, Amend and a revision. The diff is made by the same selection the commit uses, in a copy of the index, so the index and the working tree stay as they are; unsaved editors of the included files are saved first, as Commit does. Only in trusted projects.
- `commit.set-commit-message(revision, message)` (`vcs.write`): replaces the message only while the draft is still at that revision, so text the user typed meanwhile is never overwritten (`stale`).
- `[[contributes.commitChecks]]` and the optional `commit-checker` export (worlds `plugin-commit-checks` / `commit-checks`): checks listed in Commit Options (on by default, `vcs.commit.disabledPluginChecks` turns them off) and run after the IDE's own; their problems, optionally with a location, stop the commit until Commit Anyway.

The window answers the host through `CommitRequested` / `plugin_answer_commit`, also for remote windows. The Rust SDK gains `host::pending_commit`, `host::set_commit_message`, `openidea_plugin::commit` and their mock; a `commit` test fixture exercises them. All components are rebuilt for the WIT change.

Refs #1650
2026-11-07 16:17:10 +08:00

39 lines
1.5 KiB
Rust

//! Before-commit checks (world `plugin-commit-checks`): declare each under
//! `[[contributes.commitChecks]]` and register the export with
//! `register_plugin!(MyPlugin, commit_checks)`. They run when the user commits
//! (after the IDE's own checks, for the ones turned on in Commit Options);
//! problems stop the commit until the user changes it or chooses Commit Anyway.
//! Needs `vcs.read`.
//!
//! To read or set the message of the commit being prepared from a command, see
//! [`crate::host::pending_commit`] and [`crate::host::set_commit_message`].
use crate::{CommitDraft, Error, Invocation, Location};
/// Something the user should look at before committing.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommitProblem {
/// One sentence, shown after the check's title.
pub message: String,
/// Where it is, opened from the problem; `None` for the commit as a whole.
pub location: Option<Location>,
}
impl CommitProblem {
pub fn new(message: impl Into<String>) -> Self {
Self { message: message.into(), location: None }
}
pub fn at(mut self, location: Location) -> Self {
self.location = Some(location);
self
}
}
/// The plugin's before-commit checks.
pub trait CommitChecks {
/// Runs the declared check `check` on `draft`: no problems lets the commit
/// go on. An error is reported as a problem of the check.
fn check(&mut self, check: &str, draft: &CommitDraft, ctx: &Invocation) -> Result<Vec<CommitProblem>, Error>;
}