@@ -18,6 +18,7 @@ use vfs::AbsPath;
1818
1919use crate :: {
2020 cargo_target_spec:: CargoTargetSpec ,
21+ config:: Config ,
2122 global_state:: GlobalStateSnapshot ,
2223 line_index:: { LineEndings , LineIndex , OffsetEncoding } ,
2324 lsp_ext, semantic_tokens, Result ,
@@ -190,32 +191,22 @@ pub(crate) fn snippet_text_edit_vec(
190191}
191192
192193pub ( crate ) fn completion_items (
193- insert_replace_support : bool ,
194- enable_imports_on_the_fly : bool ,
194+ config : & Config ,
195195 line_index : & LineIndex ,
196196 tdpp : lsp_types:: TextDocumentPositionParams ,
197197 items : Vec < CompletionItem > ,
198198) -> Vec < lsp_types:: CompletionItem > {
199199 let max_relevance = items. iter ( ) . map ( |it| it. relevance ( ) . score ( ) ) . max ( ) . unwrap_or_default ( ) ;
200200 let mut res = Vec :: with_capacity ( items. len ( ) ) ;
201201 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)
211203 }
212204 res
213205}
214206
215207fn completion_item (
216208 acc : & mut Vec < lsp_types:: CompletionItem > ,
217- insert_replace_support : bool ,
218- enable_imports_on_the_fly : bool ,
209+ config : & Config ,
219210 line_index : & LineIndex ,
220211 tdpp : & lsp_types:: TextDocumentPositionParams ,
221212 max_relevance : u32 ,
@@ -230,7 +221,7 @@ fn completion_item(
230221 let source_range = item. source_range ( ) ;
231222 for indel in item. text_edit ( ) . iter ( ) {
232223 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 ) ;
234225 text_edit = Some ( if indel. delete == source_range {
235226 self :: completion_text_edit ( line_index, insert_replace_support, indel. clone ( ) )
236227 } else {
@@ -269,14 +260,14 @@ fn completion_item(
269260 lsp_item. tags = Some ( vec ! [ lsp_types:: CompletionItemTag :: Deprecated ] )
270261 }
271262
272- if item. trigger_call_info ( ) {
263+ if item. trigger_call_info ( ) && config . client_commands ( ) . trigger_parameter_hints {
273264 lsp_item. command = Some ( command:: trigger_parameter_hints ( ) ) ;
274265 }
275266
276267 if item. is_snippet ( ) {
277268 lsp_item. insert_text_format = Some ( lsp_types:: InsertTextFormat :: Snippet ) ;
278269 }
279- if enable_imports_on_the_fly {
270+ if config . completion ( ) . enable_imports_on_the_fly {
280271 if let Some ( import_edit) = item. import_to_add ( ) {
281272 let import_path = & import_edit. import . import_path ;
282273 if let Some ( import_name) = import_path. segments ( ) . last ( ) {
@@ -992,6 +983,7 @@ pub(crate) fn code_lens(
992983 snap : & GlobalStateSnapshot ,
993984 annotation : Annotation ,
994985) -> Result < ( ) > {
986+ let client_commands_config = snap. config . client_commands ( ) ;
995987 match annotation. kind {
996988 AnnotationKind :: Runnable ( run) => {
997989 let line_index = snap. file_line_index ( run. nav . file_id ) ?;
@@ -1008,15 +1000,15 @@ pub(crate) fn code_lens(
10081000 let r = runnable ( snap, run) ?;
10091001
10101002 let lens_config = snap. config . lens ( ) ;
1011- if lens_config. run {
1003+ if lens_config. run && client_commands_config . run_single {
10121004 let command = command:: run_single ( & r, & title) ;
10131005 acc. push ( lsp_types:: CodeLens {
10141006 range : annotation_range,
10151007 command : Some ( command) ,
10161008 data : None ,
10171009 } )
10181010 }
1019- if lens_config. debug && can_debug {
1011+ if lens_config. debug && can_debug && client_commands_config . debug_single {
10201012 let command = command:: debug_single ( & r) ;
10211013 acc. push ( lsp_types:: CodeLens {
10221014 range : annotation_range,
@@ -1026,6 +1018,9 @@ pub(crate) fn code_lens(
10261018 }
10271019 }
10281020 AnnotationKind :: HasImpls { position : file_position, data } => {
1021+ if !client_commands_config. show_reference {
1022+ return Ok ( ( ) ) ;
1023+ }
10291024 let line_index = snap. file_line_index ( file_position. file_id ) ?;
10301025 let annotation_range = range ( & line_index, annotation. range ) ;
10311026 let url = url ( snap, file_position. file_id ) ;
@@ -1069,6 +1064,9 @@ pub(crate) fn code_lens(
10691064 } )
10701065 }
10711066 AnnotationKind :: HasReferences { position : file_position, data } => {
1067+ if !client_commands_config. show_reference {
1068+ return Ok ( ( ) ) ;
1069+ }
10721070 let line_index = snap. file_line_index ( file_position. file_id ) ?;
10731071 let annotation_range = range ( & line_index, annotation. range ) ;
10741072 let url = url ( snap, file_position. file_id ) ;
@@ -1207,88 +1205,9 @@ mod tests {
12071205 use std:: sync:: Arc ;
12081206
12091207 use ide:: Analysis ;
1210- use ide_db:: helpers:: {
1211- insert_use:: { ImportGranularity , InsertUseConfig , PrefixKind } ,
1212- SnippetCap ,
1213- } ;
12141208
12151209 use super :: * ;
12161210
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-
12921211 #[ test]
12931212 fn conv_fold_line_folding_only_fixup ( ) {
12941213 let text = r#"mod a;
0 commit comments