lsdocs_plugin_sdk #
Write lsdocs plugins in Rust.
Implement one or more of Parser, Transformer and Renderer,
bundle them into a Plugin, and hand it to main:
use ;
use ;
;
The capabilities sent to the host follow from what the plugin
implements. main speaks the protocol over stdio, or over the pipe in
LSDOCS_PIPE when the host sets it, and returns when the host says
exit or closes the connection.
The host can also run a Plugin in-process, calling Plugin::parse
and friends directly with no serialization.
Submodules
re-export protocol #
pub use lsdocs_protocol as protocol;Re-export of lsdocs_protocol.
re-export doctree #
pub use doctree;Re-export of lsdocs_protocol::doctree.
re-export TRACE_TARGET #
pub use TARGET as TRACE_TARGET;Tracing target for wire logs; enable it at TRACE level to log every protocol message.
Re-export of lsdocs_rpc::trace::TARGET.
type alias BoxFuture #
pub type BoxFuture<'a, T> = ;A boxed, sendable future.
type alias PluginResult #
pub type PluginResult<T> = ;Result of a plugin operation.
struct PluginError #
A plugin operation failed. Any std::error::Error converts into it, so
? works on most errors.
Trait implementations
function new #
Creates an error with the given message.
method message #
The error message.
trait Parser #
Turns source files into documents.
method extensions #
;File extensions handled, without the dot, e.g. ["md"].
method parse #
+ Send;Parses one file.
trait Transformer #
Rewrites documents, optionally using data collected from every document first.
constant READS #
const READS: bool = false;Whether to run the collect pass. If true, Transformer::read is
called for every document before any Transformer::apply, and
apply receives everything collected.
method nodes #
Node kinds this transformer looks at, e.g. ["heading"]. The host
skips documents containing none of them. Empty means every document.
method read #
+ Send Gathers data from one document. Only called if
Transformer::READS is true.
method conclude #
+ Send Generates documents from everything collected (a map from each
document's source to its collected data), once between the two
passes. They join the project: the apply pass, later transformers and
rendering see them like any other document. Only called if
Transformer::READS is true; none by default.
method apply #
+ Send;Transforms one document.
trait Renderer #
Turns documents into output files.
method formats #
;Output formats produced, e.g. ["html"].
constant RENDERS_ALL #
const RENDERS_ALL: bool = false;Whether to handle render/transform/all. If true,
Renderer::render_all is called once after every document is
rendered.
method render #
+ Send;Renders one document.
method render_all #
+ Send Produces output files no single document makes, such as a sitemap,
from the list of rendered pages. Only called if
Renderer::RENDERS_ALL is true.
trait OutputFiles #
Writes output files after every document is rendered, without
rendering documents itself: an inventory of the documented objects,
say. A plugin with output files asks for render/transform/all (its render
capability has all and, without a renderer, no formats).
method files #
+ Send;Produces the files from the list of rendered pages.
struct Plugin #
A plugin: a name, a version, and any of a parser, a transformer and a renderer.
Trait implementations
function new #
A plugin with no capabilities yet.
method parser #
Adds a parser.
method transformer #
Adds a transformer.
method renderer #
Adds a renderer.
method output_files #
Adds output files written after rendering (see OutputFiles).
method max_concurrency #
Limits how many requests the plugin works on at once.
method cacheable #
Lets the host cache the plugin's results: they depend only on each
request, the project settings, the plugin's name and version and its
settings files. See Capabilities::cache.
method cache_key #
Lets the host cache the plugin's results, as Plugin::cacheable,
with a key covering any other input the plugin reads, computed from
the session's setup (e.g. a digest of a template file named in the
settings). Returning None turns caching off for the session.
method syntax #
Declares the directives and roles the plugin handles (see
Capabilities::syntax), computed from the session's setup so
they may depend on the plugin's settings.
method settings #
Reads the plugin's settings at initialize, from the project's
.config/ directory (see config). The settings are
Context::settings and Setup::settings; an error fails
initialize.
method setup #
The setup of the session initialize starts: its params and the
settings the plugin's loader reads.
method info #
The plugin's name and version.
method capabilities_for #
What the plugin can do in the session initialize starts: its
Plugin::capabilities plus its cache key and syntax.
method capabilities #
What the plugin can do, derived from the parts it has (without a
cache key or syntax, which depend on the session; see
Plugin::capabilities_for).
method initialize_result #
The answer to initialize.
method parse #
pub async Parses a file. Fails if the plugin has no parser.
method read #
pub async Runs the collect pass on a document. Fails if the plugin has no transformer.
method conclude #
pub async Generates documents from everything collected. Fails if the plugin has no transformer.
method apply #
pub async Transforms a document. Fails if the plugin has no transformer.
method render #
pub async Renders a document. Fails if the plugin has no renderer.
method render_all #
pub async Produces output files after rendering: the renderer's (if it
renders all), then the OutputFiles'. Fails if the plugin has
neither.
struct Setup #
A session's setup: the initialize params and the settings the
plugin's loader read (see Plugin::settings).
Trait implementations
field params #
pub params: InitializeParamsThe initialize params.
field settings #
pub settings: ValueThe plugin's settings (null if it reads none).
field config_files #
pub config_files: The files they came from, for the host's cache keys.
function with_settings #
A setup with these settings, as if a loader had read them (for tests, and plugins built without a loader).
enum Event #
Something a plugin reports to the host outside of a result.
Trait implementations
variant Log #
LogA log line.
variant Progress #
ProgressProgress on long-running work.
variant Diagnostics #
DiagnosticsDiagnostics.
trait EventSink #
Where a Context sends Events and requests to the host: the RPC
connection, or the host directly for in-process plugins.
method send #
;Delivers one event.
method parse #
Asks the host to parse text with another parser (host/parse).
The default says it cannot.
struct Context #
What a plugin operation can see and do besides its params: the project and site, the plugin's options, and reporting to the host.
Trait implementations
function new #
A context for the session started by initialize.
method project #
The project being built: its directory, source directory and files.
method site #
The site the project renders to: its title and base URL.
method config #
Where the plugin's settings are: the project's .config/ directory
and the plugin's name in the project config.
method settings #
The plugin's settings, as its loader read them (null if none; see
Plugin::settings).
method parse #
pub async Parses text with the project's parser for files with extension
("md", "rst", ...), as part of the document source: e.g. a doc
comment. The parser gets the declared syntax; the result is not
normalized (no generated ids or link targets). See
Context::host_parse to name the parser or parse a fragment.
method host_parse #
pub async Sends a host/parse request: Context::parse with every field,
such as the parser's name, a fragment context and the text's origin.
Parsers may call it while parsing (an included file in another
markup); one that does guards against include cycles itself.
method log #
pub async Sends a log line to the host.
method debug #
pub async Logs at debug level.
method info #
pub async Logs at info level.
method warn #
pub async Logs at warning level.
method progress #
pub async Reports progress.
method diagnostic #
pub async Reports a diagnostic outside of any result.
function relative_path #
A relative URL from the document from to the file to, both given
relative to the source directory with / separators: e.g. from
guide/a.md to index.md is ../index.md.
function main #
Runs plugin until the host is done with it, then returns an exit code.
Use as the body of a plugin's main.
function serve #
pub async Serves plugin over the pipe named in LSDOCS_PIPE if set, otherwise
over stdio. Must run inside a tokio runtime.
function serve_on #
pub async Serves plugin over a given transport until the host sends exit or
closes the connection.