Skip to content
lsdocs-protocol API

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

  1. Host -> plugin: request::Initialize; the plugin answers with its Capabilities.
  2. Host -> plugin: notification::Initialized.
  3. Phase requests, as the plugin's capabilities allow: request::Parse, request::ParseTransformEach, then once request::ParseTransformAll, request::RenderTransformEach, request::Render, then once request::RenderTransformAll.
  4. Host -> plugin: request::Shutdown, then notification::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 #

pub fn compatible(a: &str, b: &str) -> bool

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 #

pub trait Request

A request: a message that expects a response.

Implementors

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 #

pub 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 #

pub struct ProgramInfo

Name and version of a program taking part in the protocol.

Trait implementations

field name #

pub name: String

Program name.

field version #

pub version: String

Program version.

struct ProjectInfo #

pub struct ProjectInfo

The project being built: the directory holding lsdocs.toml, its sources and their files.

Trait implementations

field root #

pub root: Option<String>

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: Option<String>

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: Vec<String>

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 #

pub struct SiteInfo

What the rendered site is, e.g. for building links.

Trait implementations

field title #

pub title: Option<String>

Site title.

field base_url #

pub base_url: Option<String>

URL or path prefix the site is served from.

struct InitializeParams #

pub struct InitializeParams

Parameters of request::Initialize.

Trait implementations

field protocol_version #

pub protocol_version: String

Protocol version the host speaks, e.g. "1.0".

field host #

pub host: ProgramInfo

The host.

field project #

pub project: ProjectInfo

The project being built.

field site #

pub site: SiteInfo

The site the project renders to.

field config #

pub config: ConfigInfo

Where the plugin's settings are.

struct ConfigInfo #

pub 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

field dir #

pub dir: String

Absolute path of .config/ (next to lsdocs.toml), whether or not it exists.

field name #

pub name: String

The plugin's name in the project config (name = "..."), so that two instances of a plugin can keep separate settings.

struct InitializeResult #

pub struct InitializeResult

Result of request::Initialize.

Trait implementations

field protocol_version #

pub protocol_version: String

Protocol version the plugin speaks. The host ends the session if it is not compatible with its own.

field plugin #

pub plugin: ProgramInfo

The plugin.

field capabilities #

pub capabilities: Capabilities

What the plugin can do.

field config_files #

pub config_files: Vec<String>

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 #

pub struct Capabilities

What a plugin can do. A phase the plugin does not support is omitted.

Trait implementations

field parse #

pub parse: Option<ParseCapability>

Present if the plugin handles request::Parse.

field transform #

pub transform: Option<TransformCapability>

Present if the plugin handles the transform requests.

field render #

pub render: Option<RenderCapability>

Present if the plugin handles request::Render.

field max_concurrency #

pub max_concurrency: Option<u32>

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: Option<String>

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: Syntax

Directives 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 #

pub 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 #

field directives #

pub directives: Vec<DirectiveSyntax>

Block-level directives.

field roles #

pub roles: Vec<RoleSyntax>

Inline roles.

method is_empty #

pub fn is_empty(&self) -> bool

Whether there are neither directives nor roles.

method merge #

pub fn merge(&mut self, other: &Syntax)

Adds other's directives and roles, keeping the first declaration of a name.

method directive #

pub fn directive(&self, name: &str) -> Option<&DirectiveSyntax>

The directive called name, if declared.

method has_role #

pub fn has_role(&self, name: &str) -> bool

Whether a role called name is declared.

struct DirectiveSyntax #

pub struct DirectiveSyntax

A directive: what it accepts, so parsers can split its parts.

Trait implementations

field name #

pub name: String

The directive's name, in lower case, e.g. "versionadded".

field required_arguments #

pub required_arguments: u32

How many arguments it requires.

field optional_arguments #

pub optional_arguments: u32

How many more arguments it accepts.

field final_argument_whitespace #

pub final_argument_whitespace: bool

Whether the last argument may contain whitespace (it takes the rest of the argument text).

field argument #

pub argument: ArgumentSyntax

How the argument is read.

field options #

pub options: BTreeMap<String, OptionSyntax>

The options it accepts, by name.

field content #

pub content: ContentSyntax

What its content is.

enum ArgumentSyntax #

pub enum ArgumentSyntax

How a directive's argument is read.

Trait implementations

variant Text #

Text

Plain text, kept as written.

variant Inline #

Inline

Inline markup, parsed as well as kept as text.

enum OptionSyntax #

pub enum OptionSyntax

What a directive option takes.

Trait implementations

variant Flag #

Flag

No value.

variant Value #

Value

A value, which may be empty.

variant Required #

Required

A value that must not be empty.

enum ContentSyntax #

pub enum ContentSyntax

What a directive's content is.

Trait implementations

variant None #

None

The directive takes no content.

variant Blocks #

Blocks

Block markup, parsed into the node's children.

variant Text #

Text

Text kept as written (code, a list of document names, ...).

struct RoleSyntax #

pub struct RoleSyntax

A role: inline text with a name, e.g. :kbd:`Ctrl+C`.

Trait implementations

field name #

pub name: String

The role's name, in lower case, e.g. "kbd".

struct ParseCapability #

pub struct ParseCapability

Parsing capability.

Trait implementations

field extensions #

pub extensions: Vec<String>

File extensions handled, without the dot, e.g. ["md", "markdown"].

struct TransformCapability #

pub struct TransformCapability

Transform capability.

Trait implementations

field nodes #

pub nodes: Vec<String>

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: bool

Whether the plugin handles request::ParseTransformEach. If false, only request::RenderTransformEach is sent.

struct RenderCapability #

pub struct RenderCapability

Rendering capability.

Trait implementations

field formats #

pub formats: Vec<String>

Output formats produced, e.g. ["html"].

field all #

pub all: bool

Whether the plugin handles request::RenderTransformAll. With no formats, the plugin is not a renderer and only takes part in that request.

struct ParseParams #

pub struct ParseParams

Parameters of request::Parse.

Trait implementations

field source #

pub source: String

Path of the file relative to the source directory, with / separators. Becomes the document's source.

field text #

pub text: String

The file's text.

field syntax #

pub syntax: Syntax

The directives and roles plugins declared (Capabilities::syntax), for parsers that support syntax extensions. Sent for fragments too.

field fragment #

pub fragment: Option<Fragment>

Present when text is a piece of a document rather than a whole file (sent through request::HostParse).

field origin #

pub origin: Option<Origin>

Where text really comes from, when that is not source.

struct Fragment #

pub 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

field context #

pub context: FragmentContext

What kind of nodes to return.

enum FragmentContext #

pub enum FragmentContext

What kind of nodes a fragment parse returns.

Trait implementations

variant Block #

Block

Block nodes. Headings make sections as in a document; they nest under the section the fragment is inserted into.

variant Inline #

Inline

Inline nodes only. A parser that only makes blocks returns the children of the one paragraph it made.

struct Origin #

pub 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

field source #

pub source: String

The 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: u32

Byte 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 #

pub struct HostParseParams

Parameters of request::HostParse.

Trait implementations

field extension #

pub extension: String

The extension of the files whose parser should parse the text, without the dot, e.g. "md" or "rst".

field parser #

pub parser: Option<String>

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: String

The source path to give the parsed document (and its diagnostics), usually the document the text will be part of.

field text #

pub text: String

The text.

field fragment #

pub fragment: Option<Fragment>

Present to parse a piece of a document; see Fragment.

field origin #

pub origin: Option<Origin>

Where text really comes from; see Origin.

struct ParseResult #

pub struct ParseResult

Result of request::Parse.

Trait implementations

field document #

pub document: Document

The parsed document.

field diagnostics #

pub diagnostics: Vec<Diagnostic>

Problems found while parsing.

field dependencies #

pub dependencies: Vec<String>

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 #

pub struct ParseTransformEachParams

Parameters of request::ParseTransformEach.

Trait implementations

field document #

pub document: Document

The document to collect from.

struct ParseTransformEachResult #

pub struct ParseTransformEachResult

Result of request::ParseTransformEach.

Trait implementations

field data #

pub data: Value

Data gathered from the document, in any shape the plugin likes.

field diagnostics #

pub diagnostics: Vec<Diagnostic>

Problems found.

field dependencies #

pub dependencies: Vec<String>

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 #

pub struct ParseTransformAllParams

Parameters of request::ParseTransformAll.

Trait implementations

field collected #

pub collected: Value

What this plugin collected from every document: a map from each document's source to its collected data.

struct ParseTransformAllResult #

pub struct ParseTransformAllResult

Result of request::ParseTransformAll.

Trait implementations

field documents #

pub documents: Vec<Document>

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: Vec<Diagnostic>

Problems found.

field dependencies #

pub dependencies: Vec<String>

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 #

pub struct RenderTransformEachParams

Parameters of request::RenderTransformEach.

Trait implementations

field document #

pub document: Document

The document to transform.

field collected #

pub collected: Value

What 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 #

pub struct RenderTransformEachResult

Result of request::RenderTransformEach.

Trait implementations

field document #

pub document: Document

The transformed document.

field diagnostics #

pub diagnostics: Vec<Diagnostic>

Problems found.

field dependencies #

pub dependencies: Vec<String>

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 #

pub struct RenderParams

Parameters of request::Render.

Trait implementations

field document #

pub document: Document

The document to render.

field format #

pub format: String

Output format, one of the plugin's RenderCapability::formats.

struct RenderResult #

pub struct RenderResult

Result of request::Render.

Trait implementations

field output #

pub output: Vec<u8>

The rendered output. Sent as MessagePack bin.

field extension #

pub extension: String

File extension for the output, without the dot, e.g. "html".

field diagnostics #

pub diagnostics: Vec<Diagnostic>

Problems found.

field data #

pub data: Value

Data 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 #

pub struct RenderTransformAllParams

Parameters of request::RenderTransformAll.

Trait implementations

field format #

pub format: String

Output format the pages were rendered to.

field pages #

pub pages: Vec<RenderedPage>

Every page rendered, sorted by source path.

struct RenderedPage #

pub struct RenderedPage

A page written by the render phase.

Trait implementations

field source #

pub source: String

The document's source path.

field path #

pub path: String

Where the page was written, relative to the output directory, with / separators, e.g. guide/intro.html.

field metadata #

pub metadata: Metadata

The document's metadata after the transform phase.

field data #

pub data: Value

The data of the page's RenderResult. Omitted when null.

struct RenderTransformAllResult #

pub struct RenderTransformAllResult

Result of request::RenderTransformAll.

Trait implementations

field files #

pub files: Vec<OutputFile>

Extra files to write.

field diagnostics #

pub diagnostics: Vec<Diagnostic>

Problems found.

struct OutputFile #

pub struct OutputFile

A file for the host to write.

Trait implementations

field path #

pub path: String

Path relative to the output directory, with / separators. It may not leave the output directory or replace a rendered page.

field output #

pub output: Vec<u8>

The file's content. Sent as MessagePack bin.

struct Diagnostic #

pub struct Diagnostic

A problem to report to the user, modeled on LSP diagnostics.

Trait implementations

field severity #

pub severity: Severity

How serious the problem is.

field message #

pub message: String

What is wrong.

field source #

pub source: Option<String>

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: Option<Span>

Where in source the problem is.

field code #

pub code: Option<String>

A short identifier for the kind of problem, e.g. "broken-link".

enum Severity #

pub enum Severity

Severity of a Diagnostic.

Trait implementations

variant Error #

Error

The build fails.

variant Warning #

Warning

Probably a mistake, but the build continues.

variant Info #

Info

Worth knowing.

variant Hint #

Hint

A suggestion.

struct CancelParams #

pub struct CancelParams

Parameters of notification::Cancel.

Trait implementations

field id #

pub id: u32

Id of the request to cancel.

struct LogParams #

pub struct LogParams

Parameters of notification::Log.

Trait implementations

field level #

pub level: LogLevel

Log level.

field message #

pub message: String

The message.

enum LogLevel #

pub enum LogLevel

Level of a LogParams message.

Trait implementations

variant Error #

Error

Errors.

variant Warn #

Warn

Warnings.

variant Info #

Info

General information.

variant Debug #

Debug

Debugging detail.

variant Trace #

Trace

Very verbose detail.

struct ProgressParams #

pub struct ProgressParams

Parameters of notification::Progress.

Trait implementations

field message #

pub message: String

What is being worked on.

field percentage #

pub percentage: Option<u8>

Percent complete, 0-100, if known.

struct DiagnosticsParams #

pub struct DiagnosticsParams

Parameters of notification::Diagnostics.

Trait implementations

field diagnostics #

pub diagnostics: Vec<Diagnostic>

The diagnostics.