Skip to main content

ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder<S> { /* private fields */ }
Expand description

Collects static registrations for one connection before handing them to a Server (ADR 0017). Registration mistakes are recorded and surfaced by build; the builder methods stay chainable.

Implementations§

Source§

impl<S: Send + Sync + 'static> ServerBuilder<S>

Source

pub fn text_document_sync(self, options: TextDocumentSyncOptions) -> Self

Configure the connection’s protocol-owned text-document synchronization. Unspecified open/close and change fields retain the framework defaults; save-related fields are inferred from typed registrations.

Source

pub fn file_provider<P: FileProvider>(self, provider: P) -> Self

Replace the provider used to resolve resources that are not open in the editor. The provider is owned by this connection’s workspace.

Source

pub fn feature<F, H, Fut>(self, spec: F, handler: H) -> Self
where F: FeatureSpec, H: Fn(Arc<S>, Context, <F::Marker as Request>::Params, CancellationToken) -> Fut + SharedHandler<(Arc<S>, Context, <F::Marker as Request>::Params, CancellationToken), Fut> + 'static, Fut: Future<Output = Result<<F::Marker as Request>::Result, LspError>> + TaskSend + 'static,

Register a standard LSP feature and its capability contribution.

spec is a descriptor from lspf::features — for example features::hover() or features::completion(options). It fixes the wire method, the typed parameter and result, and the single capability field the feature advertises. The handler has the same shape as a custom request handler for that method.

Registering two handlers for the same method is a BuildError::DuplicateMethod; two features that disagree on a singular capability field are a BuildError::ConflictingCapability. Both are reported by build.

Source

pub fn request<R, H, Fut>(self, handler: H) -> Self
where R: Request, H: Fn(Arc<S>, Context, R::Params, CancellationToken) -> Fut + SharedHandler<(Arc<S>, Context, R::Params, CancellationToken), Fut> + 'static, Fut: Future<Output = Result<R::Result, LspError>> + TaskSend + 'static,

Register a typed custom request handler.

The marker R implements lspf::types::request::Request (lspf’s re-export of lsp_types::request::Request) and thereby fixes the wire method, parameter type, and result type used by dispatch. The handler receives the shared application state, a Context, the decoded parameters, and a request-scoped CancellationToken.

Custom requests add nothing to ServerCapabilities. Registering two handlers for the same method, or a method the framework reserves, is a BuildError reported by build.

Source

pub fn notification<N, H, Fut>(self, handler: H) -> Self
where N: Notification, H: Fn(Arc<S>, Context, N::Params) -> Fut + SharedHandler<(Arc<S>, Context, N::Params), Fut> + 'static, Fut: Future<Output = ()> + TaskSend + 'static,

Register a typed custom notification handler.

The marker N implements lspf::types::notification::Notification (lspf’s re-export of lsp_types::notification::Notification) and fixes the wire method and parameter type. The handler receives the shared application state, a Context, and the decoded parameters. A notification has no response, so the handler returns () and there is no cancellation token.

Custom notifications add nothing to ServerCapabilities. Malformed parameters are logged and dropped without invoking the handler. Registering two handlers for the same method, or a method the framework reserves, is a BuildError reported by build.

Source

pub fn feature_notification<F, H, Fut>(self, spec: F, handler: H) -> Self
where F: NotificationFeatureSpec, H: Fn(Arc<S>, Context, <F::Marker as Notification>::Params) -> Fut + SharedHandler<(Arc<S>, Context, <F::Marker as Notification>::Params), Fut> + 'static, Fut: Future<Output = ()> + TaskSend + 'static,

Register a standard LSP notification feature and its capability contribution.

spec is a descriptor from lspf::features — for example features::did_create_files(options). It fixes the wire method, the typed parameter, and the capability field the feature advertises. The handler has the same shape as a custom notification handler for that method.

Registering two handlers for the same method is a BuildError::DuplicateMethod; two features that disagree on a singular capability field are a BuildError::ConflictingCapability. Both are reported by build.

Source

pub fn command<Args, Output, H, Fut>( self, name: impl Into<String>, handler: H, ) -> Self
where Args: DeserializeOwned + TaskSend + 'static, Output: Serialize + 'static, H: Fn(Arc<S>, Context, Args, CancellationToken) -> Fut + SharedHandler<(Arc<S>, Context, Args, CancellationToken), Fut> + 'static, Fut: Future<Output = Result<Output, LspError>> + TaskSend + 'static,

Register a typed command dispatched on workspace/executeCommand.

The command is invoked when the editor sends workspace/executeCommand with a matching name; its complete arguments array is decoded into Args (tuple, struct, and Vec types alike), and an absent arguments field decodes as an empty array. The handler’s Output is returned as the command result. The handler receives the shared application state, a Context, the typed arguments, and a request-scoped CancellationToken. Args and Output are bounded by the serialization required to cross the wire.

Each registered name merges into one de-duplicated execute-command capability that preserves registration order (ADR 0022). An empty name, two handlers for the same name, or a command alongside an explicit workspace/executeCommand request handler is a BuildError reported by build.

Source

pub fn configure_initialize<F>(self, callback: F) -> Self
where F: FnOnce(&InitializeParams, &mut InitializeRegistrar<S>) -> Result<(), LspError> + TaskSend + 'static,

Register the sole synchronous initialization-dependent registration callback (ADR 0017).

After a valid initialize request the engine runs callback exactly once against a transactional InitializeRegistrar, passing read-only InitializeParams. The callback may conditionally register features, requests, notifications, and commands; returning Err discards the whole transaction. It performs no I/O and cannot .await.

Supplying configure_initialize more than once is a BuildError::DuplicateConfigureInitialize reported by build.

Source

pub fn on_initialize<H, Fut>(self, hook: H) -> Self
where H: Fn(Arc<S>, Context, InitializeParams, CancellationToken) -> Fut + SharedHandler<(Arc<S>, Context, InitializeParams, CancellationToken), Fut> + 'static, Fut: Future<Output = Result<Option<ServerInfo>, LspError>> + TaskSend + 'static,

Register the on_initialize lifecycle hook (ADR 0018).

The hook runs after the Workspace, Documents, and negotiated position encoding are established and after the Router is frozen, but before the InitializeResult is sent. It may contribute an optional ServerInfo, but it cannot register routes or replace the generated ServerCapabilities. Returning Err fails initialization.

Supplying on_initialize more than once is a BuildError::DuplicateLifecycleHook reported by build.

Source

pub fn on_initialized<H, Fut>(self, hook: H) -> Self
where H: Fn(Arc<S>, Context, InitializedParams) -> Fut + SharedHandler<(Arc<S>, Context, InitializedParams), Fut> + 'static, Fut: Future<Output = ()> + TaskSend + 'static,

Register the on_initialized lifecycle hook (ADR 0024).

The hook runs at most once, and only after a successful initialize transaction: when the client’s initialized notification arrives while the connection is running. It receives the shared application state, a Context, and the typed InitializedParams. A notification has no response, so the hook resolves to (). An initialized notification received before initialize or after shutdown is ignored without consuming the hook, and malformed parameters are dropped.

Supplying on_initialized more than once is a BuildError::DuplicateLifecycleHook reported by build.

Source

pub fn on_shutdown<H, Fut>(self, hook: H) -> Self
where H: Fn(Arc<S>, Context, (), CancellationToken) -> Fut + SharedHandler<(Arc<S>, Context, (), CancellationToken), Fut> + 'static, Fut: Future<Output = Result<(), LspError>> + TaskSend + 'static,

Register the on_shutdown lifecycle hook (ADR 0018).

The hook runs after a successful initialize transaction and before the protocol engine enters its shutting-down state. It receives the shared application state, a live Context, the shutdown request’s unit parameters, and its CancellationToken. Returning Ok(()) permits shutdown; returning LspError sends that error response and leaves the connection running so the client may retry or continue using it.

Supplying on_shutdown more than once is a BuildError::DuplicateLifecycleHook reported by build.

Source

pub fn on_exit<H, Fut>(self, hook: H) -> Self
where H: Fn(Arc<S>, Context) -> Fut + SharedHandler<(Arc<S>, Context), Fut> + 'static, Fut: Future<Output = ()> + TaskSend + 'static,

Register the on_exit lifecycle hook (ADR 0018, ADR 0024).

The hook runs when the peer’s exit notification arrives after a successful initialize transaction, before the protocol engine computes the exit outcome. It receives the shared application state and a Context — the notification-handler shape; exit carries no parameters — and resolves to (), so it cannot override the lifecycle-derived outcome: the reported LSP exit code is still 0 after a successful shutdown and 1 otherwise. An exit received before initialize closes the connection with code 1 without running the hook — no Workspace exists to hand it.

Supplying on_exit more than once is a BuildError::DuplicateLifecycleHook reported by build.

Source

pub fn layer<L>(self, layer: L) -> Self
where L: Layer<S>,

Register a user Layer around normalized user dispatch.

The last registered Layer is outermost among user Layers. Framework panic isolation, tracing, and concurrency limiting remain outside it.

Source

pub fn concurrency_limit(self, limit: usize) -> Self

Set the maximum number of calls executing inside the complete user Layer chain. Zero is rejected by build.

Source

pub fn outbound_warning_threshold(self, threshold: usize) -> Self

Set the outbound queue depth at which the engine warns once per upward crossing. Zero is rejected by build. The queue itself stays unbounded regardless: the threshold only controls when sustained depth produces a warning, never whether a message is sent.

Source

pub fn build(self) -> Result<Server<S>, BuildError>

Validate the complete static registration set and return the Server.

Performs no I/O and does not run configure_initialize; the Router is frozen later, when the engine commits the initialize transaction. Returns the first BuildError recorded during registration, if any.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for ServerBuilder<S>

§

impl<S> !Sync for ServerBuilder<S>

§

impl<S> !UnwindSafe for ServerBuilder<S>

§

impl<S> Freeze for ServerBuilder<S>
where Arc<S>: Freeze, Registrations<S>: Freeze, Option<Box<dyn ConfigureInitializeCallback<S>>>: Freeze, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializeParams, CancellationToken), Pin<Box<dyn TaskFuture<Result<Option<ServerInfo>, LspError>, Output = Result<Option<ServerInfo>, LspError>>>>>>>: Freeze, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializedParams), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Freeze, Option<Box<dyn SharedHandler<(Arc<S>, Context, (), CancellationToken), Pin<Box<dyn TaskFuture<Result<(), LspError>, Output = Result<(), LspError>>>>>>>: Freeze, Option<Box<dyn SharedHandler<(Arc<S>, Context), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Freeze, Vec<Arc<dyn Layer<S>>>: Freeze,

§

impl<S> Send for ServerBuilder<S>
where Arc<S>: Send, Registrations<S>: Send, Option<Box<dyn ConfigureInitializeCallback<S>>>: Send, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializeParams, CancellationToken), Pin<Box<dyn TaskFuture<Result<Option<ServerInfo>, LspError>, Output = Result<Option<ServerInfo>, LspError>>>>>>>: Send, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializedParams), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Send, Option<Box<dyn SharedHandler<(Arc<S>, Context, (), CancellationToken), Pin<Box<dyn TaskFuture<Result<(), LspError>, Output = Result<(), LspError>>>>>>>: Send, Option<Box<dyn SharedHandler<(Arc<S>, Context), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Send, Vec<Arc<dyn Layer<S>>>: Send,

§

impl<S> Unpin for ServerBuilder<S>
where Arc<S>: Unpin, Registrations<S>: Unpin, Option<Box<dyn ConfigureInitializeCallback<S>>>: Unpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializeParams, CancellationToken), Pin<Box<dyn TaskFuture<Result<Option<ServerInfo>, LspError>, Output = Result<Option<ServerInfo>, LspError>>>>>>>: Unpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializedParams), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Unpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, (), CancellationToken), Pin<Box<dyn TaskFuture<Result<(), LspError>, Output = Result<(), LspError>>>>>>>: Unpin, Option<Box<dyn SharedHandler<(Arc<S>, Context), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: Unpin, Vec<Arc<dyn Layer<S>>>: Unpin,

§

impl<S> UnsafeUnpin for ServerBuilder<S>
where Arc<S>: UnsafeUnpin, Registrations<S>: UnsafeUnpin, Option<Box<dyn ConfigureInitializeCallback<S>>>: UnsafeUnpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializeParams, CancellationToken), Pin<Box<dyn TaskFuture<Result<Option<ServerInfo>, LspError>, Output = Result<Option<ServerInfo>, LspError>>>>>>>: UnsafeUnpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, InitializedParams), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: UnsafeUnpin, Option<Box<dyn SharedHandler<(Arc<S>, Context, (), CancellationToken), Pin<Box<dyn TaskFuture<Result<(), LspError>, Output = Result<(), LspError>>>>>>>: UnsafeUnpin, Option<Box<dyn SharedHandler<(Arc<S>, Context), Pin<Box<dyn TaskFuture<(), Output = ()>>>>>>: UnsafeUnpin, Vec<Arc<dyn Layer<S>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more