lsdocs_plugin_sdk::fragment #
Fragments: text parsed as a piece of a document (see "Fragments" in
spec/wire.md).
A parser answering a request with a Fragment calls finish on
its result. A plugin that asks for one (Context::host_parse) and
inserts the nodes into its own document fixes their spans up with
shift_spans (the text is a contiguous slice of its source) or
pin_spans (it is not, e.g. it was de-indented), and renumbers its
section titles with nest_sections.
function finish #
Makes a parser's result for params what a fragment request asks
for. Without a fragment or origin, returns it unchanged.
- An inline fragment that parsed to one paragraph becomes that paragraph's children. (Anything else is left as blocks.)
- With an
origin, diagnostics about the text (whosesourceis the request'ssource, or none) nameorigin.source, and their spans are shifted byorigin.offset. Node spans stay relative to the text.
function shift_spans #
Adds offset to every span in nodes, recursively: for nodes parsed
from text found at offset in the source they are inserted into.
function pin_spans #
Sets every span in nodes to span, recursively: for nodes parsed
from text that is not a slice of the source they are inserted into
(such as an included file), which all point at the place that brought
the text in. Nodes without a span keep none.
function nest_sections #
Renumbers the section titles in nodes, recursively, for nodes
inserted under a section whose title is at level enclosing (0 at the
document's top level): the fragment's highest section title becomes
level enclosing + 1, the others keep their distance from it, and none
goes past 6. A fragment's parser numbers its titles as in a document of
its own, from 1. Headings that are not section titles keep their level.