lsp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: 0BSD Imports: 17 Imported by: 0

Documentation

Overview

Package lsp owns Glippy's bounded JSON-RPC editor protocol surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, input io.Reader, output io.Writer, backend Backend) error

Serve runs one LSP 3.17-compatible stdio session until exit or EOF.

Types

type Analysis

type Analysis struct {
	File        *source.File
	Diagnostics []Diagnostic
	State       any
}

Analysis binds editor findings and backend state to one immutable source.

type Backend

type Backend interface {
	Analyze(context.Context, Document) (Analysis, error)
	CodeActions(context.Context, Document, Analysis, source.Range) ([]CodeAction, error)
	Format(context.Context, Document) ([]byte, error)
}

Backend reuses Glippy's formatter, analyzer, and fix transaction contracts. Implementations must stop promptly when an operation context is canceled. Serve serializes analysis to bound memory, so a backend that ignores cancellation violates this contract and can delay the latest snapshot.

type CodeAction

type CodeAction struct {
	Title                      string
	Kind                       string
	Preferred                  bool
	DiagnosticCode             string
	DiagnosticRange            source.Range
	DiagnosticSeverity         Severity
	DiagnosticMessage          string
	DiagnosticDocumentationURI string
	DiagnosticWithheldFixes    []WithheldFix
	NewText                    []byte
}

CodeAction is one validated whole-document replacement.

type Diagnostic

type Diagnostic struct {
	Range            source.Range
	Severity         Severity
	Code             string
	DocumentationURI string
	Message          string
	Related          []Related
	WithheldFixes    []WithheldFix
}

Diagnostic is one editor-facing finding over physical UTF-8 byte ranges.

type Document

type Document struct {
	URI     string
	Path    string
	Version int
	Text    []byte
}

Document is one exact editor-owned buffer version.

type Related struct {
	Range   source.Range
	Message string
}

Related identifies secondary context in the same exact source version.

type Severity

type Severity int

Severity is an LSP diagnostic severity.

const (
	SeverityError   Severity = 1
	SeverityWarning Severity = 2
)

type WithheldFix

type WithheldFix struct {
	Name    string `json:"name"`
	Reason  string `json:"reason"`
	Message string `json:"message"`
}

WithheldFix is one rule-declared fix that could not be offered safely for the current source.

type WorkspaceAnalysis

type WorkspaceAnalysis struct {
	Document Document
	Analysis Analysis
	Err      error
}

WorkspaceAnalysis binds one backend result to the exact document snapshot that produced it.

type WorkspaceBackend

type WorkspaceBackend interface {
	AnalyzeWorkspace(context.Context, []Document) ([]WorkspaceAnalysis, error)
}

WorkspaceBackend analyzes one immutable snapshot of every editor-owned buffer. Backends that do not need workspace state may implement Backend alone. AnalyzeWorkspace has the same prompt-cancellation requirement as Backend.Analyze.

type WorkspaceFileBackend

type WorkspaceFileBackend interface {
	WorkspaceFilesChanged(context.Context, WorkspaceFileChanges) error
}

WorkspaceFileBackend invalidates persistent workspace state after editor filesystem notifications.

type WorkspaceFileChanges

type WorkspaceFileChanges struct {
	Paths         []string
	InvalidateAll bool
}

WorkspaceFileChanges describes one persistent-workspace invalidation. Paths are absolute, cleaned, sorted, and unique. InvalidateAll is exclusive with Paths and discards every cached workspace result.

Jump to

Keyboard shortcuts

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