@@ -18,6 +18,7 @@ use vfs::AbsPath;
18
18
19
19
use crate :: {
20
20
cargo_target_spec:: CargoTargetSpec ,
21
+ config:: Config ,
21
22
global_state:: GlobalStateSnapshot ,
22
23
line_index:: { LineEndings , LineIndex , OffsetEncoding } ,
23
24
lsp_ext, semantic_tokens, Result ,
@@ -190,32 +191,22 @@ pub(crate) fn snippet_text_edit_vec(
190
191
}
191
192
192
193
pub ( crate ) fn completion_items (
193
- insert_replace_support : bool ,
194
- enable_imports_on_the_fly : bool ,
194
+ config : & Config ,
195
195
line_index : & LineIndex ,
196
196
tdpp : lsp_types:: TextDocumentPositionParams ,
197
197
items : Vec < CompletionItem > ,
198
198
) -> Vec < lsp_types:: CompletionItem > {
199
199
let max_relevance = items. iter ( ) . map ( |it| it. relevance ( ) . score ( ) ) . max ( ) . unwrap_or_default ( ) ;
200
200
let mut res = Vec :: with_capacity ( items. len ( ) ) ;
201
201
for item in items {
202
- completion_item (
203
- & mut res,
204
- insert_replace_support,
205
- enable_imports_on_the_fly,
206
- line_index,
207
- & tdpp,
208
- max_relevance,
209
- item,
210
- )
202
+ completion_item ( & mut res, config, line_index, & tdpp, max_relevance, item)
211
203
}
212
204
res
213
205
}
214
206
215
207
fn completion_item (
216
208
acc : & mut Vec < lsp_types:: CompletionItem > ,
217
- insert_replace_support : bool ,
218
- enable_imports_on_the_fly : bool ,
209
+ config : & Config ,
219
210
line_index : & LineIndex ,
220
211
tdpp : & lsp_types:: TextDocumentPositionParams ,
221
212
max_relevance : u32 ,
@@ -230,7 +221,7 @@ fn completion_item(
230
221
let source_range = item. source_range ( ) ;
231
222
for indel in item. text_edit ( ) . iter ( ) {
232
223
if indel. delete . contains_range ( source_range) {
233
- let insert_replace_support = insert_replace_support. then ( || tdpp. position ) ;
224
+ let insert_replace_support = config . insert_replace_support ( ) . then ( || tdpp. position ) ;
234
225
text_edit = Some ( if indel. delete == source_range {
235
226
self :: completion_text_edit ( line_index, insert_replace_support, indel. clone ( ) )
236
227
} else {
@@ -269,14 +260,14 @@ fn completion_item(
269
260
lsp_item. tags = Some ( vec ! [ lsp_types:: CompletionItemTag :: Deprecated ] )
270
261
}
271
262
272
- if item. trigger_call_info ( ) {
263
+ if item. trigger_call_info ( ) && config . client_commands ( ) . trigger_parameter_hints {
273
264
lsp_item. command = Some ( command:: trigger_parameter_hints ( ) ) ;
274
265
}
275
266
276
267
if item. is_snippet ( ) {
277
268
lsp_item. insert_text_format = Some ( lsp_types:: InsertTextFormat :: Snippet ) ;
278
269
}
279
- if enable_imports_on_the_fly {
270
+ if config . completion ( ) . enable_imports_on_the_fly {
280
271
if let Some ( import_edit) = item. import_to_add ( ) {
281
272
let import_path = & import_edit. import . import_path ;
282
273
if let Some ( import_name) = import_path. segments ( ) . last ( ) {
@@ -992,6 +983,7 @@ pub(crate) fn code_lens(
992
983
snap : & GlobalStateSnapshot ,
993
984
annotation : Annotation ,
994
985
) -> Result < ( ) > {
986
+ let client_commands_config = snap. config . client_commands ( ) ;
995
987
match annotation. kind {
996
988
AnnotationKind :: Runnable ( run) => {
997
989
let line_index = snap. file_line_index ( run. nav . file_id ) ?;
@@ -1008,15 +1000,15 @@ pub(crate) fn code_lens(
1008
1000
let r = runnable ( snap, run) ?;
1009
1001
1010
1002
let lens_config = snap. config . lens ( ) ;
1011
- if lens_config. run {
1003
+ if lens_config. run && client_commands_config . run_single {
1012
1004
let command = command:: run_single ( & r, & title) ;
1013
1005
acc. push ( lsp_types:: CodeLens {
1014
1006
range : annotation_range,
1015
1007
command : Some ( command) ,
1016
1008
data : None ,
1017
1009
} )
1018
1010
}
1019
- if lens_config. debug && can_debug {
1011
+ if lens_config. debug && can_debug && client_commands_config . debug_single {
1020
1012
let command = command:: debug_single ( & r) ;
1021
1013
acc. push ( lsp_types:: CodeLens {
1022
1014
range : annotation_range,
@@ -1026,6 +1018,9 @@ pub(crate) fn code_lens(
1026
1018
}
1027
1019
}
1028
1020
AnnotationKind :: HasImpls { position : file_position, data } => {
1021
+ if !client_commands_config. show_reference {
1022
+ return Ok ( ( ) ) ;
1023
+ }
1029
1024
let line_index = snap. file_line_index ( file_position. file_id ) ?;
1030
1025
let annotation_range = range ( & line_index, annotation. range ) ;
1031
1026
let url = url ( snap, file_position. file_id ) ;
@@ -1069,6 +1064,9 @@ pub(crate) fn code_lens(
1069
1064
} )
1070
1065
}
1071
1066
AnnotationKind :: HasReferences { position : file_position, data } => {
1067
+ if !client_commands_config. show_reference {
1068
+ return Ok ( ( ) ) ;
1069
+ }
1072
1070
let line_index = snap. file_line_index ( file_position. file_id ) ?;
1073
1071
let annotation_range = range ( & line_index, annotation. range ) ;
1074
1072
let url = url ( snap, file_position. file_id ) ;
@@ -1207,88 +1205,9 @@ mod tests {
1207
1205
use std:: sync:: Arc ;
1208
1206
1209
1207
use ide:: Analysis ;
1210
- use ide_db:: helpers:: {
1211
- insert_use:: { ImportGranularity , InsertUseConfig , PrefixKind } ,
1212
- SnippetCap ,
1213
- } ;
1214
1208
1215
1209
use super :: * ;
1216
1210
1217
- #[ test]
1218
- fn test_completion_with_ref ( ) {
1219
- let fixture = r#"
1220
- struct Foo;
1221
- fn foo(arg: &Foo) {}
1222
- fn main() {
1223
- let arg = Foo;
1224
- foo($0)
1225
- }"# ;
1226
-
1227
- let ( offset, text) = test_utils:: extract_offset ( fixture) ;
1228
- let line_index = LineIndex {
1229
- index : Arc :: new ( ide:: LineIndex :: new ( & text) ) ,
1230
- endings : LineEndings :: Unix ,
1231
- encoding : OffsetEncoding :: Utf16 ,
1232
- } ;
1233
- let ( analysis, file_id) = Analysis :: from_single_file ( text) ;
1234
-
1235
- let file_position = ide_db:: base_db:: FilePosition { file_id, offset } ;
1236
- let mut items = analysis
1237
- . completions (
1238
- & ide:: CompletionConfig {
1239
- enable_postfix_completions : true ,
1240
- enable_imports_on_the_fly : true ,
1241
- enable_self_on_the_fly : true ,
1242
- add_call_parenthesis : true ,
1243
- add_call_argument_snippets : true ,
1244
- snippet_cap : SnippetCap :: new ( true ) ,
1245
- insert_use : InsertUseConfig {
1246
- granularity : ImportGranularity :: Item ,
1247
- prefix_kind : PrefixKind :: Plain ,
1248
- enforce_granularity : true ,
1249
- group : true ,
1250
- skip_glob_imports : true ,
1251
- } ,
1252
- } ,
1253
- file_position,
1254
- )
1255
- . unwrap ( )
1256
- . unwrap ( ) ;
1257
- items. retain ( |c| c. label ( ) . ends_with ( "arg" ) ) ;
1258
- let items = completion_items (
1259
- false ,
1260
- false ,
1261
- & line_index,
1262
- lsp_types:: TextDocumentPositionParams {
1263
- text_document : lsp_types:: TextDocumentIdentifier {
1264
- uri : "file://main.rs" . parse ( ) . unwrap ( ) ,
1265
- } ,
1266
- position : position ( & line_index, file_position. offset ) ,
1267
- } ,
1268
- items,
1269
- ) ;
1270
- let items: Vec < ( String , Option < String > ) > =
1271
- items. into_iter ( ) . map ( |c| ( c. label , c. sort_text ) ) . collect ( ) ;
1272
-
1273
- expect_test:: expect![ [ r#"
1274
- [
1275
- (
1276
- "&arg",
1277
- Some(
1278
- "fffffff9",
1279
- ),
1280
- ),
1281
- (
1282
- "arg",
1283
- Some(
1284
- "fffffffd",
1285
- ),
1286
- ),
1287
- ]
1288
- "# ] ]
1289
- . assert_debug_eq ( & items) ;
1290
- }
1291
-
1292
1211
#[ test]
1293
1212
fn conv_fold_line_folding_only_fixup ( ) {
1294
1213
let text = r#"mod a;
0 commit comments