Crate async_lsp

Source
Expand description

Asynchronous Language Server Protocol (LSP) framework based on tower.

See project README for a general overview.

This project is centered at a core service trait LspService for either Language Servers or Language Clients. The main loop driver MainLoop executes the service. The additional features, called middleware, are pluggable can be layered using the tower_layer abstraction. This crate defines several common middlewares for various mandatory or optional LSP functionalities, see their documentations for details.

Users are free to select and layer middlewares to run a Language Server or Language Client. They can also implement their own middlewares for like timeout, metering, request transformation and etc.

§Usages

There are two main ways to define a Router root service: one is via its builder API, and the other is to construct via implementing the omnitrait LanguageServer or LanguageClient for a state struct. The former is more flexible, while the latter has a more similar API as tower-lsp.

The examples for both builder-API and omnitrait, cross Language Server and Language Client, can be seen under examples directory.

§Cargo features

  • client-monitor: Client process monitor middleware client_monitor. Enabled by default.
  • omni-trait: Mega traits of all standard requests and notifications, namely LanguageServer and LanguageClient. Enabled by default.
  • stdio: Utilities to deal with pipe-like stdin/stdout communication channel for Language Servers. Enabled by default.
  • tracing: Integration with crate tracing and the tracing middleware. Enabled by default.
  • forward: Impl LspService for {Client,Server}Socket. This collides some method names but allows easy service forwarding. See examples/inspector.rs for a possible use case. Disabled by default.
  • tokio: Enable compatible methods for tokio runtime. Disabled by default.

Re-exports§

pub use lsp_types;

Modules§

client_monitorclient-monitor
Stop the main loop when the Language Client process aborted unexpectedly.
concurrency
Incoming request multiplexing limits and cancellation.
panic
Catch panics of underlying handlers and turn them into error responses.
router
Dispatch requests and notifications to individual handlers.
server
Language Server lifecycle.
stdiostdio and Unix
Utilities to deal with stdin/stdout communication channel for Language Servers.
tracingtracing
Attach tracing::Spans over underlying handlers.

Structs§

AnyEvent
A dynamic runtime event.
AnyNotification
A dynamic runtime LSP notification.
AnyRequest
A dynamic runtime LSP request.
ClientSocket
The socket for Language Server to communicate with the Language Client peer.
ErrorCode
A JSON-RPC error code.
MainLoop
Service main loop driver for either Language Servers or Language Clients.
ResponseError
The error object in case a request fails.
ServerSocket
The socket for Language Client to communicate with the Language Server peer.

Enums§

Error
Possible errors.

Traits§

LanguageClientomni-trait
The omnitrait defining all standard LSP requests and notifications supported by lsp_types for a Language Client.
LanguageServeromni-trait
The omnitrait defining all standard LSP requests and notifications supported by lsp_types for a Language Server.
LspService
The core service abstraction, representing either a Language Server or Language Client.

Type Aliases§

RequestId
The identifier of requests and responses.
Result
A convenient type alias for Result with E = crate::Error.