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.
typesholds 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 fromwit/plugin.wititself, so there is one definition of each, and a plugin hands diffr the same records natively and as a component.Pluginis the one trait every plugin implements:new, which makes it from its options,queries, thenclassifyandmutate, taking and returning exactly those records.hostholds what diffr gives every plugin:git.export!makes a plugin thepluginresource a component exports when the crate is built forwasm32-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:
treerebuilds a side’s list as a tree (tree::sides, which the SDK calls on the way in so a plugin is handedPairingofSourcerather than the flat records) and holds the helpers for reading trees (walk,OtherSide,one_sided,docstring_of, and the rest).applycarries moves out. diffr carries every plugin’s moves out with it, soDraft, which carries a plugin’s moves out on a copy as it makes them, andapply::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::Draftruns 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, thehostinterface ofwit/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 insidescope, with its own implementation ofHost, 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’stypesinterface. 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
Pluginas the component’spluginresource when the crate is built forwasm32: the resource’snewdeserializes the options string intoPlugin::Optionsand callsPlugin::new, and itsclassifyandmutatecall the instance. Built for anything else it exposes its name and constructor asDIFFR_PLUGINfor the host registry.
Traits§
- Plugin
- A diffr plugin: the
pluginresource ofwit/plugin.wit. diffr makes one withPlugin::newwhen it builds its pipeline, before any file, and calls that one instance for every file of the run.