Skip to main content

Crate diffr_plugin_sdk

Crate diffr_plugin_sdk 

Source
Expand description

The diffr plugin contract in Rust. wit/plugin.wit in the diffr repository is the contract; this crate is its one Rust form, shared by every plugin whether diffr compiles it in or runs it as a WASM component.

  • types holds the contract’s records: the file entry, each side’s flat preorder region list with parent ids and text, and the moves. They are generated from wit/plugin.wit itself, so there is one definition of each, and a plugin hands diffr the same records natively and as a component.
  • Plugin is the one trait every plugin implements: new, which makes it from its options, queries, then classify and mutate, taking and returning exactly those records.
  • host holds what diffr gives every plugin: git.
  • export! makes a plugin the plugin resource a component exports when the crate is built for wasm32-wasip2, and otherwise exposes its native registration for the host to collect. The same source builds both ways.

Plugins reason about regions with the same code:

  • tree rebuilds a side’s list as a tree (tree::sides, which the SDK calls on the way in so a plugin is handed Pairing of Source rather than the flat records) and holds the helpers for reading trees (walk, OtherSide, one_sided, docstring_of, and the rest).
  • apply carries moves out. diffr carries every plugin’s moves out with it, so Draft, which carries a plugin’s moves out on a copy as it makes them, and apply::Fresh, which predicts fresh ids, give a plugin exactly the ids diffr will.

Re-exports§

pub use draft::Draft;
pub use tree::before_and_after_ids;
pub use tree::docstring_of;
pub use tree::has_tag;
pub use tree::is_fold;
pub use tree::line_count;
pub use tree::one_sided;
pub use tree::path_to;
pub use tree::siblings_of;
pub use tree::sides_with_other_ids;
pub use tree::walk;
pub use tree::walk_mut;
pub use tree::Node;
pub use tree::OtherSide;
pub use tree::Pairing;
pub use tree::Region;
pub use tree::Source;
pub use types::Annotation;
pub use types::FileEntry;
pub use types::FileRef;
pub use types::FileSides;
pub use types::FileStatus;
pub use types::Move;
pub use types::Position;
pub use types::QuerySource;
pub use types::Range;
pub use types::Side;
pub use types::Span;
pub use types::Visibility;
pub use types::ROOT;
pub use anyhow;

Modules§

apply
Carry out moves, in order. diffr carries every plugin’s moves out with this applier, and crate::Draft runs the same code on a copy, so a plugin predicts exactly the trees and ids its moves leave.
draft
A plugin’s moves, carried out on a copy of the region trees as the plugin makes them. The copy lets a plugin name what its own moves create (the piece a cut leaves, the fold a join adds) with the ids the applier will give them, since both hand out ids the same way.
host
What diffr gives every plugin: git, the host interface of wit/plugin.wit. A plugin calls it the same way wherever it runs. In a component it calls the import. Natively, diffr runs each call of a plugin inside scope, with its own implementation of Host, and the function calls that.
native
Native registrations contributed by linked plugin crates.
tree
Region trees: each side’s flat preorder list rebuilt as a tree, the records rebuilt from a tree, and the helpers plugins read trees with.
types
The records of wit/plugin.wit’s types interface. They are generated from the WIT itself by [crate::bindings], so the contract has one definition of each record and nothing to keep in step: a plugin receives and returns exactly these, natively and in a component.

Macros§

export
Export a Plugin as the component’s plugin resource when the crate is built for wasm32: the resource’s new deserializes the options string into Plugin::Options and calls Plugin::new, and its classify and mutate call the instance. Built for anything else it exposes its name and constructor as DIFFR_PLUGIN for the host registry.

Traits§

Plugin
A diffr plugin: the plugin resource of wit/plugin.wit. diffr makes one with Plugin::new when it builds its pipeline, before any file, and calls that one instance for every file of the run.