@@ -12,7 +12,9 @@ use lsp::{
1212 IoKind , LanguageServer , LanguageServerBinary , LanguageServerName , LanguageServerSelector ,
1313 MessageType , SetTraceParams , TraceValue , notification:: SetTrace ,
1414} ;
15- use project:: { Project , WorktreeId , lsp_store:: LanguageServerLogType , search:: SearchQuery } ;
15+ use project:: {
16+ LspStore , Project , WorktreeId , lsp_store:: LanguageServerLogType , search:: SearchQuery ,
17+ } ;
1618use std:: { any:: TypeId , borrow:: Cow , sync:: Arc } ;
1719use ui:: { Button , Checkbox , ContextMenu , Label , PopoverMenu , ToggleState , prelude:: * } ;
1820use util:: ResultExt as _;
@@ -128,6 +130,7 @@ pub struct LanguageServerState {
128130pub enum LanguageServerKind {
129131 Local { project : WeakEntity < Project > } ,
130132 Remote { project : WeakEntity < Project > } ,
133+ LocalSsh { lsp_store : WeakEntity < LspStore > } ,
131134 Global ,
132135}
133136
@@ -136,6 +139,7 @@ impl std::fmt::Debug for LanguageServerKind {
136139 match self {
137140 LanguageServerKind :: Local { .. } => write ! ( f, "LanguageServerKind::Local" ) ,
138141 LanguageServerKind :: Remote { .. } => write ! ( f, "LanguageServerKind::Remote" ) ,
142+ LanguageServerKind :: LocalSsh { .. } => write ! ( f, "LanguageServerKind::LocalSsh" ) ,
139143 LanguageServerKind :: Global => write ! ( f, "LanguageServerKind::Global" ) ,
140144 }
141145 }
@@ -146,6 +150,7 @@ impl LanguageServerKind {
146150 match self {
147151 Self :: Local { project } => Some ( project) ,
148152 Self :: Remote { project } => Some ( project) ,
153+ Self :: LocalSsh { .. } => None ,
149154 Self :: Global { .. } => None ,
150155 }
151156 }
@@ -264,13 +269,13 @@ impl LogStore {
264269 && let Some ( server) = copilot. read ( cx) . language_server ( )
265270 {
266271 let server_id = server. server_id ( ) ;
267- let weak_this = cx. weak_entity ( ) ;
272+ let weak_lsp_store = cx. weak_entity ( ) ;
268273 log_store. copilot_log_subscription =
269274 Some ( server. on_notification :: < copilot:: request:: LogMessage , _ > (
270275 move |params, cx| {
271- weak_this
272- . update ( cx, |this , cx| {
273- this . add_language_server_log (
276+ weak_lsp_store
277+ . update ( cx, |lsp_store , cx| {
278+ lsp_store . add_language_server_log (
274279 server_id,
275280 MessageType :: LOG ,
276281 & params. message ,
@@ -460,21 +465,27 @@ impl LogStore {
460465 let message = message. trim_end ( ) . to_string ( ) ;
461466 if !store_logs {
462467 // Send all messages regardless of the visibility in case of not storing, to notify the receiver anyway
463- cx. emit ( Event :: NewServerLogEntry {
464- id,
465- kind : LanguageServerLogType :: Log ( typ) ,
466- text : message,
467- } ) ;
468+ self . emit_event (
469+ Event :: NewServerLogEntry {
470+ id,
471+ kind : LanguageServerLogType :: Log ( typ) ,
472+ text : message,
473+ } ,
474+ cx,
475+ ) ;
468476 } else if let Some ( new_message) = Self :: push_new_message (
469477 log_lines,
470478 LogMessage { message, typ } ,
471479 language_server_state. log_level ,
472480 ) {
473- cx. emit ( Event :: NewServerLogEntry {
474- id,
475- kind : LanguageServerLogType :: Log ( typ) ,
476- text : new_message,
477- } ) ;
481+ self . emit_event (
482+ Event :: NewServerLogEntry {
483+ id,
484+ kind : LanguageServerLogType :: Log ( typ) ,
485+ text : new_message,
486+ } ,
487+ cx,
488+ ) ;
478489 }
479490 Some ( ( ) )
480491 }
@@ -492,11 +503,14 @@ impl LogStore {
492503 let log_lines = & mut language_server_state. trace_messages ;
493504 if !store_logs {
494505 // Send all messages regardless of the visibility in case of not storing, to notify the receiver anyway
495- cx. emit ( Event :: NewServerLogEntry {
496- id,
497- kind : LanguageServerLogType :: Trace { verbose_info } ,
498- text : message. trim ( ) . to_string ( ) ,
499- } ) ;
506+ self . emit_event (
507+ Event :: NewServerLogEntry {
508+ id,
509+ kind : LanguageServerLogType :: Trace { verbose_info } ,
510+ text : message. trim ( ) . to_string ( ) ,
511+ } ,
512+ cx,
513+ ) ;
500514 } else if let Some ( new_message) = Self :: push_new_message (
501515 log_lines,
502516 TraceMessage {
@@ -515,11 +529,14 @@ impl LogStore {
515529 TraceValue :: Verbose ,
516530 ) ;
517531 }
518- cx. emit ( Event :: NewServerLogEntry {
519- id,
520- kind : LanguageServerLogType :: Trace { verbose_info } ,
521- text : new_message,
522- } ) ;
532+ self . emit_event (
533+ Event :: NewServerLogEntry {
534+ id,
535+ kind : LanguageServerLogType :: Trace { verbose_info } ,
536+ text : new_message,
537+ } ,
538+ cx,
539+ ) ;
523540 }
524541 Some ( ( ) )
525542 }
@@ -544,7 +561,7 @@ impl LogStore {
544561 language_server_id : LanguageServerId ,
545562 kind : MessageKind ,
546563 message : & str ,
547- cx : & mut Context < ' _ , LogStore > ,
564+ cx : & mut Context < ' _ , Self > ,
548565 ) {
549566 let store_logs = self . store_logs ;
550567 let Some ( state) = self
@@ -554,6 +571,7 @@ impl LogStore {
554571 return ;
555572 } ;
556573
574+ let mut line_before_message_to_send = None ;
557575 let rpc_log_lines = & mut state. rpc_messages ;
558576 if state. last_message_kind != Some ( kind) {
559577 while rpc_log_lines. len ( ) + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -568,13 +586,7 @@ impl LogStore {
568586 message : line_before_message. to_string ( ) ,
569587 } ) ;
570588 }
571- cx. emit ( Event :: NewServerLogEntry {
572- id : language_server_id,
573- kind : LanguageServerLogType :: Rpc {
574- received : kind == MessageKind :: Receive ,
575- } ,
576- text : line_before_message. to_string ( ) ,
577- } ) ;
589+ line_before_message_to_send = Some ( line_before_message) ;
578590 }
579591
580592 while rpc_log_lines. len ( ) + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -587,14 +599,25 @@ impl LogStore {
587599 } ) ;
588600 }
589601
590- log:: error!( "|||||||||| {message}" ) ;
591- cx. emit ( Event :: NewServerLogEntry {
592- id : language_server_id,
593- kind : LanguageServerLogType :: Rpc {
594- received : kind == MessageKind :: Receive ,
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+ }
613+ self . emit_event (
614+ Event :: NewServerLogEntry {
615+ id : language_server_id,
616+ kind : LanguageServerLogType :: Rpc { received } ,
617+ text : message. to_owned ( ) ,
595618 } ,
596- text : message . to_owned ( ) ,
597- } ) ;
619+ cx ,
620+ ) ;
598621 }
599622
600623 pub fn remove_language_server ( & mut self , id : LanguageServerId , cx : & mut Context < Self > ) {
@@ -627,7 +650,7 @@ impl LogStore {
627650 None
628651 }
629652 }
630- LanguageServerKind :: Global => Some ( * id) ,
653+ LanguageServerKind :: Global | LanguageServerKind :: LocalSsh { .. } => Some ( * id) ,
631654 } )
632655 }
633656
@@ -784,6 +807,37 @@ impl LogStore {
784807 cx. notify ( ) ;
785808 Some ( ( ) )
786809 }
810+
811+ fn emit_event ( & mut self , e : Event , cx : & mut Context < Self > ) {
812+ match & e {
813+ Event :: NewServerLogEntry { id, kind, text } => {
814+ if let Some ( state) = self . get_language_server_state ( * id) {
815+ let downstream_client = match & state. kind {
816+ LanguageServerKind :: Remote { project }
817+ | LanguageServerKind :: Local { project } => project
818+ . upgrade ( )
819+ . map ( |project| project. read ( cx) . lsp_store ( ) ) ,
820+ LanguageServerKind :: LocalSsh { lsp_store } => lsp_store. upgrade ( ) ,
821+ LanguageServerKind :: Global => None ,
822+ }
823+ . and_then ( |lsp_store| lsp_store. read ( cx) . downstream_client ( ) ) ;
824+ if let Some ( ( client, project_id) ) = downstream_client {
825+ log:: error!( "|||||||||| {text}" ) ;
826+ client
827+ . send ( proto:: LanguageServerLog {
828+ project_id,
829+ language_server_id : id. to_proto ( ) ,
830+ message : text. clone ( ) ,
831+ log_type : Some ( kind. to_proto ( ) ) ,
832+ } )
833+ . ok ( ) ;
834+ }
835+ }
836+ }
837+ }
838+
839+ cx. emit ( e) ;
840+ }
787841}
788842
789843impl LspLogView {
@@ -828,27 +882,11 @@ impl LspLogView {
828882 cx. notify ( ) ;
829883 } ) ;
830884
831- let weak_lsp_store = project. read ( cx) . lsp_store ( ) . downgrade ( ) ;
832885 let events_subscriptions =
833886 cx. subscribe_in ( & log_store, window, move |log_view, _, e, window, cx| {
834- log:: error!( "|||||||| @@@@|| {e:?}" ) ;
887+ log:: error!( "@@@@@@ {e:?}" ) ;
835888 match e {
836889 Event :: NewServerLogEntry { id, kind, text } => {
837- weak_lsp_store
838- . update ( cx, |lsp_store, _| {
839- if let Some ( ( client, project_id) ) = lsp_store. downstream_client ( ) {
840- client
841- . send ( proto:: LanguageServerLog {
842- project_id,
843- language_server_id : id. to_proto ( ) ,
844- message : text. clone ( ) ,
845- log_type : Some ( kind. to_proto ( ) ) ,
846- } )
847- . log_err ( ) ;
848- } ;
849- } )
850- . ok ( ) ;
851-
852890 if log_view. current_server_id == Some ( * id)
853891 && LogKind :: from_server_log_type ( kind) == log_view. active_entry_kind
854892 {
@@ -983,7 +1021,9 @@ impl LspLogView {
9831021 . language_servers
9841022 . iter ( )
9851023 . map ( |( server_id, state) | match & state. kind {
986- LanguageServerKind :: Local { .. } | LanguageServerKind :: Remote { .. } => {
1024+ LanguageServerKind :: Local { .. }
1025+ | LanguageServerKind :: Remote { .. }
1026+ | LanguageServerKind :: LocalSsh { .. } => {
9871027 let worktree_root_name = state
9881028 . worktree_id
9891029 . and_then ( |id| self . project . read ( cx) . worktree_for_id ( id, cx) )
0 commit comments