server

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Debouncer added in v0.11.0

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

func NewDebouncer added in v0.11.0

func NewDebouncer(delay time.Duration) *Debouncer

NewDebouncer returns a Debouncer with the given idle window. A typical value for LSP diagnostics is 150-250ms; long enough that a burst of typing doesn't publish per keystroke, short enough that the user sees errors when they pause.

func (*Debouncer) Stop added in v0.11.0

func (d *Debouncer) Stop()

Stop cancels all pending timers. Idempotent; after Stop, subsequent Trigger calls are no-ops.

func (*Debouncer) Trigger added in v0.11.0

func (d *Debouncer) Trigger(key string, fn func())

Trigger schedules `fn` to run after the configured delay. If another Trigger lands on the same key first, the existing timer is stopped and the new fn replaces it - the most recent fn wins. This matters because the publish closure usually wants to grab the latest snapshot at fire time, not the one at trigger time, so it's fine that earlier fns are dropped.

A zero delay short-circuits to a synchronous call: fn runs inline on the caller's goroutine. Useful in tests that want deterministic publish behavior without racing a goroutine scheduler.

If the Debouncer has been Stopped, Trigger is a no-op.

Each pending timer is tracked by a generation counter so the "fired-but-running" race can be detected: a callback whose timer has been superseded by a later Trigger must not delete the new timer's map entry on its way out.

type Mux

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

func NewMux

func NewMux(r io.Reader, w io.Writer) *Mux

func (*Mux) AddNotificationHandler

func (m *Mux) AddNotificationHandler(method string, handler NotificationHandler)

func (*Mux) AddRequestHandler

func (m *Mux) AddRequestHandler(method string, handler RequestHandler)

func (*Mux) Init

func (m *Mux) Init() (err error)

func (*Mux) Notify

func (m *Mux) Notify(method string, params any) (err error)

func (*Mux) Run

func (m *Mux) Run() (err error)

type NotificationHandler

type NotificationHandler func(ctx context.Context, params json.RawMessage) (err error)

NotificationHandler handles a JSON-RPC notification. Notifications have no response, so the only return value is an error for logging. The context carries cancellation derived from the server's session context - if the session shuts down, in-flight notifications get cancelled too.

type RequestHandler

type RequestHandler func(ctx context.Context, params json.RawMessage) (result any, err error)

RequestHandler handles a JSON-RPC request. The context carries cancellation that the client can flip via $/cancelRequest. Long- running handlers should check ctx.Err() at sensible checkpoints and bail out with a partial result (or the context's error) rather than spending budget on work the client no longer wants.

type Server

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

func NewServer

func NewServer(r io.Reader, w io.Writer) *Server

NewServer creates a server using the default diagnostics debounce delay. Tests that need synchronous publish should use NewServerWithDebounce(r, w, 0) instead.

func NewServerWithDebounce added in v0.11.0

func NewServerWithDebounce(r io.Reader, w io.Writer, delay time.Duration) *Server

NewServerWithDebounce lets tests override the publish-diagnostics debounce delay. A zero delay makes Trigger synchronous, which keeps the snapshot-test harness deterministic without forcing it to sleep for arbitrary windows.

func (*Server) Run

func (s *Server) Run() (err error)

Jump to

Keyboard shortcuts

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