lsdocs_protocol #
Message and capability types for the lsdocs plugin protocol.
The host and plugins exchange requests and notifications. Each one is a
marker type implementing Request or Notification, which ties the
method name to its parameter and result types; see request and
notification. How messages are framed and sent is up to the rpc
crate; this crate only defines what is inside them.
Lifecycle
- Host -> plugin:
request::Initialize; the plugin answers with itsCapabilities. - Host -> plugin:
notification::Initialized. - Phase requests, as the plugin's capabilities allow:
request::Parse,request::ParseTransformEach, then oncerequest::ParseTransformAll,request::RenderTransformEach,request::Render, then oncerequest::RenderTransformAll. - Host -> plugin:
request::Shutdown, thennotification::Exit.
Plugins may send notification::Log, notification::Progress and
notification::Diagnostics at any time after initialization.
Encoding
Messages are MessagePack. Use msgpack::encode and msgpack::decode,
which write structs as maps (never positional arrays) so that fields can be
added without breaking plugins in other languages. Field names are
snake_case; optional fields are omitted when empty; unknown fields are
ignored.
Submodules
re-export doctree #
pub use lsdocs_doctree as doctree;Re-export of lsdocs_doctree.
constant PROTOCOL_VERSION #
pub const PROTOCOL_VERSION: &str = "1.0-rc.1";Protocol version spoken by this crate: MAJOR.MINOR, with -rc.N for
a release candidate. See compatible and "Versions" in
spec/wire.md.
function compatible #
Whether peers speaking protocol versions a and b can talk: the same
major version, and, if either is a release candidate, the very same
version. Minor versions only add things older peers can ignore.
trait Request #
A request: a message that expects a response.
Implementors
InitializeShutdownParseParseTransformEachParseTransformAllRenderTransformEachRenderHostParseRenderTransformAll
constant METHOD #
const METHOD: &'static str;Method name on the wire.
type alias Params #
type Params: Serialize + DeserializeOwned;Parameters sent with the request.
type alias Result #
type Result: Serialize + DeserializeOwned;Value returned on success.
trait Notification #
A notification: a message with no response.
Implementors
constant METHOD #
const METHOD: &'static str;Method name on the wire.
type alias Params #
type Params: Serialize + DeserializeOwned;Parameters sent with the notification.
struct ProgramInfo #
Name and version of a program taking part in the protocol.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field name #
pub name: StringProgram name.
field version #
pub version: StringProgram version.
struct ProjectInfo #
The project being built: the directory holding lsdocs.toml, its
sources and their files.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field root #
pub root: Absolute path of the project directory (where lsdocs.toml is).
Resolve relative paths from plugin settings against this, not the
process's working directory: builtin plugins run inside the host.
field source_dir #
pub source_dir: Absolute path of the source directory, which document source
paths are relative to (e.g. for parsers that read included files).
field files #
pub files: Every file under the source directory (documents and static assets
alike), relative to it with / separators, sorted. Lets transformers
check links to files that are not documents, such as images.
struct SiteInfo #
What the rendered site is, e.g. for building links.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field title #
pub title: Site title.
field base_url #
pub base_url: URL or path prefix the site is served from.
struct InitializeParams #
Parameters of request::Initialize.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field protocol_version #
pub protocol_version: StringProtocol version the host speaks, e.g. "1.0".
field host #
pub host: ProgramInfoThe host.
field project #
pub project: ProjectInfoThe project being built.
field site #
pub site: SiteInfoThe site the project renders to.
field config #
pub config: ConfigInfoWhere the plugin's settings are.
struct ConfigInfo #
Where a plugin's settings are: the project's .config/ directory, whose
layout is the plugin's business (the recommended one is
<vendor>/<name>/), and the plugin's name in the project config.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field dir #
pub dir: StringAbsolute path of .config/ (next to lsdocs.toml), whether or
not it exists.
field name #
pub name: StringThe plugin's name in the project config (name = "..."), so that two
instances of a plugin can keep separate settings.
struct InitializeResult #
Result of request::Initialize.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field protocol_version #
pub protocol_version: StringProtocol version the plugin speaks. The host ends the session if it
is not compatible with its own.
field plugin #
pub plugin: ProgramInfoThe plugin.
field capabilities #
pub capabilities: CapabilitiesWhat the plugin can do.
field config_files #
pub config_files: The files the plugin read its settings from, relative to
.config/ (or absolute), including ones it looked for and did not
find. The host digests them into the plugin's cache keys, so a
change to one (or creating one) is a change of settings, and
lsdocs serve restarts the plugins when one changes. Other files
the settings name and the plugin reads at startup (a theme
directory's), and directories, may be listed too.
struct Capabilities #
What a plugin can do. A phase the plugin does not support is omitted.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field parse #
pub parse: Present if the plugin handles request::Parse.
field transform #
pub transform: Present if the plugin handles the transform requests.
field render #
pub render: Present if the plugin handles request::Render.
field max_concurrency #
pub max_concurrency: Most requests the plugin can work on at once; omitted means no limit. Python plugins report 1 because of the GIL.
field cache #
pub cache: Present if the plugin's results may be cached: they depend only on the request, the project settings, the plugin's name, version and options, and this key. A plugin that reads anything else (say, a template file its options name) puts a digest of it in the key, so the cache is invalidated when that changes. Omitted means never cache.
field syntax #
pub syntax: SyntaxDirectives and roles the plugin handles. The host passes every
plugin's syntax to parsers (ParseParams::syntax), which turn it
into custom nodes for the plugin to transform.
struct Syntax #
Syntax extensions: directives and roles that plugins give meaning to.
Parsers read them with their format's syntax (in reStructuredText,
.. name:: argument and :name:`text`; in Markdown, MyST's
```{name} argument fences and {name}`text`) and make
format-neutral nodes of them; see "Syntax extensions" in
spec/wire.md for the shape.
Trait implementations #
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field directives #
pub directives: Block-level directives.
field roles #
pub roles: Inline roles.
method is_empty #
Whether there are neither directives nor roles.
method merge #
Adds other's directives and roles, keeping the first declaration
of a name.
method directive #
The directive called name, if declared.
method has_role #
Whether a role called name is declared.
struct DirectiveSyntax #
A directive: what it accepts, so parsers can split its parts.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field name #
pub name: StringThe directive's name, in lower case, e.g. "versionadded".
field required_arguments #
pub required_arguments: u32How many arguments it requires.
field optional_arguments #
pub optional_arguments: u32How many more arguments it accepts.
field final_argument_whitespace #
pub final_argument_whitespace: boolWhether the last argument may contain whitespace (it takes the rest of the argument text).
field argument #
pub argument: ArgumentSyntaxHow the argument is read.
field options #
pub options: The options it accepts, by name.
field content #
pub content: ContentSyntaxWhat its content is.
enum ArgumentSyntax #
How a directive's argument is read.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
variant Text #
TextPlain text, kept as written.
variant Inline #
InlineInline markup, parsed as well as kept as text.
enum OptionSyntax #
What a directive option takes.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
variant Flag #
FlagNo value.
variant Value #
ValueA value, which may be empty.
variant Required #
RequiredA value that must not be empty.
enum ContentSyntax #
What a directive's content is.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
variant None #
NoneThe directive takes no content.
variant Blocks #
BlocksBlock markup, parsed into the node's children.
variant Text #
TextText kept as written (code, a list of document names, ...).
struct RoleSyntax #
A role: inline text with a name, e.g. :kbd:`Ctrl+C`.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field name #
pub name: StringThe role's name, in lower case, e.g. "kbd".
struct ParseCapability #
Parsing capability.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field extensions #
pub extensions: File extensions handled, without the dot, e.g. ["md", "markdown"].
struct TransformCapability #
Transform capability.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field nodes #
pub nodes: Node kinds the transformer looks at (see Node::kind in the doctree
crate, e.g. "heading" or "custom:mermaid"). Empty means the whole
document.
field each #
pub each: boolWhether the plugin handles request::ParseTransformEach. If false,
only request::RenderTransformEach is sent.
struct RenderCapability #
Rendering capability.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field formats #
pub formats: Output formats produced, e.g. ["html"].
field all #
pub all: boolWhether the plugin handles request::RenderTransformAll. With no
formats, the plugin is not a renderer and only takes part in that
request.
struct ParseParams #
Parameters of request::Parse.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field source #
pub source: StringPath of the file relative to the source directory, with /
separators. Becomes the document's source.
field text #
pub text: StringThe file's text.
field syntax #
pub syntax: SyntaxThe directives and roles plugins declared (Capabilities::syntax),
for parsers that support syntax extensions. Sent for fragments too.
field fragment #
pub fragment: Present when text is a piece of a document rather than a whole
file (sent through request::HostParse).
field origin #
pub origin: Where text really comes from, when that is not source.
struct Fragment #
A request to parse a piece of a document. The result's
document.children are the nodes, to be inserted where the text was;
the document's metadata is not read. The host does not normalize a
fragment's ids or link targets: that happens on the document it ends up
in.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
field context #
pub context: FragmentContextWhat kind of nodes to return.
enum FragmentContext #
What kind of nodes a fragment parse returns.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
variant Block #
BlockBlock nodes. Headings make sections as in a document; they nest under the section the fragment is inserted into.
variant Inline #
InlineInline nodes only. A parser that only makes blocks returns the children of the one paragraph it made.
struct Origin #
Where parsed text comes from, for diagnostics: a file other than the document being parsed (an included file, a doc comment's source file), or a place inside it.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
field source #
pub source: StringThe file the text comes from, as a Diagnostic's source names
it: relative to the source directory, or absolute for a file outside
it (a doc comment's source file). Diagnostics about the text name it
as their source.
field offset #
pub offset: u32Byte offset of the text in source. Diagnostic spans are this plus
the span in the text; node spans stay relative to the text.
struct HostParseParams #
Parameters of request::HostParse.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field extension #
pub extension: StringThe extension of the files whose parser should parse the text,
without the dot, e.g. "md" or "rst".
field parser #
pub parser: The name of the parser plugin to use (its name in the project
config); it must parse extension. Omitted: the first parser in
config order that takes extension.
field source #
pub source: StringThe source path to give the parsed document (and its diagnostics), usually the document the text will be part of.
field text #
pub text: StringThe text.
field fragment #
pub fragment: Present to parse a piece of a document; see Fragment.
field origin #
pub origin: Where text really comes from; see Origin.
struct ParseResult #
Result of request::Parse.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: DocumentThe parsed document.
field diagnostics #
pub diagnostics: Problems found while parsing.
field dependencies #
pub dependencies: Files the result depends on besides the request, such as included
files: absolute paths, or paths relative to the project directory
(project.root), with / separators. A cached result is only reused
while they are unchanged (a file that did not exist must still not
exist), and lsdocs serve rebuilds when they change. List files
looked for but missing too.
struct ParseTransformEachParams #
Parameters of request::ParseTransformEach.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: DocumentThe document to collect from.
struct ParseTransformEachResult #
Result of request::ParseTransformEach.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field data #
pub data: ValueData gathered from the document, in any shape the plugin likes.
field diagnostics #
pub diagnostics: Problems found.
field dependencies #
pub dependencies: Files the result depends on besides the request, such as included
files: absolute paths, or paths relative to the project directory
(project.root), with / separators. A cached result is only reused
while they are unchanged (a file that did not exist must still not
exist), and lsdocs serve rebuilds when they change. List files
looked for but missing too.
struct ParseTransformAllParams #
Parameters of request::ParseTransformAll.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field collected #
pub collected: ValueWhat this plugin collected from every document: a map from each
document's source to its collected data.
struct ParseTransformAllResult #
Result of request::ParseTransformAll.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field documents #
pub documents: Documents the plugin generates, with no source file: each one's
source is a path no source file has (it names the output, as a
source path would). The host normalizes them, and they go through
this plugin's apply pass, the transformers after it and rendering
like any other document.
field diagnostics #
pub diagnostics: Problems found.
field dependencies #
pub dependencies: Files the result depends on besides the request, such as included
files: absolute paths, or paths relative to the project directory
(project.root), with / separators. A cached result is only reused
while they are unchanged (a file that did not exist must still not
exist), and lsdocs serve rebuilds when they change. List files
looked for but missing too.
struct RenderTransformEachParams #
Parameters of request::RenderTransformEach.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: DocumentThe document to transform.
field collected #
pub collected: ValueWhat this plugin collected from every document: a map from each
document's source to its collected data. Null if the plugin does
not collect. Over the wire the host leaves it null and sends it once
beforehand with request::ParseTransformAll; the plugin SDK fills
it back in, so handlers always see it here.
struct RenderTransformEachResult #
Result of request::RenderTransformEach.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: DocumentThe transformed document.
field diagnostics #
pub diagnostics: Problems found.
field dependencies #
pub dependencies: Files the result depends on besides the request, such as included
files: absolute paths, or paths relative to the project directory
(project.root), with / separators. A cached result is only reused
while they are unchanged (a file that did not exist must still not
exist), and lsdocs serve rebuilds when they change. List files
looked for but missing too.
struct RenderParams #
Parameters of request::Render.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: DocumentThe document to render.
field format #
pub format: StringOutput format, one of the plugin's RenderCapability::formats.
struct RenderResult #
Result of request::Render.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field output #
pub output: The rendered output. Sent as MessagePack bin.
field extension #
pub extension: StringFile extension for the output, without the dot, e.g. "html".
field diagnostics #
pub diagnostics: Problems found.
field data #
pub data: ValueData about the page, in any shape the plugin likes, handed back to
it in RenderedPage::data at request::RenderTransformAll
(a search index's entry for the page, say). Cached with the
result, so a page that is not rendered again keeps it. Omitted
when null.
struct RenderTransformAllParams #
Parameters of request::RenderTransformAll.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field format #
pub format: StringOutput format the pages were rendered to.
field pages #
pub pages: Every page rendered, sorted by source path.
struct RenderedPage #
A page written by the render phase.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field source #
pub source: StringThe document's source path.
field path #
pub path: StringWhere the page was written, relative to the output directory, with
/ separators, e.g. guide/intro.html.
field metadata #
pub metadata: MetadataThe document's metadata after the transform phase.
field data #
pub data: ValueThe data of the page's RenderResult. Omitted when null.
struct RenderTransformAllResult #
Result of request::RenderTransformAll.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field files #
pub files: Extra files to write.
field diagnostics #
pub diagnostics: Problems found.
struct OutputFile #
A file for the host to write.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field path #
pub path: StringPath relative to the output directory, with / separators. It may
not leave the output directory or replace a rendered page.
field output #
pub output: The file's content. Sent as MessagePack bin.
struct Diagnostic #
A problem to report to the user, modeled on LSP diagnostics.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field severity #
pub severity: SeverityHow serious the problem is.
field message #
pub message: StringWhat is wrong.
field source #
pub source: Source file the problem is in, relative to the source directory, or
absolute for a file outside it (see Origin); / separators.
field span #
pub span: Where in source the problem is.
field code #
pub code: A short identifier for the kind of problem, e.g. "broken-link".
enum Severity #
Severity of a Diagnostic.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqPartialOrdOrdHashSerializeDeserialize<'de>(impl<'de>)
variant Error #
ErrorThe build fails.
variant Warning #
WarningProbably a mistake, but the build continues.
variant Info #
InfoWorth knowing.
variant Hint #
HintA suggestion.
struct CancelParams #
Parameters of notification::Cancel.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field id #
pub id: u32Id of the request to cancel.
struct LogParams #
Parameters of notification::Log.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field level #
pub level: LogLevelLog level.
field message #
pub message: StringThe message.
enum LogLevel #
Level of a LogParams message.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqPartialOrdOrdHashSerializeDeserialize<'de>(impl<'de>)
variant Error #
ErrorErrors.
variant Warn #
WarnWarnings.
variant Info #
InfoGeneral information.
variant Debug #
DebugDebugging detail.
variant Trace #
TraceVery verbose detail.
struct ProgressParams #
Parameters of notification::Progress.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field message #
pub message: StringWhat is being worked on.
field percentage #
pub percentage: Percent complete, 0-100, if known.
struct DiagnosticsParams #
Parameters of notification::Diagnostics.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field diagnostics #
pub diagnostics: The diagnostics.