Help us shape the future of Go! Take the 2026 Go Developer Survey

editor

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package editor is what an editor extension needs from go-slides, as plain data: a preview of the deck, its problems positioned on lines, and the completions and hovers for directives, kinds and template functions.

It is the logic of the VS Code extension (go-slides/vscode), which runs it compiled to WebAssembly and only translates its results into the editor's types. Every entry point takes a Request: the deck and the workspace files the editor has read. A build reads nothing else (see vfs.Map); the files it wanted and did not get come back in Missing, for the editor to read and ask again.

Index

Constants

View Source
const PreviewCSS = `#go-slides-preview{margin:0 auto}` +
	`#go-slides-preview>svg[data-marpit-svg]{display:block;width:100%;height:auto;margin:0 0 1.5em;` +
	`box-shadow:0 1px 4px rgba(0,0,0,.25)}`

PreviewCSS lays the slides out in the editor's preview: one under the other, full width, with a gap and a shadow.

Variables

This section is empty.

Functions

func Detect

func Detect(src string, marp bool) bool

Detect reports whether a Markdown document is a deck to preview: its front matter sets slides: true, or marp: true when marp is set. The editor leaves marp: true to Marp for VS Code when that extension is installed, so that the two do not both render the same document. An HCL front matter (---hcl) says slides = true or marp = true.

Types

type Diagnostic

type Diagnostic struct {
	// File is the path of the file the problem is in: the deck, or a file
	// it reads (a kinds file, an included fragment, slides.hcl).
	File      string `json:"file"`
	Line      int    `json:"line"`
	Column    int    `json:"column"`
	EndLine   int    `json:"endLine"`
	EndColumn int    `json:"endColumn"`
	// Severity is "error" or "warning".
	Severity string `json:"severity"`
	Message  string `json:"message"`
}

Diagnostic is a problem positioned in a file. Lines are 0-based and columns count UTF-16 code units, as editors (LSP, VS Code) do.

func Diagnose

func Diagnose(err error, path, src string) []Diagnostic

Diagnose positions an error from a build of the deck at path, whose text is src. Each line of the message (errors.Join) is one diagnostic.

type Directive

type Directive struct {
	Name string `json:"name"`
	// Scope is "global" (the whole deck), "local" (this slide and the
	// following ones; "_name" for this slide only) or "deck" (a go-slides
	// front-matter key that is not a Marp directive).
	Scope string `json:"scope"`
	// Doc is Markdown.
	Doc string `json:"doc"`
	// Values are the values the directive takes, when they are a short
	// list.
	Values []string `json:"values,omitempty"`
}

Directive describes a directive for completion and hover.

func Directives

func Directives() []Directive

Directives returns every directive and go-slides front-matter key, in the order Marpit lists them, then kind, then the deck keys.

type Func

type Func struct {
	Name      string `json:"name"`
	Signature string `json:"signature"`
	Doc       string `json:"doc"`
}

Func describes a template function.

func Funcs

func Funcs() []Func

Funcs returns the template functions.

type Hover

type Hover struct {
	// Doc is Markdown.
	Doc string `json:"doc"`
	// The hovered word, on Line from Column to EndColumn (UTF-16).
	Line      int `json:"line"`
	Column    int `json:"column"`
	EndColumn int `json:"endColumn"`
}

Hover is what to show over a position.

func HoverAt

func HoverAt(r Request, line, char int) *Hover

HoverAt returns the hover at a 0-based line and UTF-16 character, nil if there is nothing to say.

type Item

type Item struct {
	Label string `json:"label"`
	// Kind is "directive", "value", "kind", "theme", "function" or
	// "data".
	Kind   string `json:"kind"`
	Detail string `json:"detail,omitempty"`
	// Doc is Markdown.
	Doc string `json:"doc,omitempty"`
	// Insert is the text to insert when it differs from Label.
	Insert string `json:"insert,omitempty"`
}

Item is a completion.

func Complete

func Complete(r Request, line, char int) []Item

Complete returns the completions at a 0-based line and UTF-16 character.

type KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

KV is a directive and its value.

type KindInfo

type KindInfo struct {
	Name    string `json:"name"`
	Extends string `json:"extends,omitempty"`
	// Directives are the resolved directives, in the order they are set.
	Directives []KV `json:"directives"`
}

KindInfo is a kind and the directives it sets, extends resolved.

func KindList

func KindList(k deck.Kinds) ([]KindInfo, error)

KindList lists kinds by name.

type Request

type Request struct {
	// Path is the deck's path; relative paths in the deck resolve from its
	// directory.
	Path string `json:"path"`
	// Source is the deck's text, as the editor holds it (unsaved edits
	// included).
	Source string `json:"source"`
	// Files are the workspace files the editor has read, by path.
	Files map[string]string `json:"files,omitempty"`
	// Dirs are directories the editor has listed, with the names in them;
	// a subdirectory's name ends with "/". A listed file the editor has not
	// read comes back in Missing if the build reads it.
	Dirs map[string][]string `json:"dirs,omitempty"`
	// HTML allows all raw HTML. The editor sets it only when the user asked
	// for it and trusts the workspace; a configuration file's html: true is
	// not enough, since the workspace wrote it.
	HTML bool `json:"html,omitempty"`
	// NoConfig ignores slides.yaml and slides.hcl.
	NoConfig bool `json:"noConfig,omitempty"`
}

Request is a deck and what the editor knows around it.

type Result

type Result struct {
	// HTML is the preview's markup: the theme's style element and the
	// slides, each an inline SVG that scales to the preview's width.
	HTML string `json:"html"`
	// Slides counts the slides.
	Slides int `json:"slides"`
	// Diagnostics are the deck's problems; an error leaves HTML empty.
	Diagnostics []Diagnostic `json:"diagnostics"`
	// Missing are the files the build wanted and the request did not hold.
	Missing []string `json:"missing"`
}

Result is a preview.

func Render

func Render(r Request) Result

Render builds the deck's preview.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL