// Summary: LSP protocol types used by the server (requests, responses, params, capabilities). package lsp import "encoding/json" // JSON-RPC 2.0 structures (minimal) type Request struct { JSONRPC string `json:"jsonrpc"` ID json.RawMessage `json:"id,omitempty"` Method string `json:"method"` Params json.RawMessage `json:"params,omitempty"` } type Response struct { JSONRPC string `json:"jsonrpc"` ID json.RawMessage `json:"id,omitempty"` Result any `json:"result,omitempty"` Error *RespError `json:"error,omitempty"` } type RespError struct { Code int `json:"code"` Message string `json:"message"` } // LSP responses (subset) type InitializeResult struct { Capabilities ServerCapabilities `json:"capabilities"` ServerInfo *ServerInfo `json:"serverInfo,omitempty"` } type ServerInfo struct { Name string `json:"name"` Version string `json:"version,omitempty"` } type ServerCapabilities struct { TextDocumentSync any `json:"textDocumentSync,omitempty"` CompletionProvider *CompletionOptions `json:"completionProvider,omitempty"` // bool | CodeActionOptions CodeActionProvider any `json:"codeActionProvider,omitempty"` } type CompletionOptions struct { ResolveProvider bool `json:"resolveProvider,omitempty"` TriggerCharacters []string `json:"triggerCharacters,omitempty"` } type CompletionList struct { IsIncomplete bool `json:"isIncomplete"` Items []CompletionItem `json:"items"` } type CompletionItem struct { Label string `json:"label"` Kind int `json:"kind,omitempty"` Detail string `json:"detail,omitempty"` InsertText string `json:"insertText,omitempty"` InsertTextFormat int `json:"insertTextFormat,omitempty"` FilterText string `json:"filterText,omitempty"` TextEdit *TextEdit `json:"textEdit,omitempty"` AdditionalTextEdits []TextEdit `json:"additionalTextEdits,omitempty"` SortText string `json:"sortText,omitempty"` Documentation string `json:"documentation,omitempty"` } // Code action options type CodeActionOptions struct { ResolveProvider bool `json:"resolveProvider,omitempty"` } // LSP param types (subset) type TextDocumentItem struct { URI string `json:"uri"` LanguageID string `json:"languageId,omitempty"` Version int `json:"version,omitempty"` Text string `json:"text"` } type VersionedTextDocumentIdentifier struct { URI string `json:"uri"` Version int `json:"version,omitempty"` } type TextDocumentIdentifier struct { URI string `json:"uri"` } type DidOpenTextDocumentParams struct { TextDocument TextDocumentItem `json:"textDocument"` } type TextDocumentContentChangeEvent struct { Range any `json:"range,omitempty"` RangeLength int `json:"rangeLength,omitempty"` Text string `json:"text"` } type DidChangeTextDocumentParams struct { TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"` } type DidCloseTextDocumentParams struct { TextDocument TextDocumentIdentifier `json:"textDocument"` } type Position struct { Line int `json:"line"` Character int `json:"character"` } type CompletionParams struct { TextDocument TextDocumentIdentifier `json:"textDocument"` Position Position `json:"position"` Context any `json:"context,omitempty"` } // Code actions type CodeActionParams struct { TextDocument TextDocumentIdentifier `json:"textDocument"` Range Range `json:"range"` Context json.RawMessage `json:"context,omitempty"` } type WorkspaceEdit struct { Changes map[string][]TextEdit `json:"changes,omitempty"` DocumentChanges []any `json:"documentChanges,omitempty"` } // ApplyWorkspaceEditParams is the client request payload for workspace/applyEdit. type ApplyWorkspaceEditParams struct { Label string `json:"label,omitempty"` Edit WorkspaceEdit `json:"edit"` } type CodeAction struct { Title string `json:"title"` Kind string `json:"kind,omitempty"` Edit *WorkspaceEdit `json:"edit,omitempty"` Data json.RawMessage `json:"data,omitempty"` Command *Command `json:"command,omitempty"` } // Extended workspace edit types (minimal subset) type TextDocumentEdit struct { TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` Edits []TextEdit `json:"edits"` } type CreateFile struct { Kind string `json:"kind"` URI string `json:"uri"` } // Commands type Command struct { Title string `json:"title"` Command string `json:"command"` Arguments []any `json:"arguments,omitempty"` } type ExecuteCommandParams struct { Command string `json:"command"` Arguments []any `json:"arguments,omitempty"` } // Diagnostics (subset needed for code action context) type Diagnostic struct { Range Range `json:"range"` Message string `json:"message"` Severity int `json:"severity,omitempty"` Code interface{} `json:"code,omitempty"` Source string `json:"source,omitempty"` } type CodeActionContext struct { Diagnostics []Diagnostic `json:"diagnostics"` } // Range defines a text range in a document. type Range struct { Start Position `json:"start"` End Position `json:"end"` } // TextEdit represents a textual edit applicable to a document. type TextEdit struct { Range Range `json:"range"` NewText string `json:"newText"` }