[ty] Improve LSP test server logging (#21432)

This commit is contained in:
Micha Reiser 2025-11-13 18:29:54 +01:00 committed by GitHub
parent 90b32f3b3b
commit e70fccbf25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 5 deletions

View file

@ -40,6 +40,16 @@ bitflags::bitflags! {
} }
} }
impl std::fmt::Display for ResolvedClientCapabilities {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut f = f.debug_list();
for (name, _) in self.iter_names() {
f.entry(&name);
}
f.finish()
}
}
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum SupportedCommand { pub(crate) enum SupportedCommand {
Debug, Debug,

View file

@ -65,9 +65,12 @@ impl Server {
tracing::error!("Failed to deserialize initialization options: {error}"); tracing::error!("Failed to deserialize initialization options: {error}");
} }
tracing::debug!("Initialization options: {initialization_options:?}"); tracing::debug!("Initialization options: {initialization_options:#?}");
let resolved_client_capabilities = ResolvedClientCapabilities::new(&client_capabilities); let resolved_client_capabilities = ResolvedClientCapabilities::new(&client_capabilities);
tracing::debug!("Resolved client capabilities: {resolved_client_capabilities}");
let position_encoding = Self::find_best_position_encoding(&client_capabilities); let position_encoding = Self::find_best_position_encoding(&client_capabilities);
let server_capabilities = server_capabilities( let server_capabilities = server_capabilities(
position_encoding, position_encoding,

View file

@ -5,7 +5,6 @@ use lsp_types::{
CodeDescription, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, CodeDescription, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
NumberOrString, PublishDiagnosticsParams, Url, NumberOrString, PublishDiagnosticsParams, Url,
}; };
use ruff_db::source::source_text;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use ruff_db::diagnostic::{Annotation, Severity, SubDiagnostic}; use ruff_db::diagnostic::{Annotation, Severity, SubDiagnostic};
@ -274,7 +273,6 @@ pub(super) fn compute_diagnostics(
return None; return None;
}; };
tracing::debug!("source text: {}", source_text(db, file).as_str());
let diagnostics = db.check_file(file); let diagnostics = db.check_file(file);
Some(Diagnostics { Some(Diagnostics {

View file

@ -167,6 +167,8 @@ impl TestServer {
) -> Result<Self> { ) -> Result<Self> {
setup_tracing(); setup_tracing();
tracing::debug!("Starting test client with capabilities {:#?}", capabilities);
let (server_connection, client_connection) = Connection::memory(); let (server_connection, client_connection) = Connection::memory();
// Create OS system with the test directory as cwd // Create OS system with the test directory as cwd
@ -346,6 +348,7 @@ impl TestServer {
} }
let id = self.next_request_id(); let id = self.next_request_id();
tracing::debug!("Client sends request `{}` with ID {}", R::METHOD, id);
let request = lsp_server::Request::new(id.clone(), R::METHOD.to_string(), params); let request = lsp_server::Request::new(id.clone(), R::METHOD.to_string(), params);
self.send(Message::Request(request)); self.send(Message::Request(request));
id id
@ -357,6 +360,7 @@ impl TestServer {
N: Notification, N: Notification,
{ {
let notification = lsp_server::Notification::new(N::METHOD.to_string(), params); let notification = lsp_server::Notification::new(N::METHOD.to_string(), params);
tracing::debug!("Client sends notification `{}`", N::METHOD);
self.send(Message::Notification(notification)); self.send(Message::Notification(notification));
} }
@ -540,7 +544,7 @@ impl TestServer {
fn handle_message(&mut self, message: Message) -> Result<(), TestServerError> { fn handle_message(&mut self, message: Message) -> Result<(), TestServerError> {
match message { match message {
Message::Request(request) => { Message::Request(request) => {
tracing::debug!("Received server request {}", &request.method); tracing::debug!("Received server request `{}`", &request.method);
self.requests.push_back(request); self.requests.push_back(request);
} }
Message::Response(response) => { Message::Response(response) => {
@ -558,7 +562,7 @@ impl TestServer {
} }
} }
Message::Notification(notification) => { Message::Notification(notification) => {
tracing::debug!("Received notification {}", &notification.method); tracing::debug!("Received notification `{}`", &notification.method);
self.notifications.push_back(notification); self.notifications.push_back(notification);
} }
} }