Do not send any LSP logs by default to collab clients (#37163)
Follow-up https://github.com/zed-industries/zed/pull/37083 Noisy RPC LSP logs were functioning this way already, but to keep Collab loaded even less, do not send any kind of logs to the client if the client has a corresponding log tab not opened. This change is pretty raw and does not fully cover scenarious with multiple clients: if one client has a log tab open and another opens tab with another kind of log, the 2nd kind of logs will be streamed only. Also, it should be possible to forward the host logs to the client on enabling — that is not done to keep the change smaller. Release Notes: - N/A
This commit is contained in:
@@ -14,7 +14,7 @@ use ui::{Context, Window};
|
||||
use workspace::{Item, ItemHandle, SplitDirection, Workspace};
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
lsp_log_view::init(true, cx);
|
||||
lsp_log_view::init(false, cx);
|
||||
syntax_tree_view::init(cx);
|
||||
key_context_view::init(cx);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use project::{
|
||||
lsp_store::log_store::{self, Event, LanguageServerKind, LogKind, LogStore, Message},
|
||||
search::SearchQuery,
|
||||
};
|
||||
use proto::toggle_lsp_logs::LogType;
|
||||
use std::{any::TypeId, borrow::Cow, sync::Arc};
|
||||
use ui::{Button, Checkbox, ContextMenu, Label, PopoverMenu, ToggleState, prelude::*};
|
||||
use util::ResultExt as _;
|
||||
@@ -111,8 +112,8 @@ actions!(
|
||||
]
|
||||
);
|
||||
|
||||
pub fn init(store_logs: bool, cx: &mut App) {
|
||||
let log_store = log_store::init(store_logs, cx);
|
||||
pub fn init(on_headless_host: bool, cx: &mut App) {
|
||||
let log_store = log_store::init(on_headless_host, cx);
|
||||
|
||||
log_store.update(cx, |_, cx| {
|
||||
Copilot::global(cx).map(|copilot| {
|
||||
@@ -266,6 +267,19 @@ impl LspLogView {
|
||||
window.focus(&log_view.editor.focus_handle(cx));
|
||||
});
|
||||
|
||||
cx.on_release(|log_view, cx| {
|
||||
log_view.log_store.update(cx, |log_store, cx| {
|
||||
for (server_id, state) in &log_store.language_servers {
|
||||
if let Some(log_kind) = state.toggled_log_kind {
|
||||
if let Some(log_type) = log_type(log_kind) {
|
||||
send_toggle_log_message(state, *server_id, false, log_type, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
|
||||
let mut lsp_log_view = Self {
|
||||
focus_handle,
|
||||
editor,
|
||||
@@ -436,6 +450,12 @@ impl LspLogView {
|
||||
cx.notify();
|
||||
}
|
||||
self.editor.read(cx).focus_handle(cx).focus(window);
|
||||
self.log_store.update(cx, |log_store, cx| {
|
||||
let state = log_store.get_language_server_state(server_id)?;
|
||||
state.toggled_log_kind = Some(LogKind::Logs);
|
||||
send_toggle_log_message(state, server_id, true, LogType::Log, cx);
|
||||
Some(())
|
||||
});
|
||||
}
|
||||
|
||||
fn update_log_level(
|
||||
@@ -472,8 +492,8 @@ impl LspLogView {
|
||||
) {
|
||||
let trace_level = self
|
||||
.log_store
|
||||
.update(cx, |this, _| {
|
||||
Some(this.get_language_server_state(server_id)?.trace_level)
|
||||
.update(cx, |log_store, _| {
|
||||
Some(log_store.get_language_server_state(server_id)?.trace_level)
|
||||
})
|
||||
.unwrap_or(TraceValue::Messages);
|
||||
let log_contents = self
|
||||
@@ -487,6 +507,12 @@ impl LspLogView {
|
||||
let (editor, editor_subscriptions) = Self::editor_for_logs(log_contents, window, cx);
|
||||
self.editor = editor;
|
||||
self.editor_subscriptions = editor_subscriptions;
|
||||
self.log_store.update(cx, |log_store, cx| {
|
||||
let state = log_store.get_language_server_state(server_id)?;
|
||||
state.toggled_log_kind = Some(LogKind::Trace);
|
||||
send_toggle_log_message(state, server_id, true, LogType::Trace, cx);
|
||||
Some(())
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
self.editor.read(cx).focus_handle(cx).focus(window);
|
||||
@@ -551,24 +577,7 @@ impl LspLogView {
|
||||
}
|
||||
|
||||
if let Some(server_state) = log_store.language_servers.get(&server_id) {
|
||||
if let LanguageServerKind::Remote { project } = &server_state.kind {
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
if let Some((client, project_id)) =
|
||||
project.lsp_store().read(cx).upstream_client()
|
||||
{
|
||||
client
|
||||
.send(proto::ToggleLspLogs {
|
||||
project_id,
|
||||
log_type: proto::toggle_lsp_logs::LogType::Rpc as i32,
|
||||
server_id: server_id.to_proto(),
|
||||
enabled,
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
send_toggle_log_message(server_state, server_id, enabled, LogType::Rpc, cx);
|
||||
};
|
||||
});
|
||||
if !enabled && Some(server_id) == self.current_server_id {
|
||||
@@ -644,6 +653,49 @@ impl LspLogView {
|
||||
self.editor_subscriptions = editor_subscriptions;
|
||||
cx.notify();
|
||||
self.editor.read(cx).focus_handle(cx).focus(window);
|
||||
self.log_store.update(cx, |log_store, cx| {
|
||||
let state = log_store.get_language_server_state(server_id)?;
|
||||
if let Some(log_kind) = state.toggled_log_kind.take() {
|
||||
if let Some(log_type) = log_type(log_kind) {
|
||||
send_toggle_log_message(state, server_id, false, log_type, cx);
|
||||
}
|
||||
};
|
||||
Some(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn log_type(log_kind: LogKind) -> Option<LogType> {
|
||||
match log_kind {
|
||||
LogKind::Rpc => Some(LogType::Rpc),
|
||||
LogKind::Trace => Some(LogType::Trace),
|
||||
LogKind::Logs => Some(LogType::Log),
|
||||
LogKind::ServerInfo => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn send_toggle_log_message(
|
||||
server_state: &log_store::LanguageServerState,
|
||||
server_id: LanguageServerId,
|
||||
enabled: bool,
|
||||
log_type: LogType,
|
||||
cx: &mut App,
|
||||
) {
|
||||
if let LanguageServerKind::Remote { project } = &server_state.kind {
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
if let Some((client, project_id)) = project.lsp_store().read(cx).upstream_client() {
|
||||
client
|
||||
.send(proto::ToggleLspLogs {
|
||||
project_id,
|
||||
log_type: log_type as i32,
|
||||
server_id: server_id.to_proto(),
|
||||
enabled,
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ async fn test_lsp_log_view(cx: &mut TestAppContext) {
|
||||
},
|
||||
);
|
||||
|
||||
let log_store = cx.new(|cx| LogStore::new(true, cx));
|
||||
let log_store = cx.new(|cx| LogStore::new(false, cx));
|
||||
log_store.update(cx, |store, cx| store.add_project(&project, cx));
|
||||
|
||||
let _rust_buffer = project
|
||||
|
||||
Reference in New Issue
Block a user