Documentation
¶
Index ¶
- func OffloadSlowRequests(handler jsonrpc2.Handler) jsonrpc2.Handler
- type LspHandler
- func (h *LspHandler) Close()
- func (h *LspHandler) ExitCode() int
- func (h *LspHandler) ForgetDocument(uri types.DocumentURI)
- func (h *LspHandler) Formatting(ctx context.Context, reporter core.Reporter, uri types.DocumentURI, ...) ([]types.TextEdit, error)
- func (h *LspHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleExit(_ context.Context, conn *jsonrpc2.Conn, _ *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleInitialize(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (types.InitializeResult, error)
- func (h *LspHandler) HandleShutdown(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentDidChange(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentDidOpen(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentDidSave(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentFormatting(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleTextDocumentRangeFormatting(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) HandleWorkspaceDidChangeConfiguration(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
- func (h *LspHandler) ScheduleLinting(reporter core.Reporter, uri types.DocumentURI, eventType types.EventType)
- func (h *LspHandler) UpdateConfiguration(config *types.Config)
- type LspNotifier
- func (n *LspNotifier) LogMessage(ctx context.Context, typ types.MessageType, message string)
- func (n *LspNotifier) Progress(ctx context.Context, params types.ProgressParams)
- func (n *LspNotifier) PublishDiagnostics(ctx context.Context, params types.PublishDiagnosticsParams)
- func (n *LspNotifier) ReportError(ctx context.Context, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OffloadSlowRequests ¶
OffloadSlowRequests runs the requests that wait on external tools in their own goroutine and keeps everything else on the connection's read loop.
Everything else has to stay inline, because dispatching to goroutines loses the order the client sent messages in, and that order is load-bearing: document sync (didOpen/didChange/didClose) only reconstructs the right text when applied in sequence, initialize has to be seen before the documents it applies to, and shutdown has to be seen before exit. So an inline handler must never block -- work that takes real time belongs on a goroutine of its own, not on a dispatcher that would reorder the message that started it.
Types ¶
type LspHandler ¶
type LspHandler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(langHandler *core.LangHandler) *LspHandler
func (*LspHandler) Close ¶
func (h *LspHandler) Close()
Close abandons all scheduled work and refuses to schedule more. It does not wait for in-flight linters: their contexts are cancelled, which kills the external processes, and their results are discarded.
func (*LspHandler) ExitCode ¶
func (h *LspHandler) ExitCode() int
ExitCode reports the process exit status the client asked for: the spec wants 1 when exit arrives without a preceding shutdown, 0 otherwise. A connection that simply goes away is not an error.
func (*LspHandler) ForgetDocument ¶
func (h *LspHandler) ForgetDocument(uri types.DocumentURI)
ForgetDocument drops everything scheduled for uri. Used when a document is closed: its diagnostics are no longer wanted. A formatting run still going for it finds the document gone and gives up on its own.
func (*LspHandler) Formatting ¶
func (h *LspHandler) Formatting(ctx context.Context, reporter core.Reporter, uri types.DocumentURI, rng *types.Range, opt types.FormattingOptions) ([]types.TextEdit, error)
Formatting runs every configured formatter for uri and returns the edits that bring the document to its formatted state.
Requests run concurrently, including several for the same document, but only the newest request for a document on its current text answers with edits; see core.ErrSuperseded. Saying so with an error keeps the client honest -- answering with an empty edit list would instead claim the document needs no changes.
func (*LspHandler) HandleExit ¶
func (h *LspHandler) HandleExit(_ context.Context, conn *jsonrpc2.Conn, _ *jsonrpc2.Request) (any, error)
HandleExit ends the session. Closing the connection is what actually stops the server: it releases main, which then exits with ExitCode.
func (*LspHandler) HandleInitialize ¶
func (h *LspHandler) HandleInitialize(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (types.InitializeResult, error)
func (*LspHandler) HandleShutdown ¶
func (h *LspHandler) HandleShutdown(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (any, error)
HandleShutdown stops all outstanding work and replies. The connection stays open on purpose: the client is expected to follow up with exit, and closing here would race that notification against our own response.
func (*LspHandler) HandleTextDocumentDidChange ¶
func (*LspHandler) HandleTextDocumentDidClose ¶
func (*LspHandler) HandleTextDocumentDidOpen ¶
func (*LspHandler) HandleTextDocumentDidSave ¶
func (*LspHandler) HandleTextDocumentFormatting ¶
func (*LspHandler) HandleTextDocumentRangeFormatting ¶
func (*LspHandler) HandleWorkspaceDidChangeConfiguration ¶
func (*LspHandler) ScheduleLinting ¶
func (h *LspHandler) ScheduleLinting(reporter core.Reporter, uri types.DocumentURI, eventType types.EventType)
ScheduleLinting queues a lint run for uri. Runs are debounced per document: the run happens once uri has been quiet for the debounce interval, and any run already in flight for uri is cancelled because its results are stale.
The replacement lints for the superseded run's events as well, as long as that run had not started. Otherwise a config that only lints on one kind of event would be lost whenever a different kind arrived inside the debounce window -- a keystroke landing 50ms after a save would drop a save-only linter, and the document would show nothing from it until the next save.
func (*LspHandler) UpdateConfiguration ¶
func (h *LspHandler) UpdateConfiguration(config *types.Config)
type LspNotifier ¶
type LspNotifier struct {
// contains filtered or unexported fields
}
LspNotifier sends server-initiated messages to the client. It implements core.Reporter.
func NewNotifier ¶
func NewNotifier(conn *jsonrpc2.Conn, progress bool) *LspNotifier
func (*LspNotifier) LogMessage ¶
func (n *LspNotifier) LogMessage(ctx context.Context, typ types.MessageType, message string)
func (*LspNotifier) Progress ¶
func (n *LspNotifier) Progress(ctx context.Context, params types.ProgressParams)
func (*LspNotifier) PublishDiagnostics ¶
func (n *LspNotifier) PublishDiagnostics(ctx context.Context, params types.PublishDiagnosticsParams)
func (*LspNotifier) ReportError ¶
func (n *LspNotifier) ReportError(ctx context.Context, err error)