mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-30 03:27:07 +00:00
[ty] Remove ConnectionInitializer (#19353)
## Summary This PR removes the `ConnectionInitializer` and inlines the `initialize_start` and `initialize_finish` calls. The main benefit of this is that it will allow us to use [`Connection::memory`](https://docs.rs/lsp-server/latest/lsp_server/struct.Connection.html#method.memory) in the mock server. That method returns two `Connection` where one of them will represent the client side connection and the other will be sent to the `Server::new` call to be used by the server. This way the mock client can send notifications and requests to mimic the editor. ## Test Plan I tested out the initialization process and checked that the initialized result contains the server capabilities and server info.
This commit is contained in:
parent
2c9da80985
commit
f3a27406c9
4 changed files with 24 additions and 65 deletions
|
|
@ -6,9 +6,9 @@ use crate::session::{AllOptions, ClientOptions, DiagnosticMode, Session};
|
|||
use lsp_server::Connection;
|
||||
use lsp_types::{
|
||||
ClientCapabilities, DiagnosticOptions, DiagnosticServerCapabilities, HoverProviderCapability,
|
||||
InlayHintOptions, InlayHintServerCapabilities, MessageType, SemanticTokensLegend,
|
||||
SemanticTokensOptions, SemanticTokensServerCapabilities, ServerCapabilities,
|
||||
SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
InitializeParams, InlayHintOptions, InlayHintServerCapabilities, MessageType,
|
||||
SemanticTokensLegend, SemanticTokensOptions, SemanticTokensServerCapabilities,
|
||||
ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
TextDocumentSyncOptions, TypeDefinitionProviderCapability, Url, WorkDoneProgressOptions,
|
||||
};
|
||||
use std::num::NonZeroUsize;
|
||||
|
|
@ -16,14 +16,12 @@ use std::panic::PanicHookInfo;
|
|||
use std::sync::Arc;
|
||||
|
||||
mod api;
|
||||
mod connection;
|
||||
mod main_loop;
|
||||
mod schedule;
|
||||
|
||||
use crate::session::client::Client;
|
||||
pub(crate) use api::Error;
|
||||
pub(crate) use connection::{ConnectionInitializer, ConnectionSender};
|
||||
pub(crate) use main_loop::{Action, Event, MainLoopReceiver, MainLoopSender};
|
||||
pub(crate) use main_loop::{Action, ConnectionSender, Event, MainLoopReceiver, MainLoopSender};
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, api::Error>;
|
||||
|
||||
|
|
@ -37,11 +35,9 @@ pub(crate) struct Server {
|
|||
}
|
||||
|
||||
impl Server {
|
||||
pub(crate) fn new(
|
||||
worker_threads: NonZeroUsize,
|
||||
connection: ConnectionInitializer,
|
||||
) -> crate::Result<Self> {
|
||||
let (id, init_params) = connection.initialize_start()?;
|
||||
pub(crate) fn new(worker_threads: NonZeroUsize, connection: Connection) -> crate::Result<Self> {
|
||||
let (id, init_value) = connection.initialize_start()?;
|
||||
let init_params: InitializeParams = serde_json::from_value(init_value)?;
|
||||
|
||||
let AllOptions {
|
||||
global: global_options,
|
||||
|
|
@ -59,8 +55,16 @@ impl Server {
|
|||
|
||||
let version = ruff_db::program_version().unwrap_or("Unknown");
|
||||
|
||||
let connection =
|
||||
connection.initialize_finish(id, &server_capabilities, crate::SERVER_NAME, version)?;
|
||||
connection.initialize_finish(
|
||||
id,
|
||||
serde_json::json!({
|
||||
"capabilities": server_capabilities,
|
||||
"serverInfo": {
|
||||
"name": crate::SERVER_NAME,
|
||||
"version": version
|
||||
}
|
||||
}),
|
||||
)?;
|
||||
|
||||
// The number 32 was chosen arbitrarily. The main goal was to have enough capacity to queue
|
||||
// some responses before blocking.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue