Skip to main content

Crate ocomment_plugin_sdk

Crate ocomment_plugin_sdk 

Source
Expand description

Versioned scanner-plugin boundary.

A scanner plugin finds comments in a syntax ocomment-core has no scanner for and hands their spans back to the host, which puts them through the ordinary policy with transform_spans. This crate is the contract between the two: the PluginComment a guest returns, the API_VERSION it was built against, and the validate_comments check the host runs before it trusts any of it.

A plugin is untrusted code, so nothing it returns is taken on faith. The host validates first and refuses the whole batch on the first fault; it never removes bytes on the strength of a span it has not checked.

use ocomment_core::{ByteSpan, CommentKind};
use ocomment_plugin_sdk::{API_VERSION, PluginComment, ValidationError, validate_comments};

let source = b"a ;; note\n";
let found = [PluginComment {
    span: ByteSpan::new(2, 9),
    kind: CommentKind::Line,
}];
assert!(validate_comments(source.len(), API_VERSION, &found).is_ok());

// A guest built against another revision of the contract is refused
// before its spans are even read.
assert!(matches!(
    validate_comments(source.len(), API_VERSION + 1, &found),
    Err(ValidationError::ApiVersion { .. }),
));

Structs§

PluginComment
One comment a plugin found.

Enums§

ValidationError
Why a plugin’s answer cannot be trusted.

Constants§

API_VERSION
The revision of this contract that host and guest must agree on.

Functions§

validate_comments
Check everything a plugin returned before the host acts on any of it.