Skip to content

Commit 4ba48ab

Browse files
Fix duplicated RPC headers
1 parent 1155757 commit 4ba48ab

File tree

3 files changed

+48
-53
lines changed

3 files changed

+48
-53
lines changed

crates/language_tools/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ futures.workspace = true
2222
gpui.workspace = true
2323
itertools.workspace = true
2424
language.workspace = true
25-
log.workspace = true
2625
lsp.workspace = true
2726
project.workspace = true
2827
proto.workspace = true

crates/language_tools/src/lsp_log.rs

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl Message for TraceMessage {
100100
}
101101
}
102102

103+
#[derive(Debug)]
103104
struct RpcMessage {
104105
message: String,
105106
}
@@ -156,6 +157,7 @@ impl LanguageServerKind {
156157
}
157158
}
158159

160+
#[derive(Debug)]
159161
pub struct LanguageServerRpcState {
160162
rpc_messages: VecDeque<RpcMessage>,
161163
last_message_kind: Option<MessageKind>,
@@ -177,7 +179,7 @@ pub struct LspLogToolbarItemView {
177179
_log_view_subscription: Option<Subscription>,
178180
}
179181

180-
#[derive(Copy, Clone, PartialEq, Eq)]
182+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
181183
enum MessageKind {
182184
Send,
183185
Receive,
@@ -571,7 +573,7 @@ impl LogStore {
571573
return;
572574
};
573575

574-
let mut line_before_message_to_send = None;
576+
let received = kind == MessageKind::Receive;
575577
let rpc_log_lines = &mut state.rpc_messages;
576578
if state.last_message_kind != Some(kind) {
577579
while rpc_log_lines.len() + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -586,7 +588,12 @@ impl LogStore {
586588
message: line_before_message.to_string(),
587589
});
588590
}
589-
line_before_message_to_send = Some(line_before_message);
591+
// Do not send a synthetic message over the wire, it will be derived from the actual RPC message
592+
cx.emit(Event::NewServerLogEntry {
593+
id: language_server_id,
594+
kind: LanguageServerLogType::Rpc { received },
595+
text: line_before_message.to_string(),
596+
});
590597
}
591598

592599
while rpc_log_lines.len() + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -599,17 +606,6 @@ impl LogStore {
599606
});
600607
}
601608

602-
let received = kind == MessageKind::Receive;
603-
if let Some(line_before_message) = line_before_message_to_send {
604-
self.emit_event(
605-
Event::NewServerLogEntry {
606-
id: language_server_id,
607-
kind: LanguageServerLogType::Rpc { received },
608-
text: line_before_message.to_string(),
609-
},
610-
cx,
611-
);
612-
}
613609
self.emit_event(
614610
Event::NewServerLogEntry {
615611
id: language_server_id,
@@ -822,7 +818,6 @@ impl LogStore {
822818
}
823819
.and_then(|lsp_store| lsp_store.read(cx).downstream_client());
824820
if let Some((client, project_id)) = downstream_client {
825-
log::error!("|||||||||| {text}");
826821
client
827822
.send(proto::LanguageServerLog {
828823
project_id,
@@ -882,48 +877,48 @@ impl LspLogView {
882877
cx.notify();
883878
});
884879

885-
let events_subscriptions =
886-
cx.subscribe_in(&log_store, window, move |log_view, _, e, window, cx| {
887-
log::error!("@@@@@@ {e:?}");
888-
match e {
889-
Event::NewServerLogEntry { id, kind, text } => {
890-
if log_view.current_server_id == Some(*id)
891-
&& LogKind::from_server_log_type(kind) == log_view.active_entry_kind
892-
{
893-
log_view.editor.update(cx, |editor, cx| {
894-
editor.set_read_only(false);
895-
let last_offset = editor.buffer().read(cx).len(cx);
896-
let newest_cursor_is_at_end =
897-
editor.selections.newest::<usize>(cx).start >= last_offset;
898-
editor.edit(
899-
vec![
900-
(last_offset..last_offset, text.as_str()),
901-
(last_offset..last_offset, "\n"),
902-
],
880+
let events_subscriptions = cx.subscribe_in(
881+
&log_store,
882+
window,
883+
move |log_view, _, e, window, cx| match e {
884+
Event::NewServerLogEntry { id, kind, text } => {
885+
if log_view.current_server_id == Some(*id)
886+
&& LogKind::from_server_log_type(kind) == log_view.active_entry_kind
887+
{
888+
log_view.editor.update(cx, |editor, cx| {
889+
editor.set_read_only(false);
890+
let last_offset = editor.buffer().read(cx).len(cx);
891+
let newest_cursor_is_at_end =
892+
editor.selections.newest::<usize>(cx).start >= last_offset;
893+
editor.edit(
894+
vec![
895+
(last_offset..last_offset, text.as_str()),
896+
(last_offset..last_offset, "\n"),
897+
],
898+
cx,
899+
);
900+
if text.len() > 1024
901+
&& let Some((fold_offset, _)) =
902+
text.char_indices().dropping(1024).next()
903+
&& fold_offset < text.len()
904+
{
905+
editor.fold_ranges(
906+
vec![last_offset + fold_offset..last_offset + text.len()],
907+
false,
908+
window,
903909
cx,
904910
);
905-
if text.len() > 1024
906-
&& let Some((fold_offset, _)) =
907-
text.char_indices().dropping(1024).next()
908-
&& fold_offset < text.len()
909-
{
910-
editor.fold_ranges(
911-
vec![last_offset + fold_offset..last_offset + text.len()],
912-
false,
913-
window,
914-
cx,
915-
);
916-
}
911+
}
917912

918-
if newest_cursor_is_at_end {
919-
editor.request_autoscroll(Autoscroll::bottom(), cx);
920-
}
921-
editor.set_read_only(true);
922-
});
923-
}
913+
if newest_cursor_is_at_end {
914+
editor.request_autoscroll(Autoscroll::bottom(), cx);
915+
}
916+
editor.set_read_only(true);
917+
});
924918
}
925919
}
926-
});
920+
},
921+
);
927922
let (editor, editor_subscriptions) = Self::editor_for_logs(String::new(), window, cx);
928923

929924
let focus_handle = cx.focus_handle();

crates/project/src/lsp_store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8982,6 +8982,7 @@ impl LspStore {
89828982
envelope: TypedEnvelope<proto::LanguageServerLog>,
89838983
mut cx: AsyncApp,
89848984
) -> Result<()> {
8985+
log::error!("########################################### {envelope:?}");
89858986
let language_server_id = LanguageServerId(envelope.payload.language_server_id as usize);
89868987
let log_type = envelope
89878988
.payload

0 commit comments

Comments
 (0)