@@ -55,6 +55,7 @@ use crate::{
55
55
proxy:: { path_from_url, LapceProxy } ,
56
56
rename:: RenameData ,
57
57
selection_range:: SelectionRangeDirection ,
58
+ signature:: { SignatureData , SignatureStatus } ,
58
59
source_control:: SourceControlData ,
59
60
split:: { SplitDirection , SplitMoveDirection } ,
60
61
} ;
@@ -208,6 +209,7 @@ pub struct LapceEditorBufferData {
208
209
pub editor : Arc < LapceEditorData > ,
209
210
pub doc : Arc < Document > ,
210
211
pub completion : Arc < CompletionData > ,
212
+ pub signature : Arc < SignatureData > ,
211
213
pub hover : Arc < HoverData > ,
212
214
pub rename : Arc < RenameData > ,
213
215
pub main_split : LapceMainSplitData ,
@@ -341,6 +343,12 @@ impl LapceEditorBufferData {
341
343
&& self . completion . len ( ) > 0
342
344
}
343
345
346
+ /// Check if there are signatures that are being rendered
347
+ fn has_signature ( & self ) -> bool {
348
+ self . signature . status != SignatureStatus :: Inactive
349
+ && !self . signature . is_empty ( )
350
+ }
351
+
344
352
fn has_hover ( & self ) -> bool {
345
353
self . hover . status != HoverStatus :: Inactive && !self . hover . is_empty ( )
346
354
}
@@ -612,6 +620,14 @@ impl LapceEditorBufferData {
612
620
completion. cancel ( ) ;
613
621
}
614
622
623
+ pub fn cancel_signature ( & mut self ) {
624
+ if self . signature . status == SignatureStatus :: Inactive {
625
+ return ;
626
+ }
627
+ let signature = Arc :: make_mut ( & mut self . signature ) ;
628
+ signature. cancel ( ) ;
629
+ }
630
+
615
631
pub fn cancel_hover ( & mut self ) {
616
632
let hover = Arc :: make_mut ( & mut self . hover ) ;
617
633
hover. cancel ( ) ;
@@ -781,6 +797,34 @@ impl LapceEditorBufferData {
781
797
}
782
798
}
783
799
800
+ fn update_signature ( & mut self ) {
801
+ if self . get_mode ( ) != Mode :: Insert {
802
+ self . cancel_signature ( ) ;
803
+ return ;
804
+ }
805
+ if !self . doc . loaded ( ) || !self . doc . content ( ) . is_file ( ) {
806
+ return ;
807
+ }
808
+
809
+ let offset = self . editor . cursor . offset ( ) ;
810
+ let start_offset = self . doc . buffer ( ) . prev_code_boundary ( offset) ;
811
+
812
+ let signature = Arc :: make_mut ( & mut self . signature ) ;
813
+
814
+ signature. buffer_id = self . doc . id ( ) ;
815
+ signature. offset = start_offset;
816
+ signature. status = SignatureStatus :: Started ;
817
+ signature. request_id += 1 ;
818
+
819
+ let start_pos = self . doc . buffer ( ) . offset_to_position ( start_offset) ;
820
+ signature. request (
821
+ self . proxy . clone ( ) ,
822
+ signature. request_id ,
823
+ self . doc . content ( ) . path ( ) . unwrap ( ) . into ( ) ,
824
+ start_pos,
825
+ ) ;
826
+ }
827
+
784
828
/// return true if there's existing hover and it's not changed
785
829
pub fn check_hover (
786
830
& mut self ,
@@ -1416,6 +1460,10 @@ impl LapceEditorBufferData {
1416
1460
}
1417
1461
}
1418
1462
self . cancel_completion ( ) ;
1463
+ // Cancel but then immediately try to see if there's a signature to provide
1464
+ // TODO: Can we be smarter about this?
1465
+ self . cancel_signature ( ) ;
1466
+ self . update_signature ( ) ;
1419
1467
self . cancel_hover ( ) ;
1420
1468
CommandExecuted :: Yes
1421
1469
}
@@ -1447,8 +1495,11 @@ impl LapceEditorBufferData {
1447
1495
1448
1496
if show_completion ( cmd, & doc_before_edit, & deltas) {
1449
1497
self . update_completion ( ctx, false ) ;
1498
+ // TODO: This can be requested in more specific cases based on the LSP supplied trigger
1499
+ self . update_signature ( ) ;
1450
1500
} else {
1451
1501
self . cancel_completion ( ) ;
1502
+ self . cancel_signature ( ) ;
1452
1503
}
1453
1504
self . apply_deltas ( & deltas) ;
1454
1505
@@ -1478,6 +1529,9 @@ impl LapceEditorBufferData {
1478
1529
if self . has_completions ( ) {
1479
1530
self . cancel_completion ( ) ;
1480
1531
}
1532
+ if self . has_signature ( ) {
1533
+ self . cancel_signature ( ) ;
1534
+ }
1481
1535
if self . has_hover ( ) {
1482
1536
self . cancel_hover ( ) ;
1483
1537
}
@@ -1822,6 +1876,7 @@ impl LapceEditorBufferData {
1822
1876
if last_placeholder {
1823
1877
Arc :: make_mut ( & mut self . editor ) . snippet = None ;
1824
1878
}
1879
+ self . update_signature ( ) ;
1825
1880
self . cancel_completion ( ) ;
1826
1881
}
1827
1882
}
@@ -1848,6 +1903,7 @@ impl LapceEditorBufferData {
1848
1903
. cursor
1849
1904
. set_insert ( selection) ;
1850
1905
}
1906
+ self . update_signature ( ) ;
1851
1907
self . cancel_completion ( ) ;
1852
1908
}
1853
1909
}
@@ -1902,6 +1958,9 @@ impl LapceEditorBufferData {
1902
1958
// we allow empty inputs to allow for cases where the user wants to get the autocompletion beforehand
1903
1959
self . update_completion ( ctx, true ) ;
1904
1960
}
1961
+ GetSignature => {
1962
+ self . update_signature ( ) ;
1963
+ }
1905
1964
GotoDefinition => {
1906
1965
if let BufferContent :: File ( path) = self . doc . content ( ) {
1907
1966
let offset = self . editor . cursor . offset ( ) ;
@@ -2392,6 +2451,7 @@ impl LapceEditorBufferData {
2392
2451
let cursor = & mut Arc :: make_mut ( & mut self . editor ) . cursor ;
2393
2452
self . doc
2394
2453
. do_multi_selection ( ctx. text ( ) , cursor, cmd, & view, & self . config ) ;
2454
+ self . cancel_signature ( ) ;
2395
2455
self . cancel_completion ( ) ;
2396
2456
CommandExecuted :: Yes
2397
2457
}
@@ -2465,6 +2525,7 @@ impl KeyPressFocus for LapceEditorBufferData {
2465
2525
. all ( |c| c. is_whitespace ( ) || c. is_ascii_whitespace ( ) )
2466
2526
{
2467
2527
self . update_completion ( ctx, false ) ;
2528
+ self . update_signature ( ) ;
2468
2529
} else {
2469
2530
self . cancel_completion ( ) ;
2470
2531
}
0 commit comments