@@ -298,28 +298,42 @@ static int printDiags();
298
298
299
299
static void getSemanticInfo (sourcekitd_variant_t Info, StringRef Filename);
300
300
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)) {
302
303
if (!Opts.RequestOptions .empty ()) {
303
304
sourcekitd_object_t CCOpts =
304
305
sourcekitd_request_dictionary_create (nullptr , nullptr , 0 );
305
306
for (auto &Opt : Opts.RequestOptions ) {
306
307
auto KeyValue = StringRef (Opt).split (' =' );
307
- std::string KeyStr (" key.codecomplete. " );
308
+ std::string KeyStr (prefix. str () );
308
309
KeyStr.append (KeyValue.first .str ());
309
310
sourcekitd_uid_t Key = sourcekitd_uid_get_from_cstr (KeyStr.c_str ());
310
311
311
312
// FIXME: more robust way to determine the option type.
312
313
if (KeyValue.first == " filtertext" ) {
313
314
sourcekitd_request_dictionary_set_stringbuf (
314
315
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);
315
330
} else {
316
331
int64_t Value = 0 ;
317
332
KeyValue.second .getAsInteger (0 , Value);
318
333
sourcekitd_request_dictionary_set_int64 (CCOpts, Key, Value);
319
334
}
320
335
}
321
- sourcekitd_request_dictionary_set_value (Req, KeyCodeCompleteOptions,
322
- CCOpts);
336
+ sourcekitd_request_dictionary_set_value (Req, Key, CCOpts);
323
337
sourcekitd_request_release (CCOpts);
324
338
}
325
339
}
@@ -444,28 +458,6 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
444
458
return 0 ;
445
459
}
446
460
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
-
469
461
static bool sendGlobalConfigRequest () {
470
462
TestOptions Opts;
471
463
sourcekitd_object_t Req = sourcekitd_request_dictionary_create (nullptr ,
@@ -601,15 +593,15 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
601
593
sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
602
594
// Default to sort by name.
603
595
Opts.RequestOptions .insert (Opts.RequestOptions .begin (), " sort.byname=1" );
604
- addCodeCompleteOptions (Req, Opts);
596
+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
605
597
break ;
606
598
607
599
case SourceKitRequest::CodeCompleteOpen:
608
600
sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
609
601
RequestCodeCompleteOpen);
610
602
sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
611
603
sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
612
- addCodeCompleteOptions (Req, Opts);
604
+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
613
605
break ;
614
606
615
607
case SourceKitRequest::CodeCompleteClose:
@@ -624,7 +616,7 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
624
616
RequestCodeCompleteUpdate);
625
617
sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
626
618
sourcekitd_request_dictionary_set_string (Req, KeyName, SemaName.c_str ());
627
- addCodeCompleteOptions (Req, Opts);
619
+ addRequestOptions (Req, Opts, KeyCodeCompleteOptions, " key.codecomplete. " );
628
620
break ;
629
621
630
622
case SourceKitRequest::CodeCompleteCacheOnDisk:
@@ -673,13 +665,16 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
673
665
sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
674
666
RequestTypeContextInfo);
675
667
sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
668
+ addRequestOptions (Req, Opts, KeyTypeContextInfoOptions,
669
+ " key.typecontextinfo." );
676
670
break ;
677
671
678
672
case SourceKitRequest::ConformingMethodList:
679
673
sourcekitd_request_dictionary_set_uid (Req, KeyRequest,
680
674
RequestConformingMethodList);
681
675
sourcekitd_request_dictionary_set_int64 (Req, KeyOffset, ByteOffset);
682
- setExpectedTypes (Opts, Req);
676
+ addRequestOptions (Req, Opts, KeyConformingMethodListOptions,
677
+ " key.conformingmethods." );
683
678
break ;
684
679
685
680
case SourceKitRequest::CursorInfo:
@@ -711,7 +706,10 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
711
706
712
707
case SourceKitRequest::CollectExpresstionType: {
713
708
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." );
715
713
break ;
716
714
}
717
715
0 commit comments