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§
- Plugin
Comment - One comment a plugin found.
Enums§
- Validation
Error - 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.