// Package lsp implements a minimal Language Server Protocol server for glint. package lsp import "encoding/json" // Message is a JSON-RPC 2.0 message (request, response, or notification). type Message struct { JSONRPC string `json:"jsonrpc"` ID json.RawMessage `json:"id,omitempty"` Method string `json:"method,omitempty"` Params json.RawMessage `json:"params,omitempty"` Result json.RawMessage `json:"result,omitempty"` Error *RPCError `json:"error,omitempty"` } // RPCError is a JSON-RPC 2.0 error object. type RPCError struct { Code int `json:"code"` Message string `json:"message"` } // InitializeResult is the server's response to the initialize request. type InitializeResult struct { Capabilities ServerCapabilities `json:"capabilities"` ServerInfo *ServerInfo `json:"serverInfo,omitempty"` } // ServerCapabilities advertises what the server supports. type ServerCapabilities struct { // TextDocumentSync: 1 = Full (send entire document on every change). TextDocumentSync int `json:"textDocumentSync"` } // ServerInfo identifies the server to the client. type ServerInfo struct { Name string `json:"name"` Version string `json:"version,omitempty"` } // TextDocumentItem is a text document opened by the client. type TextDocumentItem struct { URI string `json:"uri"` LanguageID string `json:"languageId"` Version int `json:"version"` Text string `json:"text"` } // TextDocumentIdentifier references a text document by URI. type TextDocumentIdentifier struct { URI string `json:"uri"` } // VersionedTextDocumentIdentifier includes a version number. type VersionedTextDocumentIdentifier struct { URI string `json:"uri"` Version int `json:"version"` } // TextDocumentContentChangeEvent is a single content change event. // With Full sync the Text field contains the complete new document text. type TextDocumentContentChangeEvent struct { Text string `json:"text"` } // DidOpenTextDocumentParams is the params for textDocument/didOpen. type DidOpenTextDocumentParams struct { TextDocument TextDocumentItem `json:"textDocument"` } // DidChangeTextDocumentParams is the params for textDocument/didChange. type DidChangeTextDocumentParams struct { TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"` } // DidSaveTextDocumentParams is the params for textDocument/didSave. type DidSaveTextDocumentParams struct { TextDocument TextDocumentIdentifier `json:"textDocument"` Text *string `json:"text,omitempty"` } // DidCloseTextDocumentParams is the params for textDocument/didClose. type DidCloseTextDocumentParams struct { TextDocument TextDocumentIdentifier `json:"textDocument"` } // PublishDiagnosticsParams is the params for textDocument/publishDiagnostics. type PublishDiagnosticsParams struct { URI string `json:"uri"` Diagnostics []Diagnostic `json:"diagnostics"` } // Diagnostic is a lint finding expressed in LSP terms. type Diagnostic struct { Range Range `json:"range"` Severity int `json:"severity"` // 1=Error, 2=Warning, 3=Information, 4=Hint Code string `json:"code,omitempty"` Source string `json:"source,omitempty"` Message string `json:"message"` } // Range is a zero-based line/character range within a text document. type Range struct { Start Position `json:"start"` End Position `json:"end"` } // Position is a zero-based line and character offset. type Position struct { Line int `json:"line"` Character int `json:"character"` }