@@ -298,28 +298,42 @@ static int printDiags();
298298
299299static void getSemanticInfo (sourcekitd_variant_t Info, StringRef Filename);
300300
301- static void addCodeCompleteOptions (sourcekitd_object_t Req, TestOptions &Opts) {
301+ static void addRequestOptions (sourcekitd_object_t Req, TestOptions &Opts,
302+ sourcekitd_uid_t Key, StringRef(prefix)) {
302303 if (!Opts.RequestOptions .empty ()) {
303304 sourcekitd_object_t CCOpts =
304305 sourcekitd_request_dictionary_create (nullptr , nullptr , 0 );
305306 for (auto &Opt : Opts.RequestOptions ) {
306307 auto KeyValue = StringRef (Opt).split (' =' );
307- std::string KeyStr (" key.codecomplete. " );
308+ std::string KeyStr (prefix. str () );
308309 KeyStr.append (KeyValue.first .str ());
309310 sourcekitd_uid_t Key = sourcekitd_uid_get_from_cstr (KeyStr.c_str ());
310311
311312 // FIXME: more robust way to determine the option type.
312313 if (KeyValue.first == " filtertext" ) {
313314 sourcekitd_request_dictionary_set_stringbuf (
314315 CCOpts, Key, KeyValue.second .data (), KeyValue.second .size ());
316+ } else if (KeyValue.first == " expectedtypes" ) {
317+ SmallVector<StringRef, 4 > expectedTypeNames;
318+ KeyValue.second .split (expectedTypeNames, ' ;' );
319+
320+ auto typenames = sourcekitd_request_array_create (nullptr , 0 );
321+ for (auto &name : expectedTypeNames) {
322+ std::string n = name.str ();
323+ sourcekitd_request_array_set_string (typenames,
324+ SOURCEKITD_ARRAY_APPEND,
325+ n.c_str ());
326+ }
327+ // NOTE: 'key.expectedtypes' directly to the request.
328+ sourcekitd_request_dictionary_set_value (Req, KeyExpectedTypes,
329+ typenames);
315330 } else {
316331 int64_t Value = 0 ;
317332 KeyValue.second .getAsInteger (0 , Value);
318333 sourcekitd_request_dictionary_set_int64 (CCOpts, Key, Value);
319334 }
320335 }
321- sourcekitd_request_dictionary_set_value (Req, KeyCodeCompleteOptions,
322- CCOpts);
336+ sourcekitd_request_dictionary_set_value (Req, Key, CCOpts);
323337 sourcekitd_request_release (CCOpts);
324338 }
325339}
@@ -444,28 +458,6 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
444458 return 0 ;
445459}
446460
447- static int setExpectedTypes (const sourcekitd_test::TestOptions &Opts,
448- sourcekitd_object_t Req) {
449- for (auto &Opt : Opts.RequestOptions ) {
450- auto KeyValue = StringRef (Opt).split (' =' );
451- if (KeyValue.first == " expectedtypes" ) {
452- SmallVector<StringRef, 4 > expectedTypeNames;
453- KeyValue.second .split (expectedTypeNames, ' ;' );
454-
455- auto typenames = sourcekitd_request_array_create (nullptr , 0 );
456- for (auto &name : expectedTypeNames) {
457- std::string n = name.str ();
458- sourcekitd_request_array_set_string (typenames, SOURCEKITD_ARRAY_APPEND, n.c_str ());
459- }
460- sourcekitd_request_dictionary_set_value (Req, KeyExpectedTypes, typenames);
461- } else {
462- llvm::errs () << " invalid key '" << KeyValue.first << " ' in -req-opts\n " ;
463- return 1 ;
464- }
465- }
466- return 0 ;
467- }
468-
469461static bool sendGlobalConfigRequest () {
470462 TestOptions Opts;
471463 sourcekitd_object_t Req = sourcekitd_request_dictionary_create (nullptr ,
@@ -601,15 +593,15 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
601593 sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
602594 // Default to sort by name.
603595 Opts.RequestOptions .insert (Opts.RequestOptions .begin (), " sort.byname=1" );
604- addCodeCompleteOptions (Req, Opts);
596+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
605597 break ;
606598
607599 case SourceKitRequest::CodeCompleteOpen:
608600 sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
609601 RequestCodeCompleteOpen);
610602 sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
611603 sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
612- addCodeCompleteOptions (Req, Opts);
604+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
613605 break ;
614606
615607 case SourceKitRequest::CodeCompleteClose:
@@ -624,7 +616,7 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
624616 RequestCodeCompleteUpdate);
625617 sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
626618 sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
627- addCodeCompleteOptions (Req, Opts);
619+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
628620 break ;
629621
630622 case SourceKitRequest::CodeCompleteCacheOnDisk:
@@ -673,13 +665,16 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
673665 sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
674666 RequestTypeContextInfo);
675667 sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
668+ addRequestOptions (Req, Opts, KeyTypeContextInfoOptions,
669+ " key.typecontextinfo." );
676670 break ;
677671
678672 case SourceKitRequest::ConformingMethodList:
679673 sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
680674 RequestConformingMethodList);
681675 sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
682- setExpectedTypes (Opts, Req);
676+ addRequestOptions (Req, Opts, KeyConformingMethodListOptions,
677+ " key.conformingmethods." );
683678 break ;
684679
685680 case SourceKitRequest::CursorInfo:
@@ -711,7 +706,10 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
711706
712707 case SourceKitRequest::CollectExpresstionType: {
713708 sourcekitd_request_dictionary_set_uid (Req, KeyRequest, RequestCollectExpressionType);
714- setExpectedTypes (Opts, Req);
709+ // NOTE: KeyCodeCompletion and the prefix are just dummy. This request
710+ // only accepts 'expectedtypes' which is placed to the Req root dictionary.
711+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions,
712+ " key.expression.type." );
715713 break ;
716714 }
717715
0 commit comments