@@ -26,7 +26,7 @@ use lsp_types::{
26
26
} ;
27
27
use project_model:: TargetKind ;
28
28
use serde_json:: json;
29
- use stdx:: format_to;
29
+ use stdx:: { format_to, never } ;
30
30
use syntax:: { algo, ast, AstNode , TextRange , TextSize } ;
31
31
32
32
use crate :: {
@@ -1133,41 +1133,53 @@ pub(crate) fn handle_code_lens(
1133
1133
let file_id = from_proto:: file_id ( & snap, & params. text_document . uri ) ?;
1134
1134
let cargo_target_spec = CargoTargetSpec :: for_file ( & snap, file_id) ?;
1135
1135
1136
- let lenses = snap
1137
- . analysis
1138
- . annotations (
1139
- & AnnotationConfig {
1140
- binary_target : cargo_target_spec
1141
- . map ( |spec| {
1142
- matches ! (
1143
- spec. target_kind,
1144
- TargetKind :: Bin | TargetKind :: Example | TargetKind :: Test
1145
- )
1146
- } )
1147
- . unwrap_or ( false ) ,
1148
- annotate_runnables : lens_config. runnable ( ) ,
1149
- annotate_impls : lens_config. implementations ,
1150
- annotate_references : lens_config. refs ,
1151
- annotate_method_references : lens_config. method_refs ,
1152
- run : lens_config. run ,
1153
- debug : lens_config. debug ,
1154
- } ,
1155
- file_id,
1156
- ) ?
1157
- . into_iter ( )
1158
- . map ( |annotation| to_proto:: code_lens ( & snap, annotation) . unwrap ( ) )
1159
- . collect ( ) ;
1136
+ let annotations = snap. analysis . annotations (
1137
+ & AnnotationConfig {
1138
+ binary_target : cargo_target_spec
1139
+ . map ( |spec| {
1140
+ matches ! (
1141
+ spec. target_kind,
1142
+ TargetKind :: Bin | TargetKind :: Example | TargetKind :: Test
1143
+ )
1144
+ } )
1145
+ . unwrap_or ( false ) ,
1146
+ annotate_runnables : lens_config. runnable ( ) ,
1147
+ annotate_impls : lens_config. implementations ,
1148
+ annotate_references : lens_config. refs ,
1149
+ annotate_method_references : lens_config. method_refs ,
1150
+ run : lens_config. run ,
1151
+ debug : lens_config. debug ,
1152
+ } ,
1153
+ file_id,
1154
+ ) ?;
1160
1155
1161
- Ok ( Some ( lenses) )
1156
+ let mut res = Vec :: new ( ) ;
1157
+ for a in annotations {
1158
+ to_proto:: code_lens ( & mut res, & snap, a) ?;
1159
+ }
1160
+
1161
+ Ok ( Some ( res) )
1162
1162
}
1163
1163
1164
1164
pub ( crate ) fn handle_code_lens_resolve (
1165
1165
snap : GlobalStateSnapshot ,
1166
1166
code_lens : CodeLens ,
1167
1167
) -> Result < CodeLens > {
1168
- let annotation = from_proto:: annotation ( & snap, code_lens) ?;
1168
+ let annotation = from_proto:: annotation ( & snap, code_lens. clone ( ) ) ?;
1169
+ let annotation = snap. analysis . resolve_annotation ( annotation) ?;
1170
+
1171
+ let mut acc = Vec :: new ( ) ;
1172
+ to_proto:: code_lens ( & mut acc, & snap, annotation) ?;
1169
1173
1170
- to_proto:: code_lens ( & snap, snap. analysis . resolve_annotation ( annotation) ?)
1174
+ let res = match acc. pop ( ) {
1175
+ Some ( it) if acc. is_empty ( ) => it,
1176
+ _ => {
1177
+ never ! ( ) ;
1178
+ code_lens
1179
+ }
1180
+ } ;
1181
+
1182
+ Ok ( res)
1171
1183
}
1172
1184
1173
1185
pub ( crate ) fn handle_document_highlight (
0 commit comments