lsp

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 36 Imported by: 0 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 the language server behind ant lsp: it speaks the Language Server Protocol over a stream, analyzing each open document as the root of its own program.

Index

Constants

View Source
const (
	ItemText          = 1
	ItemMethod        = 2
	ItemFunction      = 3
	ItemConstructor   = 4
	ItemField         = 5
	ItemVariable      = 6
	ItemClass         = 7
	ItemInterface     = 8
	ItemModule        = 9
	ItemProperty      = 10
	ItemUnit          = 11
	ItemValue         = 12
	ItemEnum          = 13
	ItemKeyword       = 14
	ItemSnippet       = 15
	ItemFile          = 17
	ItemReference     = 18
	ItemFolder        = 19
	ItemConstant      = 21
	ItemStruct        = 22
	ItemTypeParameter = 25
)

The completion item kinds the server uses.

View Source
const (
	SymbolFile          = 1
	SymbolModule        = 2
	SymbolNamespace     = 3
	SymbolPackage       = 4
	SymbolClass         = 5
	SymbolMethod        = 6
	SymbolProperty      = 7
	SymbolField         = 8
	SymbolConstructor   = 9
	SymbolEnum          = 10
	SymbolInterface     = 11
	SymbolFunction      = 12
	SymbolVariable      = 13
	SymbolConstant      = 14
	SymbolString        = 15
	SymbolStruct        = 23
	SymbolTypeParameter = 26
)

The symbol kinds the server uses.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, r io.Reader, w io.Writer, logw io.Writer) int

Serve runs a server over r and w until the client sends exit or the stream ends, logging to logw, and returns the exit status.

Types

type ClientCapabilities

type ClientCapabilities struct {
	General struct {
		PositionEncodings []string `json:"positionEncodings"`
	} `json:"general"`
	TextDocument struct {
		Completion struct {
			CompletionItem struct {
				SnippetSupport      bool     `json:"snippetSupport"`
				DocumentationFormat []string `json:"documentationFormat"`
				LabelDetailsSupport bool     `json:"labelDetailsSupport"`
			} `json:"completionItem"`
		} `json:"completion"`
		Hover struct {
			ContentFormat []string `json:"contentFormat"`
		} `json:"hover"`
		SignatureHelp struct {
			SignatureInformation struct {
				DocumentationFormat  []string `json:"documentationFormat"`
				ParameterInformation struct {
					LabelOffsetSupport bool `json:"labelOffsetSupport"`
				} `json:"parameterInformation"`
			} `json:"signatureInformation"`
		} `json:"signatureHelp"`
		DocumentSymbol struct {
			HierarchicalDocumentSymbolSupport bool `json:"hierarchicalDocumentSymbolSupport"`
		} `json:"documentSymbol"`
		Rename struct {
			PrepareSupport bool `json:"prepareSupport"`
		} `json:"rename"`
	} `json:"textDocument"`
	Workspace struct {
		DidChangeWatchedFiles struct {
			DynamicRegistration bool `json:"dynamicRegistration"`
		} `json:"didChangeWatchedFiles"`
	} `json:"workspace"`
}

ClientCapabilities is the part of the client's capabilities the server reads.

type Code added in v0.3.0

type Code struct {
	// contains filtered or unexported fields
}

Code answers the requests of ant code with the server's own analysis, in process: a server whose workspace folder is the root, which counts columns in bytes, and whose open documents are the files as they are on disk, each read once.

func NewCode added in v0.3.0

func NewCode(root string) (*Code, error)

NewCode makes the analysis of ant code for the workspace under root.

func (*Code) Def added in v0.3.0

func (c *Code) Def(loc string) (CodeLoc, string, *CodeError)

Def answers ant code def: where the name at loc is declared, and its signature on one line.

func (*Code) Refs added in v0.3.0

func (c *Code) Refs(loc string, decl bool) (RefsResult, *CodeError)

Refs answers ant code refs: the uses of the declaration loc selects, and the declaration itself with decl.

func (*Code) Rename added in v0.3.0

func (c *Code) Rename(loc, name string, force bool) (RenameResult, *CodeError)

Rename answers ant code rename: the edits that rename the declaration loc selects to name, or why it cannot be renamed. With force, a program with errors or an incomplete search does not stop it, and the result carries the errors and the files skipped.

func (*Code) Symbols added in v0.3.0

func (c *Code) Symbols(paths []string, match string, all bool) ([]CodeSymbol, []string, *CodeError)

Symbols answers ant code symbols: the declarations of the modules under each path, the root when there is none, whose names contain match, without regard to case; with all, the fields of record types and the declarations in functions too. It also returns the files with syntax errors, whose declarations are those it recovered.

func (*Code) Type added in v0.3.0

func (c *Code) Type(loc string) (TypeResult, *CodeError)

Type answers ant code type: what hover shows for the name loc selects, or the type of the innermost expression around a literal or an operator.

type CodeAction

type CodeAction struct {
	Title       string         `json:"title"`
	Kind        string         `json:"kind,omitempty"`
	Diagnostics []Diagnostic   `json:"diagnostics,omitempty"`
	IsPreferred bool           `json:"isPreferred,omitempty"`
	Edit        *WorkspaceEdit `json:"edit,omitempty"`
}

type CodeActionOptions

type CodeActionOptions struct {
	CodeActionKinds []string `json:"codeActionKinds"`
}

type CodeActionParams

type CodeActionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Range        Range                  `json:"range"`
	Context      struct {
		Diagnostics []Diagnostic `json:"diagnostics"`
		Only        []string     `json:"only"`
	} `json:"context"`
}

type CodeDiag added in v0.3.0

type CodeDiag struct {
	Path     string
	Pos, End ast.Pos
	Message  string
	Code     string
}

CodeDiag is an error of a program a rename changes.

type CodeEdit added in v0.3.0

type CodeEdit struct {
	Loc     CodeLoc
	NewText string
}

CodeEdit is one name a rename changes.

type CodeError added in v0.3.0

type CodeError struct {
	Code       string
	Message    string
	Candidates []CodeLoc  // for ambiguous
	Errors     []CodeDiag // for check
	Skipped    []string   // for incomplete
	// contains filtered or unexported fields
}

CodeError is a request ant code could not answer, with its code.

func (*CodeError) Error added in v0.3.0

func (e *CodeError) Error() string

type CodeFile added in v0.3.0

type CodeFile struct {
	Path     string
	Edits    []CodeEdit
	Old, New string
}

CodeFile is a file a rename changes: its edits in source order, the text they were found in, and the text they make.

type CodeLens

type CodeLens struct {
	Range   Range    `json:"range"`
	Command *Command `json:"command,omitempty"`
}

type CodeLensOptions

type CodeLensOptions struct {
	ResolveProvider bool `json:"resolveProvider"`
}

type CodeLensParams

type CodeLensParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type CodeLoc added in v0.3.0

type CodeLoc struct {
	Path       string
	Prelude    bool
	Start, End ast.Pos
	// Line is the source line the location starts on, without its line break.
	Line string
}

CodeLoc is the location of a name or an expression: the file, as the analysis spells its path (absolute, or prelude.Path for the prelude), and the span, in lines and byte columns from 1.

type CodeRef added in v0.3.0

type CodeRef struct {
	Loc   CodeLoc
	Alias string
}

CodeRef is a use refs reports, with the alias it is written through, if any.

type CodeSymbol added in v0.3.0

type CodeSymbol struct {
	Loc       CodeLoc
	Kind      string
	Name      string
	Signature string
	Exported  bool
	Container string
}

CodeSymbol is a declaration symbols lists.

type Command

type Command struct {
	Title     string `json:"title"`
	Command   string `json:"command"`
	Arguments []any  `json:"arguments,omitempty"`
}

type CompletionContext

type CompletionContext struct {
	TriggerKind      int    `json:"triggerKind"` // 1 invoked, 2 trigger character, 3 incomplete
	TriggerCharacter string `json:"triggerCharacter"`
}

type CompletionItem

type CompletionItem struct {
	Label            string                  `json:"label"`
	LabelDetails     *CompletionLabelDetails `json:"labelDetails,omitempty"`
	Kind             int                     `json:"kind,omitempty"`
	Detail           string                  `json:"detail,omitempty"`
	Documentation    *MarkupContent          `json:"documentation,omitempty"`
	SortText         string                  `json:"sortText,omitempty"`
	FilterText       string                  `json:"filterText,omitempty"`
	InsertText       string                  `json:"insertText,omitempty"`
	InsertTextFormat int                     `json:"insertTextFormat,omitempty"` // 1 plain, 2 snippet
	TextEdit         *TextEdit               `json:"textEdit,omitempty"`
	CommitCharacters []string                `json:"commitCharacters,omitempty"`
	// AdditionalTextEdits are made with the item, elsewhere in the document: an import.
	AdditionalTextEdits []TextEdit `json:"additionalTextEdits,omitempty"`
}

func Complete

func Complete(cfg loader.Config, path, text string, off int) []CompletionItem

Complete lists what can be written at byte offset off of text, the input of a session at path, for a REPL: cfg is the session's loader configuration, whose Session scope and Extra names the input is resolved against; the text itself overrides whatever cfg.Sources holds at path. The text is parsed as a script, since the checker types the statements of a script and not those of a session input; the scope still lets a name be declared again. The items are those the language server would offer, unsorted.

type CompletionLabelDetails

type CompletionLabelDetails struct {
	Detail      string `json:"detail,omitempty"`
	Description string `json:"description,omitempty"`
}

type CompletionList

type CompletionList struct {
	IsIncomplete bool             `json:"isIncomplete"`
	Items        []CompletionItem `json:"items"`
}

type CompletionOptions

type CompletionOptions struct {
	TriggerCharacters []string `json:"triggerCharacters"`
	ResolveProvider   bool     `json:"resolveProvider"`
}

type CompletionParams

type CompletionParams struct {
	TextDocumentPositionParams
	Context *CompletionContext `json:"context"`
}

type Diagnostic

type Diagnostic struct {
	Range              Range                          `json:"range"`
	Severity           int                            `json:"severity"` // 1 error, 2 warning, 3 information, 4 hint
	Code               string                         `json:"code,omitempty"`
	Tags               []int                          `json:"tags,omitempty"` // 1 unnecessary
	Source             string                         `json:"source"`
	Message            string                         `json:"message"`
	RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
}

type DiagnosticRelatedInformation

type DiagnosticRelatedInformation struct {
	Location Location `json:"location"`
	Message  string   `json:"message"`
}

type DidChangeTextDocumentParams

type DidChangeTextDocumentParams struct {
	TextDocument   VersionedTextDocumentIdentifier  `json:"textDocument"`
	ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}

type DidChangeWatchedFilesParams

type DidChangeWatchedFilesParams struct {
	Changes []FileEvent `json:"changes"`
}

type DidCloseTextDocumentParams

type DidCloseTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type DidOpenTextDocumentParams

type DidOpenTextDocumentParams struct {
	TextDocument TextDocumentItem `json:"textDocument"`
}

type DidSaveTextDocumentParams

type DidSaveTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type DocumentFormattingParams

type DocumentFormattingParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Options      struct {
		TabSize      int  `json:"tabSize"`
		InsertSpaces bool `json:"insertSpaces"`
	} `json:"options"`
}

type DocumentHighlight

type DocumentHighlight struct {
	Range Range `json:"range"`
	Kind  int   `json:"kind,omitempty"` // 1 text, 2 read, 3 write
}

type DocumentSymbol

type DocumentSymbol struct {
	Name           string           `json:"name"`
	Detail         string           `json:"detail,omitempty"`
	Kind           int              `json:"kind"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

type DocumentSymbolParams

type DocumentSymbolParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type FileEvent

type FileEvent struct {
	URI  string `json:"uri"`
	Type int    `json:"type"` // 1 created, 2 changed, 3 deleted
}

type FoldingRange

type FoldingRange struct {
	StartLine      int    `json:"startLine"`
	StartCharacter *int   `json:"startCharacter,omitempty"`
	EndLine        int    `json:"endLine"`
	EndCharacter   *int   `json:"endCharacter,omitempty"`
	Kind           string `json:"kind,omitempty"` // "comment", "imports", "region"
}

type FoldingRangeParams

type FoldingRangeParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type Hover

type Hover struct {
	Contents MarkupContent `json:"contents"`
	Range    *Range        `json:"range,omitempty"`
}

type InitializeParams

type InitializeParams struct {
	ProcessID        *int               `json:"processId"`
	RootURI          string             `json:"rootUri"`
	Capabilities     ClientCapabilities `json:"capabilities"`
	WorkspaceFolders []WorkspaceFolder  `json:"workspaceFolders"`
	ClientInfo       *struct {
		Name    string `json:"name"`
		Version string `json:"version"`
	} `json:"clientInfo"`
}

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities `json:"capabilities"`
	ServerInfo   ServerInfo         `json:"serverInfo"`
}

type InlayHint

type InlayHint struct {
	Position     Position `json:"position"`
	Label        string   `json:"label"`
	Kind         int      `json:"kind,omitempty"` // 1 type, 2 parameter
	PaddingLeft  bool     `json:"paddingLeft,omitempty"`
	PaddingRight bool     `json:"paddingRight,omitempty"`
}

type InlayHintParams

type InlayHintParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Range        Range                  `json:"range"`
}

type Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

Location is a range in a document.

type LogMessageParams

type LogMessageParams struct {
	Type    int    `json:"type"`
	Message string `json:"message"`
}

type MarkupContent

type MarkupContent struct {
	Kind  string `json:"kind"` // "plaintext" or "markdown"
	Value string `json:"value"`
}

type ParameterInformation

type ParameterInformation struct {
	Label         [2]int         `json:"label"`
	Documentation *MarkupContent `json:"documentation,omitempty"`
}

ParameterInformation names a parameter by the offsets of its label in the signature's label.

type Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

Position is a line and a character in a document, both from 0. The character counts UTF-16 code units, or bytes when the client agreed to utf-8.

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Version     *int         `json:"version,omitempty"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

Range is a span of a document, from Start inclusive to End exclusive.

type ReferenceParams

type ReferenceParams struct {
	TextDocumentPositionParams
	Context struct {
		IncludeDeclaration bool `json:"includeDeclaration"`
	} `json:"context"`
}

type RefsResult added in v0.3.0

type RefsResult struct {
	// Decl is the declaration's location; nil for a namespace of the prelude, which has none.
	Decl    *CodeLoc
	Refs    []CodeRef
	Skipped []string
}

RefsResult is the answer of ant code refs.

type RenameOptions

type RenameOptions struct {
	PrepareProvider bool `json:"prepareProvider"`
}

type RenameParams

type RenameParams struct {
	TextDocumentPositionParams
	NewName string `json:"newName"`
}

type RenameResult added in v0.3.0

type RenameResult struct {
	Files   []CodeFile
	Skipped []string
	// Errors are the errors of the programs the rename changes, which force let through.
	Errors []CodeDiag
}

RenameResult is the answer of ant code rename.

type SelectionRange

type SelectionRange struct {
	Range  Range           `json:"range"`
	Parent *SelectionRange `json:"parent,omitempty"`
}

type SelectionRangeParams

type SelectionRangeParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Positions    []Position             `json:"positions"`
}

type SemanticTokens

type SemanticTokens struct {
	Data []uint32 `json:"data"`
}

type SemanticTokensLegend

type SemanticTokensLegend struct {
	TokenTypes     []string `json:"tokenTypes"`
	TokenModifiers []string `json:"tokenModifiers"`
}

type SemanticTokensOptions

type SemanticTokensOptions struct {
	Legend SemanticTokensLegend `json:"legend"`
	Full   bool                 `json:"full"`
}

type SemanticTokensParams

type SemanticTokensParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is one language server, serving one client.

type ServerCapabilities

type ServerCapabilities struct {
	PositionEncoding           string                  `json:"positionEncoding,omitempty"`
	TextDocumentSync           TextDocumentSyncOptions `json:"textDocumentSync"`
	CompletionProvider         *CompletionOptions      `json:"completionProvider,omitempty"`
	HoverProvider              bool                    `json:"hoverProvider"`
	SignatureHelpProvider      *SignatureHelpOptions   `json:"signatureHelpProvider,omitempty"`
	DefinitionProvider         bool                    `json:"definitionProvider"`
	ReferencesProvider         bool                    `json:"referencesProvider"`
	DocumentHighlightProvider  bool                    `json:"documentHighlightProvider"`
	DocumentSymbolProvider     bool                    `json:"documentSymbolProvider"`
	WorkspaceSymbolProvider    bool                    `json:"workspaceSymbolProvider"`
	CodeActionProvider         *CodeActionOptions      `json:"codeActionProvider,omitempty"`
	DocumentFormattingProvider bool                    `json:"documentFormattingProvider"`
	RenameProvider             *RenameOptions          `json:"renameProvider,omitempty"`
	FoldingRangeProvider       bool                    `json:"foldingRangeProvider"`
	SelectionRangeProvider     bool                    `json:"selectionRangeProvider"`
	SemanticTokensProvider     *SemanticTokensOptions  `json:"semanticTokensProvider,omitempty"`
	InlayHintProvider          bool                    `json:"inlayHintProvider"`
	CodeLensProvider           *CodeLensOptions        `json:"codeLensProvider,omitempty"`
}

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

type ShowMessageParams

type ShowMessageParams struct {
	Type    int    `json:"type"` // 1 error, 2 warning, 3 info, 4 log
	Message string `json:"message"`
}

type SignatureHelp

type SignatureHelp struct {
	Signatures      []SignatureInformation `json:"signatures"`
	ActiveSignature int                    `json:"activeSignature"`
	ActiveParameter int                    `json:"activeParameter"`
}

type SignatureHelpContext

type SignatureHelpContext struct {
	TriggerKind         int            `json:"triggerKind"`
	TriggerCharacter    string         `json:"triggerCharacter"`
	IsRetrigger         bool           `json:"isRetrigger"`
	ActiveSignatureHelp *SignatureHelp `json:"activeSignatureHelp"`
}

type SignatureHelpOptions

type SignatureHelpOptions struct {
	TriggerCharacters   []string `json:"triggerCharacters"`
	RetriggerCharacters []string `json:"retriggerCharacters"`
}

type SignatureHelpParams

type SignatureHelpParams struct {
	TextDocumentPositionParams
	Context *SignatureHelpContext `json:"context"`
}

type SignatureInformation

type SignatureInformation struct {
	Label           string                 `json:"label"`
	Documentation   *MarkupContent         `json:"documentation,omitempty"`
	Parameters      []ParameterInformation `json:"parameters"`
	ActiveParameter *int                   `json:"activeParameter,omitempty"`
}

type SourceParams

type SourceParams struct {
	URI string `json:"uri"`
}

SourceParams is the parameter of the request ant/source, which the client makes for the text of a document the server owns, such as the prelude.

type SymbolInformation

type SymbolInformation struct {
	Name          string   `json:"name"`
	Kind          int      `json:"kind"`
	Location      Location `json:"location"`
	ContainerName string   `json:"containerName,omitempty"`
}

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Range *Range `json:"range"`
	Text  string `json:"text"`
}

TextDocumentContentChangeEvent replaces Range by Text, or the whole document when Range is nil.

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	URI string `json:"uri"`
}

type TextDocumentItem

type TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int    `json:"version"`
	Text       string `json:"text"`
}

type TextDocumentPositionParams

type TextDocumentPositionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

type TextDocumentSyncOptions

type TextDocumentSyncOptions struct {
	OpenClose bool `json:"openClose"`
	Change    int  `json:"change"` // 1 full, 2 incremental
}

type TextEdit

type TextEdit struct {
	Range   Range  `json:"range"`
	NewText string `json:"newText"`
}

TextEdit replaces a range by text.

type TypeResult added in v0.3.0

type TypeResult struct {
	Kind string
	Text string
	Doc  string
	Loc  CodeLoc
}

TypeResult is the answer of ant code type.

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	URI     string `json:"uri"`
	Version int    `json:"version"`
}

type WorkspaceEdit

type WorkspaceEdit struct {
	Changes map[string][]TextEdit `json:"changes"`
}

WorkspaceEdit lists the edits to make in each document.

type WorkspaceFolder

type WorkspaceFolder struct {
	URI  string `json:"uri"`
	Name string `json:"name"`
}

type WorkspaceSymbolParams

type WorkspaceSymbolParams struct {
	Query string `json:"query"`
}

Directories

Path Synopsis
Package htmldata lists the elements and attributes of HTML for completion in markup (section 5, HTML expressions).
Package htmldata lists the elements and attributes of HTML for completion in markup (section 5, HTML expressions).

Jump to

Keyboard shortcuts

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