pub struct ServerBuilder<S> { /* private fields */ }Expand description
Implementations§
Source§impl<S: Send + Sync + 'static> ServerBuilder<S>
impl<S: Send + Sync + 'static> ServerBuilder<S>
Sourcepub fn text_document_sync(self, options: TextDocumentSyncOptions) -> Self
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.
Sourcepub fn file_provider<P: FileProvider>(self, provider: P) -> Self
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.
Sourcepub fn feature<F, H, Fut>(self, spec: F, handler: H) -> Self
pub fn feature<F, H, Fut>(self, spec: F, handler: H) -> Self
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.
Sourcepub fn request<R, H, Fut>(self, handler: H) -> Self
pub fn request<R, H, Fut>(self, handler: H) -> Self
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.
Sourcepub fn notification<N, H, Fut>(self, handler: H) -> Self
pub fn notification<N, H, Fut>(self, handler: H) -> Self
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.
Sourcepub fn feature_notification<F, H, Fut>(self, spec: F, handler: H) -> Selfwhere
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,
pub fn feature_notification<F, H, Fut>(self, spec: F, handler: H) -> Selfwhere
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.
Sourcepub fn command<Args, Output, H, Fut>(
self,
name: impl Into<String>,
handler: H,
) -> Selfwhere
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,
pub fn command<Args, Output, H, Fut>(
self,
name: impl Into<String>,
handler: H,
) -> Selfwhere
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.
Sourcepub fn configure_initialize<F>(self, callback: F) -> Selfwhere
F: FnOnce(&InitializeParams, &mut InitializeRegistrar<S>) -> Result<(), LspError> + TaskSend + 'static,
pub fn configure_initialize<F>(self, callback: F) -> Selfwhere
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.
Sourcepub fn on_initialize<H, Fut>(self, hook: H) -> Selfwhere
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,
pub fn on_initialize<H, Fut>(self, hook: H) -> Selfwhere
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.
Sourcepub fn on_initialized<H, Fut>(self, hook: H) -> Selfwhere
H: Fn(Arc<S>, Context, InitializedParams) -> Fut + SharedHandler<(Arc<S>, Context, InitializedParams), Fut> + 'static,
Fut: Future<Output = ()> + TaskSend + 'static,
pub fn on_initialized<H, Fut>(self, hook: H) -> Selfwhere
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.
Sourcepub fn on_shutdown<H, Fut>(self, hook: H) -> Self
pub fn on_shutdown<H, Fut>(self, hook: H) -> Self
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.
Sourcepub fn on_exit<H, Fut>(self, hook: H) -> Self
pub fn on_exit<H, Fut>(self, hook: H) -> Self
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.
Sourcepub fn layer<L>(self, layer: L) -> Selfwhere
L: Layer<S>,
pub fn layer<L>(self, layer: L) -> Selfwhere
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.
Sourcepub fn concurrency_limit(self, limit: usize) -> Self
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.
Sourcepub fn outbound_warning_threshold(self, threshold: usize) -> Self
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.
Sourcepub fn build(self) -> Result<Server<S>, BuildError>
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.