{"modulePath":"github.com/pencode-labs/pencode","version":"v0.1.0-rc.15","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lsp\n\nPackage lsp implements the Language Server Protocol over a full-duplex, cancellable JSON-RPC connection. Unknown methods and extension fields remain available through Call and Notify rather than a closed method enumeration.\n\n## Constants\n\n```go\nconst (\n\tDiagnosticSeverityHint   = 4\n\tDiagnosticTagUnnecessary = 1\n\tDiagnosticTagDeprecated  = 2\n)\n```\n\n```go\nconst (\n\tParseError       = -32700\n\tInvalidRequest   = -32600\n\tMethodNotFound   = -32601\n\tInvalidParams    = -32602\n\tInternalError    = -32603\n\tRequestCancelled = -32800\n\tContentModified  = -32801\n)\n```\n\n```go\nconst MaxMessage = 32 \u003c\u003c 20\n```\n\n## Variables\n\n```go\nvar ErrClosed = errors.New(\"lsp: connection closed\")\n```\n\n```go\nvar SemanticTokenModifiers = []string{\"declaration\", \"definition\", \"readonly\", \"static\", \"deprecated\", \"abstract\", \"async\", \"modification\", \"documentation\", \"defaultLibrary\"}\n```\n\n```go\nvar SemanticTokenTypes = []string{\"namespace\", \"type\", \"class\", \"enum\", \"interface\", \"struct\", \"typeParameter\", \"parameter\", \"variable\", \"property\", \"enumMember\", \"event\", \"function\", \"method\", \"macro\", \"keyword\", \"modifier\", \"comment\", \"string\", \"number\", \"regexp\", \"operator\", \"decorator\"}\n```\n\n## Functions\n\n```go\nfunc ApplySemanticDelta(previous []uint32, edits []SemanticTokensEdit) ([]uint32, error)\n```\n\n```go\nfunc ApplyTextEdits(content string, edits []TextEdit, encoding PositionEncoding) (string, error)\n```\nApplyTextEdits validates the entire edit set before creating a new string. All endpoints are resolved in a single forward scan. Sorting costs O(m log m) for m edits, and scanning/copying costs O(n) for n document bytes.\n\n```go\nfunc OffsetAt[V piecetree.Value](value V, p Position, encoding PositionEncoding) (int, error)\n```\n\n```go\nfunc Request[P, R any](ctx context.Context, c *Conn, method string, params P) (R, error)\n```\nRequest is a typed convenience without a method whitelist.\n\n## Types\n\n```go\ntype Client struct {\n\tCapabilities ServerCapabilities\n\tProcessDone  \u003c-chan struct{}\n\n\t*Conn\n\n\tEncoding PositionEncoding\n\tRoot     URI\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc Connect(ctx context.Context, options Options, conn io.ReadWriteCloser) (*Client, error)\n```\nConnect runs LSP negotiation over an owned remote stdio stream. Process creation, PATH lookup, and reaping belong to pencode-server.\n\n```go\nfunc (c *Client) CloseDocument(ctx context.Context, uri URI) error\n```\n\n```go\nfunc (c *Client) Configure(ctx context.Context, configuration json.RawMessage) error\n```\n\n```go\nfunc (c *Client) DidSave(ctx context.Context, uri URI) error\n```\n\n```go\nfunc (c *Client) DidSaveText[V piecetree.Value](ctx context.Context, uri URI, value V) error\n```\n\n```go\nfunc (c *Client) DocumentVersion(uri URI) (int, bool)\n```\n\n```go\nfunc (c *Client) ProviderOptions(method, capability string) json.RawMessage\n```\nProviderOptions includes dynamically registered trigger characters and resolve support, using the same provider selection as Supports.\n\n```go\nfunc (c *Client) Shutdown(ctx context.Context) error\n```\nShutdown performs shutdown -\u003e response -\u003e exit, flushes the final notification and reaps the process. A deadline also terminates unresponsive servers.\n\n```go\nfunc (c *Client) Supports(method, capability string) bool\n```\n\n```go\nfunc (c *Client) SyncDocument[V piecetree.Value](ctx context.Context, uri URI, language string, value V, version int) error\n```\nSyncDocument sends didOpen once, then full or incremental changes according to the negotiated sync kind. Calls are ordered by the session worker.\n\n```go\nfunc (c *Client) WillSave(ctx context.Context, uri URI) error\n```\n\n```go\ntype CodeAction struct {\n\tTitle    string         `json:\"title\"`\n\tKind     string         `json:\"kind,omitempty\"`\n\tEdit     *WorkspaceEdit `json:\"edit,omitempty\"`\n\tCommand  *Command       `json:\"command,omitempty\"`\n\tDisabled *struct {\n\t\tReason string `json:\"reason\"`\n\t} `json:\"disabled,omitempty\"`\n\tData json.RawMessage `json:\"data,omitempty\"`\n}\n```\n\n```go\ntype Command struct {\n\tTitle     string            `json:\"title\"`\n\tCommand   string            `json:\"command\"`\n\tArguments []json.RawMessage `json:\"arguments,omitempty\"`\n}\n```\n\n```go\ntype CompletionItem struct {\n\tTextEdit            *TextEdit       `json:\"textEdit,omitempty\"`\n\tCommand             *Command        `json:\"command,omitempty\"`\n\tLabel               string          `json:\"label\"`\n\tSortText            string          `json:\"sortText,omitempty\"`\n\tFilterText          string          `json:\"filterText,omitempty\"`\n\tDetail              string          `json:\"detail,omitempty\"`\n\tInsertText          string          `json:\"insertText,omitempty\"`\n\tAdditionalTextEdits []TextEdit      `json:\"additionalTextEdits,omitempty\"`\n\tData                json.RawMessage `json:\"data,omitempty\"`\n\tKind                int             `json:\"kind,omitempty\"`\n\tInsertTextFormat    int             `json:\"insertTextFormat,omitempty\"`\n}\n```\n\n```go\ntype Conn struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewConn(input io.Reader, output io.Writer, closeIO func(), handler Handler) *Conn\n```\nNewConn owns its streams. closeIO must interrupt both reads and writes. Responses are dispatched independently of handlers, so a server request can make a nested client request without deadlocking the reader.\n\n```go\nfunc (c *Conn) BeginCall(ctx context.Context, method string, params any) (PendingCall, error)\n```\nBeginCall enqueues the request before returning. A session can therefore keep didOpen/didChange/requests ordered while waiting for responses concurrently.\n\n```go\nfunc (c *Conn) Call(ctx context.Context, method string, params, result any) error\n```\n\n```go\nfunc (c *Conn) Close()\n```\n\n```go\nfunc (c *Conn) Done() \u003c-chan struct{}\n```\n\n```go\nfunc (c *Conn) Err() error\n```\n\n```go\nfunc (c *Conn) Flush(ctx context.Context) error\n```\nFlush waits until preceding messages have reached the server pipe.\n\n```go\nfunc (c *Conn) Notify(ctx context.Context, method string, params any) error\n```\n\n```go\ntype Diagnostic struct {\n\tSource             string          `json:\"source,omitempty\"`\n\tMessage            string          `json:\"message\"`\n\tCode               json.RawMessage `json:\"code,omitempty\"`\n\tTags               []int           `json:\"tags,omitempty\"`\n\tRelatedInformation json.RawMessage `json:\"relatedInformation,omitempty\"`\n\tData               json.RawMessage `json:\"data,omitempty\"`\n\tRange              Range           `json:\"range\"`\n\tSeverity           int             `json:\"severity,omitempty\"`\n}\n```\n\n```go\ntype Handler func(context.Context, string, json.RawMessage) (any, error)\n```\n\n```go\ntype Location struct {\n\tURI   URI   `json:\"uri\"`\n\tRange Range `json:\"range\"`\n}\n```\n\n```go\ntype LocationLink struct {\n\tTargetURI            URI   `json:\"targetUri\"`\n\tTargetRange          Range `json:\"targetRange\"`\n\tTargetSelectionRange Range `json:\"targetSelectionRange\"`\n}\n```\n\n```go\ntype Message struct {\n\tError   *ResponseError  `json:\"error,omitempty\"`\n\tJSONRPC string          `json:\"jsonrpc\"`\n\tMethod  string          `json:\"method,omitempty\"`\n\tID      json.RawMessage `json:\"id,omitempty\"`\n\tParams  json.RawMessage `json:\"params,omitempty\"`\n\tResult  json.RawMessage `json:\"result,omitempty\"`\n}\n```\nMessage.ID is absent for notifications. Raw JSON preserves string and numeric server IDs, result unions, custom methods and future protocol additions.\n\n```go\ntype Options struct {\n\t// Handler receives server requests and notifications not handled internally.\n\t// Returning MethodNotFound is required for unsupported requests.\n\tHandler Handler\n\t// Capabilities augments the conservative built-in client capabilities.\n\tCapabilities          map[string]any\n\tRoot                  string\n\tInitializationOptions json.RawMessage\n\tConfiguration         json.RawMessage\n}\n```\n\n```go\ntype PendingCall struct {\n\t// contains filtered or unexported fields\n}\n```\nPendingCall owns one response slot. Exactly one Wait must follow BeginCall, including when its context has been cancelled, to release the registration.\n\n```go\nfunc (call PendingCall) Wait(ctx context.Context, result any) error\n```\n\n```go\ntype Position struct {\n\tLine      int `json:\"line\"`\n\tCharacter int `json:\"character\"`\n}\n```\n\n```go\nfunc PositionAt[V piecetree.Value](value V, offset int, encoding PositionEncoding) (Position, error)\n```\n\n```go\ntype PositionEncoding string\n```\nOffsets and positions are checked against rune boundaries. CRLF is one line ending; characters count UTF-16 code units by default, never UTF-8 bytes.\n\n```go\nconst (\n\tUTF8  PositionEncoding = \"utf-8\"\n\tUTF16 PositionEncoding = \"utf-16\"\n\tUTF32 PositionEncoding = \"utf-32\"\n)\n```\n\n```go\ntype PublishDiagnosticsParams struct {\n\tURI         URI          `json:\"uri\"`\n\tVersion     *int         `json:\"version,omitempty\"`\n\tDiagnostics []Diagnostic `json:\"diagnostics\"`\n}\n```\n\n```go\ntype Range struct {\n\tStart Position `json:\"start\"`\n\tEnd   Position `json:\"end\"`\n}\n```\n\n```go\nfunc IncrementalChange(old, next string, encoding PositionEncoding) (Range, string)\n```\nIncrementalChange computes one minimal replacement, without allocating or splitting UTF-8 runes. It also handles changes to line endings.\n\n```go\ntype Reader struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewReader(source io.Reader) *Reader\n```\n\n```go\nfunc (r *Reader) Read() ([]byte, error)\n```\nRead borrows its result until the next Read; framing storage is reused.\n\n```go\ntype Registration struct {\n\tID              string          `json:\"id\"`\n\tMethod          string          `json:\"method\"`\n\tRegisterOptions json.RawMessage `json:\"registerOptions,omitempty\"`\n}\n```\n\n```go\ntype ResponseError struct {\n\tMessage string          `json:\"message\"`\n\tData    json.RawMessage `json:\"data,omitempty\"`\n\tCode    int             `json:\"code\"`\n}\n```\n\n```go\nfunc (e *ResponseError) Error() string\n```\n\n```go\ntype SemanticToken struct {\n\tStart, End      int\n\tType, Modifiers uint32\n}\n```\n\n```go\nfunc DecodeSemanticTokens[V piecetree.Value](dst []SemanticToken, data []uint32, value V, encoding PositionEncoding, types int) ([]SemanticToken, error)\n```\nDecodeSemanticTokens resolves relative positions in one forward document scan. The client does not advertise overlapping or multiline token support.\n\n```go\ntype SemanticTokens struct {\n\tResultID string   `json:\"resultId,omitempty\"`\n\tData     []uint32 `json:\"data\"`\n}\n```\n\n```go\ntype SemanticTokensDelta struct {\n\tResultID string               `json:\"resultId,omitempty\"`\n\tEdits    []SemanticTokensEdit `json:\"edits\"`\n}\n```\n\n```go\ntype SemanticTokensEdit struct {\n\tData        []uint32 `json:\"data,omitempty\"`\n\tStart       int      `json:\"start\"`\n\tDeleteCount int      `json:\"deleteCount\"`\n}\n```\n\n```go\ntype ServerCapabilities map[string]json.RawMessage\n```\n\n```go\nfunc (c ServerCapabilities) Has(key string) bool\n```\n\n```go\ntype TextDocumentEdit struct {\n\tTextDocument VersionedTextDocumentIdentifier `json:\"textDocument\"`\n\tEdits        []TextEdit                      `json:\"edits\"`\n}\n```\n\n```go\ntype TextDocumentIdentifier struct {\n\tURI URI `json:\"uri\"`\n}\n```\n\n```go\ntype TextDocumentPositionParams struct {\n\tTextDocument TextDocumentIdentifier `json:\"textDocument\"`\n\tPosition     Position               `json:\"position\"`\n}\n```\n\n```go\ntype TextEdit struct {\n\tNewText string `json:\"newText\"`\n\tRange   Range  `json:\"range\"`\n}\n```\n\n```go\ntype URI string\n```\n\n```go\nfunc FileURI(path string) URI\n```\n\n```go\nfunc (u URI) Path() (string, error)\n```\n\n```go\ntype VersionedTextDocumentIdentifier struct {\n\tVersion *int `json:\"version\"`\n\tURI     URI  `json:\"uri\"`\n}\n```\n\n```go\ntype WorkspaceEdit struct {\n\tChanges           map[URI][]TextEdit `json:\"changes,omitempty\"`\n\tDocumentChanges   []json.RawMessage  `json:\"documentChanges,omitempty\"`\n\tChangeAnnotations json.RawMessage    `json:\"changeAnnotations,omitempty\"`\n}\n```\n\n```go\ntype WorkspaceFolder struct {\n\tURI  URI    `json:\"uri\"`\n\tName string `json:\"name\"`\n}\n```\n\n```go\ntype Writer struct {\n\tTarget io.Writer\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (w *Writer) Write(data []byte) error\n```\n\n","path":"github.com/pencode-labs/pencode/lsp","name":"lsp","synopsis":"Package lsp implements the Language Server Protocol over a full-duplex, cancellable JSON-RPC connection.","isRedistributable":true}
