protocol

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package protocol contains the Language Server Protocol types used by Vacuum.

It intentionally models only Vacuum's supported LSP surface. Unknown JSON fields are ignored by encoding/json, allowing clients to send newer capabilities without coupling Vacuum to the complete protocol schema.

Index

Constants

View Source
const (
	// CodeActionKindEmpty represents an unspecified code-action kind.
	CodeActionKindEmpty = CodeActionKind("")
	// CodeActionKindQuickFix represents a quick-fix code action.
	CodeActionKindQuickFix = CodeActionKind("quickfix")
)
View Source
const (
	// MethodInitialize starts an LSP session.
	MethodInitialize = Method("initialize")
	// MethodInitialized confirms that client initialization is complete.
	MethodInitialized = Method("initialized")
	// MethodShutdown requests an orderly server shutdown.
	MethodShutdown = Method("shutdown")
	// MethodExit terminates the LSP connection.
	MethodExit = Method("exit")
)
View Source
const (
	// DiagnosticSeverityError identifies an error.
	DiagnosticSeverityError = DiagnosticSeverity(1)
	// DiagnosticSeverityWarning identifies a warning.
	DiagnosticSeverityWarning = DiagnosticSeverity(2)
	// DiagnosticSeverityInformation identifies informational feedback.
	DiagnosticSeverityInformation = DiagnosticSeverity(3)
	// DiagnosticSeverityHint identifies a hint.
	DiagnosticSeverityHint = DiagnosticSeverity(4)
)
View Source
const (
	// DiagnosticTagUnnecessary marks unnecessary code.
	DiagnosticTagUnnecessary = DiagnosticTag(1)
	// DiagnosticTagDeprecated marks deprecated code.
	DiagnosticTagDeprecated = DiagnosticTag(2)
)
View Source
const (
	// MethodTextDocumentDidOpen reports an opened document.
	MethodTextDocumentDidOpen = Method("textDocument/didOpen")
	// MethodTextDocumentDidChange reports document content changes.
	MethodTextDocumentDidChange = Method("textDocument/didChange")
	// MethodTextDocumentDidClose reports a closed document.
	MethodTextDocumentDidClose = Method("textDocument/didClose")
	// MethodTextDocumentCompletion requests completions.
	MethodTextDocumentCompletion = Method("textDocument/completion")
	// MethodTextDocumentCodeAction requests code actions.
	MethodTextDocumentCodeAction = Method("textDocument/codeAction")
)
View Source
const (
	// TextDocumentSyncKindNone disables document synchronization.
	TextDocumentSyncKindNone = TextDocumentSyncKind(0)
	// TextDocumentSyncKindFull sends the complete document for each change.
	TextDocumentSyncKindFull = TextDocumentSyncKind(1)
	// TextDocumentSyncKindIncremental sends ranged document changes.
	TextDocumentSyncKindIncremental = TextDocumentSyncKind(2)
)
View Source
const (
	// MethodSetTrace changes server trace verbosity.
	MethodSetTrace = Method("$/setTrace")
	// MethodCancelRequest cancels an active JSON-RPC request.
	MethodCancelRequest = Method("$/cancelRequest")
)
View Source
const (
	// MethodWorkspaceDidChangeConfiguration reports changed client configuration.
	MethodWorkspaceDidChangeConfiguration = Method("workspace/didChangeConfiguration")
	// MethodWorkspaceDidChangeWorkspaceFolders reports workspace-folder changes.
	MethodWorkspaceDidChangeWorkspaceFolders = Method("workspace/didChangeWorkspaceFolders")
	// MethodWorkspaceExecuteCommand requests command execution.
	MethodWorkspaceExecuteCommand = Method("workspace/executeCommand")
	// ServerClientRegisterCapability dynamically registers a client capability.
	ServerClientRegisterCapability = Method("client/registerCapability")
	// ServerWorkspaceConfiguration requests scoped client configuration.
	ServerWorkspaceConfiguration = Method("workspace/configuration")
)
View Source
const ServerTextDocumentPublishDiagnostics = Method("textDocument/publishDiagnostics")

ServerTextDocumentPublishDiagnostics is the diagnostics notification method.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolOrString

type BoolOrString struct {
	Value any
}

BoolOrString represents protocol fields that accept a boolean or string.

func (BoolOrString) MarshalJSON

func (v BoolOrString) MarshalJSON() ([]byte, error)

func (BoolOrString) String

func (v BoolOrString) String() string

String returns the represented boolean or string value.

func (*BoolOrString) UnmarshalJSON

func (v *BoolOrString) UnmarshalJSON(data []byte) error

type CancelParams

type CancelParams struct {
	ID ID `json:"id"`
}

CancelParams identifies the request to cancel.

type ClientCapabilities

type ClientCapabilities struct {
	Workspace *WorkspaceClientCapabilities `json:"workspace,omitempty"`
}

ClientCapabilities contains the capabilities used by Vacuum.

type ClientInfo

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

ClientInfo identifies the connected language client.

type CodeAction

type CodeAction struct {
	Title       string              `json:"title"`
	Kind        *CodeActionKind     `json:"kind,omitempty"`
	Diagnostics []Diagnostic        `json:"diagnostics,omitempty"`
	IsPreferred *bool               `json:"isPreferred,omitempty"`
	Disabled    *CodeActionDisabled `json:"disabled,omitempty"`
	Edit        any                 `json:"edit,omitempty"`
	Command     *Command            `json:"command,omitempty"`
	Data        any                 `json:"data,omitempty"`
}

CodeAction describes an edit or command offered for a document range.

type CodeActionContext

type CodeActionContext struct {
	Diagnostics []Diagnostic     `json:"diagnostics"`
	Only        []CodeActionKind `json:"only,omitempty"`
}

CodeActionContext contains diagnostics and requested action kinds.

type CodeActionDisabled

type CodeActionDisabled struct {
	Reason string `json:"reason"`
}

CodeActionDisabled explains why a code action cannot be applied.

type CodeActionKind

type CodeActionKind = string

CodeActionKind identifies a class of code action.

type CodeActionOptions

type CodeActionOptions struct {
	CodeActionKinds []CodeActionKind `json:"codeActionKinds,omitempty"`
	ResolveProvider *bool            `json:"resolveProvider,omitempty"`
}

CodeActionOptions advertises supported code-action kinds.

type CodeActionParams

type CodeActionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Range        Range                  `json:"range"`
	Context      CodeActionContext      `json:"context"`
}

CodeActionParams identifies the document range requesting actions.

type CodeDescription

type CodeDescription struct {
	HRef URI `json:"href"`
}

CodeDescription links a diagnostic to further documentation.

type Command

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

Command describes a command that a language client can execute.

type CompletionOptions

type CompletionOptions struct{}

CompletionOptions advertises completion support without additional options.

type CompletionParams

type CompletionParams struct {
	TextDocumentPositionParams
}

CompletionParams contains a completion request position.

type ConfigurationItem

type ConfigurationItem struct {
	ScopeURI *DocumentUri `json:"scopeUri,omitempty"`
	Section  *string      `json:"section,omitempty"`
}

ConfigurationItem requests configuration scoped to a URI and section.

type ConfigurationParams

type ConfigurationParams struct {
	Items []ConfigurationItem `json:"items"`
}

ConfigurationParams contains configuration items requested from the client.

type Diagnostic

type Diagnostic struct {
	Range              Range                          `json:"range"`
	Severity           *DiagnosticSeverity            `json:"severity,omitempty"`
	Code               *IntegerOrString               `json:"code,omitempty"`
	CodeDescription    *CodeDescription               `json:"codeDescription,omitempty"`
	Source             *string                        `json:"source,omitempty"`
	Message            string                         `json:"message"`
	Tags               []DiagnosticTag                `json:"tags,omitempty"`
	RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
	Data               any                            `json:"data,omitempty"`
}

Diagnostic is a Vacuum result encoded for a language client.

type DiagnosticRelatedInformation

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

DiagnosticRelatedInformation adds a related location and message.

type DiagnosticSeverity

type DiagnosticSeverity Integer

DiagnosticSeverity is the client-facing severity of a diagnostic.

type DiagnosticTag

type DiagnosticTag Integer

DiagnosticTag identifies additional diagnostic semantics.

type DidChangeConfigurationClientCapabilities

type DidChangeConfigurationClientCapabilities struct {
	DynamicRegistration *bool `json:"dynamicRegistration,omitempty"`
}

DidChangeConfigurationClientCapabilities describes dynamic configuration registration.

type DidChangeConfigurationParams

type DidChangeConfigurationParams struct {
	Settings any `json:"settings"`
}

DidChangeConfigurationParams contains client configuration settings.

type DidChangeTextDocumentParams

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

DidChangeTextDocumentParams contains ordered document changes.

func (*DidChangeTextDocumentParams) UnmarshalJSON

func (p *DidChangeTextDocumentParams) UnmarshalJSON(data []byte) error

type DidChangeWorkspaceFoldersParams

type DidChangeWorkspaceFoldersParams struct {
	Event WorkspaceFoldersChangeEvent `json:"event"`
}

DidChangeWorkspaceFoldersParams contains a workspace-folder change.

type DidCloseTextDocumentParams

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

DidCloseTextDocumentParams identifies a closed document.

type DidOpenTextDocumentParams

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

DidOpenTextDocumentParams contains an opened document.

type DocumentURI

type DocumentURI = string

DocumentURI identifies a text document.

type DocumentUri

type DocumentUri = string // Kept for source compatibility with the former GLSP type.

DocumentUri preserves the former GLSP spelling for source compatibility.

type ExecuteCommandOptions

type ExecuteCommandOptions struct {
	Commands []string `json:"commands"`
}

ExecuteCommandOptions advertises commands handled by Vacuum.

type ExecuteCommandParams

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

ExecuteCommandParams identifies a command and its arguments.

type ID

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

ID is a JSON-RPC request identifier. It preserves its encoded form so responses can echo string and numeric identifiers exactly.

func NewIntegerID

func NewIntegerID(value int64) ID

NewIntegerID creates a numeric JSON-RPC request identifier.

func ParseID

func ParseID(data json.RawMessage) (ID, error)

ParseID creates an identifier from its encoded JSON representation.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero reports whether the identifier is unset.

func (ID) Key

func (id ID) Key() string

Key returns the encoded identifier used for request correlation.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

type InitializeParams

type InitializeParams struct {
	ProcessID             *Integer           `json:"processId"`
	ClientInfo            *ClientInfo        `json:"clientInfo,omitempty"`
	Locale                *string            `json:"locale,omitempty"`
	RootPath              *string            `json:"rootPath,omitempty"`
	RootURI               *DocumentUri       `json:"rootUri"`
	InitializationOptions any                `json:"initializationOptions,omitempty"`
	Capabilities          ClientCapabilities `json:"capabilities"`
	Trace                 *TraceValue        `json:"trace,omitempty"`
	WorkspaceFolders      []WorkspaceFolder  `json:"workspaceFolders,omitempty"`
}

InitializeParams contains client capabilities and workspace initialization state.

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities          `json:"capabilities"`
	ServerInfo   *InitializeResultServerInfo `json:"serverInfo,omitempty"`
}

InitializeResult contains Vacuum's advertised capabilities and identity.

type InitializeResultServerInfo

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

InitializeResultServerInfo identifies the Vacuum language server.

type InitializedParams

type InitializedParams struct{}

InitializedParams is the empty initialized notification payload.

type Integer

type Integer = int32

Integer is the signed integer range used by LSP.

type IntegerOrString

type IntegerOrString struct {
	Value any
}

IntegerOrString represents protocol fields that accept an integer or string.

func (IntegerOrString) MarshalJSON

func (v IntegerOrString) MarshalJSON() ([]byte, error)

func (*IntegerOrString) UnmarshalJSON

func (v *IntegerOrString) UnmarshalJSON(data []byte) error

type Location

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

Location identifies a range within a document.

type Method

type Method = string

Method is an LSP or JSON-RPC method name.

type Position

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

Position identifies a zero-based line and UTF-16 character offset.

func (Position) EndOfLineIn

func (p Position) EndOfLineIn(content string) Position

EndOfLineIn returns the UTF-16 position at the end of the selected line.

func (Position) IndexIn

func (p Position) IndexIn(content string) int

IndexIn converts an LSP UTF-16 position into a byte offset. Invalid line positions retain the former Vacuum behavior and resolve to offset zero.

type PublishDiagnosticsParams

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

PublishDiagnosticsParams publishes the current diagnostics for a document.

type Range

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

Range identifies a start and end position within a document.

func (Range) IndexesIn

func (r Range) IndexesIn(content string) (int, int)

IndexesIn converts an LSP range into byte offsets.

func (Range) ValidIndexesIn

func (r Range) ValidIndexesIn(content string) (int, int, bool)

ValidIndexesIn converts a range into ordered byte offsets and reports whether both lines exist and the start does not follow the end.

type Registration

type Registration struct {
	ID              string `json:"id"`
	Method          string `json:"method"`
	RegisterOptions any    `json:"registerOptions,omitempty"`
}

Registration describes a dynamically registered capability.

type RegistrationParams

type RegistrationParams struct {
	Registrations []Registration `json:"registrations"`
}

RegistrationParams contains dynamic capability registrations.

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync       any                          `json:"textDocumentSync,omitempty"`
	CompletionProvider     *CompletionOptions           `json:"completionProvider,omitempty"`
	CodeActionProvider     any                          `json:"codeActionProvider,omitempty"`
	ExecuteCommandProvider *ExecuteCommandOptions       `json:"executeCommandProvider,omitempty"`
	Workspace              *ServerCapabilitiesWorkspace `json:"workspace,omitempty"`
	Experimental           any                          `json:"experimental,omitempty"`
}

ServerCapabilities contains the server features advertised by Vacuum.

type ServerCapabilitiesWorkspace

type ServerCapabilitiesWorkspace struct {
	WorkspaceFolders *WorkspaceFoldersServerCapabilities `json:"workspaceFolders,omitempty"`
}

ServerCapabilitiesWorkspace contains workspace-specific server features.

type SetTraceParams

type SetTraceParams struct {
	Value TraceValue `json:"value"`
}

SetTraceParams contains a requested trace value.

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Range       *Range    `json:"range"`
	RangeLength *UInteger `json:"rangeLength,omitempty"`
	Text        string    `json:"text"`
}

TextDocumentContentChangeEvent is an incremental ranged content change.

type TextDocumentContentChangeEventWhole

type TextDocumentContentChangeEventWhole struct {
	Text string `json:"text"`
}

TextDocumentContentChangeEventWhole replaces the complete document.

type TextDocumentIdentifier

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

TextDocumentIdentifier identifies a document by URI.

type TextDocumentItem

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

TextDocumentItem contains an opened document and its content.

type TextDocumentPositionParams

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

TextDocumentPositionParams identifies a position within a document.

type TextDocumentSyncKind

type TextDocumentSyncKind Integer

TextDocumentSyncKind identifies how document content is synchronized.

type TraceValue

type TraceValue string

TraceValue identifies LSP trace verbosity.

const (
	// TraceValueOff disables protocol tracing.
	TraceValueOff TraceValue = "off"
	// TraceValueMessage enables message-level tracing.
	TraceValueMessage TraceValue = "message"
	// TraceValueVerbose enables verbose tracing.
	TraceValueVerbose TraceValue = "verbose"
)

func NormalizeTraceValue

func NormalizeTraceValue(value TraceValue) TraceValue

NormalizeTraceValue validates a trace value and accepts the legacy "messages" alias used by older Vacuum clients.

type UInteger

type UInteger = uint32

UInteger is the unsigned integer range used by LSP.

type URI

type URI = string

URI identifies a general protocol resource.

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	TextDocumentIdentifier
	Version Integer `json:"version"`
}

VersionedTextDocumentIdentifier identifies a versioned document.

type WorkspaceClientCapabilities

type WorkspaceClientCapabilities struct {
	DidChangeConfiguration *DidChangeConfigurationClientCapabilities `json:"didChangeConfiguration,omitempty"`
	WorkspaceFolders       *bool                                     `json:"workspaceFolders,omitempty"`
	Configuration          *bool                                     `json:"configuration,omitempty"`
}

WorkspaceClientCapabilities contains workspace features used by Vacuum.

type WorkspaceFolder

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

WorkspaceFolder identifies a named workspace root.

type WorkspaceFoldersChangeEvent

type WorkspaceFoldersChangeEvent struct {
	Added   []WorkspaceFolder `json:"added"`
	Removed []WorkspaceFolder `json:"removed"`
}

WorkspaceFoldersChangeEvent contains added and removed workspace folders.

type WorkspaceFoldersServerCapabilities

type WorkspaceFoldersServerCapabilities struct {
	Supported           *bool         `json:"supported"`
	ChangeNotifications *BoolOrString `json:"changeNotifications,omitempty"`
}

WorkspaceFoldersServerCapabilities advertises workspace-folder support.

Jump to

Keyboard shortcuts

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