@@ -12,7 +12,9 @@ use lsp::{
12
12
IoKind , LanguageServer , LanguageServerBinary , LanguageServerName , LanguageServerSelector ,
13
13
MessageType , SetTraceParams , TraceValue , notification:: SetTrace ,
14
14
} ;
15
- use project:: { Project , WorktreeId , lsp_store:: LanguageServerLogType , search:: SearchQuery } ;
15
+ use project:: {
16
+ LspStore , Project , WorktreeId , lsp_store:: LanguageServerLogType , search:: SearchQuery ,
17
+ } ;
16
18
use std:: { any:: TypeId , borrow:: Cow , sync:: Arc } ;
17
19
use ui:: { Button , Checkbox , ContextMenu , Label , PopoverMenu , ToggleState , prelude:: * } ;
18
20
use util:: ResultExt as _;
@@ -128,6 +130,7 @@ pub struct LanguageServerState {
128
130
pub enum LanguageServerKind {
129
131
Local { project : WeakEntity < Project > } ,
130
132
Remote { project : WeakEntity < Project > } ,
133
+ LocalSsh { lsp_store : WeakEntity < LspStore > } ,
131
134
Global ,
132
135
}
133
136
@@ -136,6 +139,7 @@ impl std::fmt::Debug for LanguageServerKind {
136
139
match self {
137
140
LanguageServerKind :: Local { .. } => write ! ( f, "LanguageServerKind::Local" ) ,
138
141
LanguageServerKind :: Remote { .. } => write ! ( f, "LanguageServerKind::Remote" ) ,
142
+ LanguageServerKind :: LocalSsh { .. } => write ! ( f, "LanguageServerKind::LocalSsh" ) ,
139
143
LanguageServerKind :: Global => write ! ( f, "LanguageServerKind::Global" ) ,
140
144
}
141
145
}
@@ -146,6 +150,7 @@ impl LanguageServerKind {
146
150
match self {
147
151
Self :: Local { project } => Some ( project) ,
148
152
Self :: Remote { project } => Some ( project) ,
153
+ Self :: LocalSsh { .. } => None ,
149
154
Self :: Global { .. } => None ,
150
155
}
151
156
}
@@ -264,13 +269,13 @@ impl LogStore {
264
269
&& let Some ( server) = copilot. read ( cx) . language_server ( )
265
270
{
266
271
let server_id = server. server_id ( ) ;
267
- let weak_this = cx. weak_entity ( ) ;
272
+ let weak_lsp_store = cx. weak_entity ( ) ;
268
273
log_store. copilot_log_subscription =
269
274
Some ( server. on_notification :: < copilot:: request:: LogMessage , _ > (
270
275
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 (
274
279
server_id,
275
280
MessageType :: LOG ,
276
281
& params. message ,
@@ -460,21 +465,27 @@ impl LogStore {
460
465
let message = message. trim_end ( ) . to_string ( ) ;
461
466
if !store_logs {
462
467
// 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
+ ) ;
468
476
} else if let Some ( new_message) = Self :: push_new_message (
469
477
log_lines,
470
478
LogMessage { message, typ } ,
471
479
language_server_state. log_level ,
472
480
) {
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
+ ) ;
478
489
}
479
490
Some ( ( ) )
480
491
}
@@ -492,11 +503,14 @@ impl LogStore {
492
503
let log_lines = & mut language_server_state. trace_messages ;
493
504
if !store_logs {
494
505
// 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
+ ) ;
500
514
} else if let Some ( new_message) = Self :: push_new_message (
501
515
log_lines,
502
516
TraceMessage {
@@ -515,11 +529,14 @@ impl LogStore {
515
529
TraceValue :: Verbose ,
516
530
) ;
517
531
}
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
+ ) ;
523
540
}
524
541
Some ( ( ) )
525
542
}
@@ -544,7 +561,7 @@ impl LogStore {
544
561
language_server_id : LanguageServerId ,
545
562
kind : MessageKind ,
546
563
message : & str ,
547
- cx : & mut Context < ' _ , LogStore > ,
564
+ cx : & mut Context < ' _ , Self > ,
548
565
) {
549
566
let store_logs = self . store_logs ;
550
567
let Some ( state) = self
@@ -554,6 +571,7 @@ impl LogStore {
554
571
return ;
555
572
} ;
556
573
574
+ let mut line_before_message_to_send = None ;
557
575
let rpc_log_lines = & mut state. rpc_messages ;
558
576
if state. last_message_kind != Some ( kind) {
559
577
while rpc_log_lines. len ( ) + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -568,13 +586,7 @@ impl LogStore {
568
586
message : line_before_message. to_string ( ) ,
569
587
} ) ;
570
588
}
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) ;
578
590
}
579
591
580
592
while rpc_log_lines. len ( ) + 1 >= MAX_STORED_LOG_ENTRIES {
@@ -587,14 +599,25 @@ impl LogStore {
587
599
} ) ;
588
600
}
589
601
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 ( ) ,
595
618
} ,
596
- text : message . to_owned ( ) ,
597
- } ) ;
619
+ cx ,
620
+ ) ;
598
621
}
599
622
600
623
pub fn remove_language_server ( & mut self , id : LanguageServerId , cx : & mut Context < Self > ) {
@@ -627,7 +650,7 @@ impl LogStore {
627
650
None
628
651
}
629
652
}
630
- LanguageServerKind :: Global => Some ( * id) ,
653
+ LanguageServerKind :: Global | LanguageServerKind :: LocalSsh { .. } => Some ( * id) ,
631
654
} )
632
655
}
633
656
@@ -784,6 +807,37 @@ impl LogStore {
784
807
cx. notify ( ) ;
785
808
Some ( ( ) )
786
809
}
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
+ }
787
841
}
788
842
789
843
impl LspLogView {
@@ -828,27 +882,11 @@ impl LspLogView {
828
882
cx. notify ( ) ;
829
883
} ) ;
830
884
831
- let weak_lsp_store = project. read ( cx) . lsp_store ( ) . downgrade ( ) ;
832
885
let events_subscriptions =
833
886
cx. subscribe_in ( & log_store, window, move |log_view, _, e, window, cx| {
834
- log:: error!( "|||||||| @@@@|| {e:?}" ) ;
887
+ log:: error!( "@@@@@@ {e:?}" ) ;
835
888
match e {
836
889
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
-
852
890
if log_view. current_server_id == Some ( * id)
853
891
&& LogKind :: from_server_log_type ( kind) == log_view. active_entry_kind
854
892
{
@@ -983,7 +1021,9 @@ impl LspLogView {
983
1021
. language_servers
984
1022
. iter ( )
985
1023
. map ( |( server_id, state) | match & state. kind {
986
- LanguageServerKind :: Local { .. } | LanguageServerKind :: Remote { .. } => {
1024
+ LanguageServerKind :: Local { .. }
1025
+ | LanguageServerKind :: Remote { .. }
1026
+ | LanguageServerKind :: LocalSsh { .. } => {
987
1027
let worktree_root_name = state
988
1028
. worktree_id
989
1029
. and_then ( |id| self . project . read ( cx) . worktree_for_id ( id, cx) )
0 commit comments