@@ -103,6 +103,7 @@ impl std::fmt::Display for WDProgress {
103
103
enum Action {
104
104
Command ( CodeActionOrCommand ) ,
105
105
Completion ( CompletionItem ) ,
106
+ CodeLens ( CodeLens ) ,
106
107
}
107
108
108
109
#[ derive( Debug , Eq , PartialEq , Hash , Clone ) ]
@@ -168,6 +169,7 @@ struct WindowHover {
168
169
hover : Option < String > ,
169
170
/// result of signature request
170
171
signature : Option < String > ,
172
+ lens : Vec < CodeLens > ,
171
173
/// completion response. we need to cache this because we also need the token
172
174
/// response to come, and we don't know which will come first.
173
175
completion : Vec < CompletionItem > ,
@@ -391,6 +393,9 @@ impl Server {
391
393
}
392
394
hover. actions . extend ( v) ;
393
395
}
396
+ hover
397
+ . actions
398
+ . extend ( hover. lens . iter ( ) . map ( |lens| Action :: CodeLens ( lens. clone ( ) ) ) ) ;
394
399
395
400
hover. body . clear ( ) ;
396
401
if let Some ( text) = & hover. hover {
@@ -431,6 +436,22 @@ impl Server {
431
436
write ! ( & mut hover. body, " {}" , d) . unwrap ( ) ;
432
437
}
433
438
}
439
+ // TODO: extract out the range text and append it to the command title to
440
+ // distinguish between lenses.
441
+ Action :: CodeLens ( _lens) => {
442
+ /*
443
+ write!(
444
+ &mut hover.body,
445
+ "{}[{}]",
446
+ newline,
447
+ lens.command
448
+ .as_ref()
449
+ .map(|c| c.title.clone())
450
+ .unwrap_or("unknown command".into())
451
+ )
452
+ .unwrap();
453
+ */
454
+ }
434
455
}
435
456
}
436
457
hover. action_addrs . push ( ( hover. body . len ( ) , 100000 ) ) ;
@@ -494,12 +515,6 @@ impl Server {
494
515
if caps. implementation_provider . is_some ( ) {
495
516
body. push_str ( "[impl] " ) ;
496
517
}
497
- #[ cfg( debug_assertions) ]
498
- {
499
- if caps. code_lens_provider . is_some ( ) {
500
- body. push_str ( "[lens] " ) ;
501
- }
502
- }
503
518
if caps. references_provider . is_some ( ) {
504
519
body. push_str ( "[references] " ) ;
505
520
}
@@ -819,17 +834,9 @@ impl Server {
819
834
CodeLensRequest :: METHOD => {
820
835
let msg = serde_json:: from_str :: < Option < Vec < CodeLens > > > ( result. get ( ) ) ?;
821
836
if let Some ( msg) = msg {
822
- let mut o: Vec < String > = vec ! [ ] ;
823
- for lens in msg {
824
- let loc = Location {
825
- uri : url. clone ( ) ,
826
- range : lens. range ,
827
- } ;
828
- o. push ( format ! ( "{}" , location_to_plumb( & loc) ) ) ;
829
- }
830
- if o. len ( ) > 0 {
831
- self . output = o. join ( "\n " ) ;
832
- }
837
+ self . set_hover ( & url, |hover| {
838
+ hover. lens = msg;
839
+ } ) ;
833
840
}
834
841
}
835
842
CodeActionRequest :: METHOD => {
@@ -1158,6 +1165,7 @@ impl Server {
1158
1165
line,
1159
1166
token : None ,
1160
1167
signature : None ,
1168
+ lens : vec ! [ ] ,
1161
1169
completion : vec ! [ ] ,
1162
1170
code_actions : vec ! [ ] ,
1163
1171
actions : vec ! [ ] ,
@@ -1212,13 +1220,22 @@ impl Server {
1212
1220
) ?;
1213
1221
self . send_request :: < SignatureHelpRequest > (
1214
1222
client_name,
1215
- url,
1223
+ url. clone ( ) ,
1216
1224
SignatureHelpParams {
1217
1225
context : None ,
1218
1226
text_document_position_params : text_document_position_params. clone ( ) ,
1219
1227
work_done_progress_params,
1220
1228
} ,
1221
1229
) ?;
1230
+ self . send_request :: < CodeLensRequest > (
1231
+ client_name,
1232
+ url. clone ( ) ,
1233
+ CodeLensParams {
1234
+ text_document,
1235
+ work_done_progress_params,
1236
+ partial_result_params,
1237
+ } ,
1238
+ ) ?;
1222
1239
Ok ( ( ) )
1223
1240
}
1224
1241
fn run_event ( & mut self , ev : Event , wid : usize ) -> Result < ( ) > {
@@ -1267,17 +1284,6 @@ impl Server {
1267
1284
} ,
1268
1285
) ?;
1269
1286
}
1270
- "lens" => {
1271
- self . send_request :: < CodeLensRequest > (
1272
- client_name,
1273
- url,
1274
- CodeLensParams {
1275
- text_document,
1276
- work_done_progress_params,
1277
- partial_result_params,
1278
- } ,
1279
- ) ?;
1280
- }
1281
1287
"impl" => {
1282
1288
self . send_request :: < GotoImplementation > (
1283
1289
client_name,
@@ -1372,6 +1378,11 @@ impl Server {
1372
1378
}
1373
1379
panic ! ( "unsupported" ) ;
1374
1380
}
1381
+ Action :: CodeLens ( lens) => {
1382
+ // TODO: rust-analyzer complains about "code lens without data" here. If I set
1383
+ // lens.data to Value::Null, it complains with some resolution error.
1384
+ let _id = self . send_request :: < CodeLensResolve > ( client_name. into ( ) , url, lens) ?;
1385
+ }
1375
1386
}
1376
1387
Ok ( ( ) )
1377
1388
}
0 commit comments