lsp

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lsp is mdsh's language server: for the markdown files mdsh runs, it completes fences' attributes and depends= names, explains an attribute on hover and reports mistakes in them as diagnostics. It speaks the Language Server Protocol over a stream, as `mdsh lsp` and mdsh-gui's Neovim pane run it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Help

func Help(text string, line, col int) (spec doc.AttrSpec, from, to int, ok bool)

Help is the attribute at line (from 0) and col (bytes) of text, with where it is in the line, or ok is false.

func HelpText

func HelpText(spec doc.AttrSpec) string

HelpText is spec's help as markdown.

func ListFiles

func ListFiles(dir string) []string

ListFiles lists the regular files under dir, as sorted slash paths relative to it. It leaves out hidden files and folders, node_modules, vendor and .assets folders (res:// paths name what is in those), goes at most maxListDepth folders down and stops at maxListFiles. It is empty if dir doesn't exist.

func Serve

func Serve(r io.Reader, w io.Writer, file string) error

Serve answers LSP requests read from r on w until the client exits or r ends. File, if set, is the document's path for those opened with a URI that isn't a file:// one, for completing paths beside it.

Types

type Diagnostic

type Diagnostic struct {
	Line, From, To int
	Severity       string // error or warning
	Message        string
}

Diagnostic is a problem at a place in a document: Line counts from 0 and the columns are bytes in that line.

func Check

func Check(text string) []Diagnostic

Check checks every fence's attributes in text: unknown or misused ones, depends= names that aren't a block that runs, and a var= bound twice.

type Item

type Item struct {
	Label  string
	Insert string
	Detail string
	Doc    string
	Kind   string // keyword, property, enum, variable, constant, text
}

Item is a completion: Label is shown, Insert replaces the text from the token's start to the cursor.

func Complete

func Complete(text, file string, line, col int) (from int, items []Item)

Complete lists the completions at line (from 0) and col (bytes) of text, the document at file, and the byte column they replace from.

type Names

type Names struct {
	IDs    []string
	Envs   []string
	Assets []string
	Files  []string
	// AssetsDir is the assets folder's name, <doc>.assets.
	AssetsDir string
}

Names are what completion offers besides the attributes: block ids, for conditions, env names, and files for paths: those in the document's assets folder, for res:// paths, and those beside the document.

func NamesFor

func NamesFor(text, file string) Names

NamesFor lists the names in text, the document at file. Without a file there are no files to offer.

type Problem

type Problem struct {
	From     int
	To       int
	Severity string // error or warning
	Message  string
}

Problem is something wrong in a fence's info string. From and To are byte offsets in the info string.

func CheckInfo

func CheckInfo(info string) []Problem

CheckInfo checks the attributes in a fence's info string, such as sh {#build timeout=5m}, against doc.BlockAttrs.

type SourceBlock

type SourceBlock struct {
	// Line is the line its opening fence is on, from 1.
	Line int
	ID   string
	// Runs says whether depends= can name it: an input never runs.
	Runs bool
	// Env is its env=, if any.
	Env string
}

SourceBlock is a block in a document's text, for completing and checking depends=.

func SourceBlocks

func SourceBlocks(text string) []SourceBlock

SourceBlocks lists the blocks in text, in order, leaving out includes and tapes, which have no name. It is nil if text doesn't parse.

Jump to

Keyboard shortcuts

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