@@ -170,6 +170,16 @@ struct NotificationBuffer {
170
170
};
171
171
static NotificationBuffer notificationBuffer;
172
172
173
+ static void printRawResponse (sourcekitd_response_t resp) {
174
+ llvm::outs ().flush ();
175
+ sourcekitd_response_description_dump_filedesc (resp, STDOUT_FILENO);
176
+ }
177
+
178
+ static void printRawVariant (sourcekitd_variant_t obj) {
179
+ llvm::outs ().flush ();
180
+ sourcekitd_variant_description_dump_filedesc (obj, STDOUT_FILENO);
181
+ }
182
+
173
183
static void syncNotificationsWithService () {
174
184
// Send TestNotification request, then wait for the notification. This ensures
175
185
// that all notifications previously posted on the service side have been
@@ -192,9 +202,8 @@ static void printBufferedNotifications(bool syncWithService = true) {
192
202
if (syncWithService) {
193
203
syncNotificationsWithService ();
194
204
}
195
- notificationBuffer.handleNotifications ([](sourcekitd_response_t note) {
196
- sourcekitd_response_description_dump_filedesc (note, STDOUT_FILENO);
197
- });
205
+ notificationBuffer.handleNotifications (
206
+ [](sourcekitd_response_t note) { printRawResponse (note); });
198
207
}
199
208
200
209
struct skt_args {
@@ -443,7 +452,7 @@ static int handleJsonRequestPath(StringRef QueryPath, const TestOptions &Opts) {
443
452
sourcekitd_response_t Resp = sendRequestSync (Req, Opts);
444
453
auto Error = sourcekitd_response_is_error (Resp);
445
454
if (Opts.PrintResponse ) {
446
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
455
+ printRawResponse (Resp);
447
456
}
448
457
return Error ? 1 : 0 ;
449
458
}
@@ -1256,7 +1265,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1256
1265
free (json);
1257
1266
1258
1267
} else if (Opts.PrintRawResponse ) {
1259
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
1268
+ printRawResponse (Resp);
1260
1269
1261
1270
} else {
1262
1271
sourcekitd_variant_t Info = sourcekitd_response_get_value (Resp);
@@ -1279,7 +1288,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1279
1288
case SourceKitRequest::Edit:
1280
1289
if (Opts.Length == 0 && Opts.ReplaceText ->empty ()) {
1281
1290
// Length=0, replace="" is a nop and will not trigger sema.
1282
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
1291
+ printRawResponse (Resp);
1283
1292
} else {
1284
1293
getSemanticInfo (Info, SourceFile);
1285
1294
KeepResponseAlive = true ;
@@ -1309,7 +1318,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1309
1318
case SourceKitRequest::ConformingMethodList:
1310
1319
case SourceKitRequest::DependencyUpdated:
1311
1320
case SourceKitRequest::Diagnostics:
1312
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
1321
+ printRawResponse (Resp);
1313
1322
break ;
1314
1323
1315
1324
case SourceKitRequest::RelatedIdents:
@@ -1380,7 +1389,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1380
1389
}
1381
1390
case SourceKitRequest::SyntaxMap:
1382
1391
case SourceKitRequest::Structure:
1383
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
1392
+ printRawResponse (Resp);
1384
1393
if (Opts.ReplaceText .hasValue ()) {
1385
1394
unsigned Offset =
1386
1395
resolveFromLineCol (Opts.Line , Opts.Col , SourceFile, Opts.VFSFiles );
@@ -1405,7 +1414,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1405
1414
!Opts.UsedSema );
1406
1415
1407
1416
sourcekitd_response_t EdResp = sendRequestSync (EdReq, Opts);
1408
- sourcekitd_response_description_dump_filedesc (EdResp, STDOUT_FILENO );
1417
+ printRawResponse (EdResp);
1409
1418
sourcekitd_response_dispose (EdResp);
1410
1419
sourcekitd_request_release (EdReq);
1411
1420
}
@@ -1440,7 +1449,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1440
1449
}
1441
1450
1442
1451
sourcekitd_response_t FmtResp = sendRequestSync (Fmt, Opts);
1443
- sourcekitd_response_description_dump_filedesc (FmtResp, STDOUT_FILENO );
1452
+ printRawResponse (FmtResp);
1444
1453
sourcekitd_response_dispose (FmtResp);
1445
1454
sourcekitd_request_release (Fmt);
1446
1455
}
@@ -1449,7 +1458,7 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
1449
1458
case SourceKitRequest::ExpandPlaceholder:
1450
1459
if (Opts.Length ) {
1451
1460
// Single placeholder by location.
1452
- sourcekitd_response_description_dump_filedesc (Resp, STDOUT_FILENO );
1461
+ printRawResponse (Resp);
1453
1462
} else {
1454
1463
// Expand all placeholders.
1455
1464
expandPlaceholders (SourceBuf.get (), llvm::outs ());
@@ -1523,13 +1532,12 @@ static void getSemanticInfo(sourcekitd_variant_t Info, StringRef Filename) {
1523
1532
}
1524
1533
1525
1534
static int printAnnotations () {
1526
- sourcekitd_variant_description_dump_filedesc (LatestSemaAnnotations,
1527
- STDOUT_FILENO);
1535
+ printRawVariant (LatestSemaAnnotations);
1528
1536
return 0 ;
1529
1537
}
1530
1538
1531
1539
static int printDiags () {
1532
- sourcekitd_variant_description_dump_filedesc (LatestSemaDiags, STDOUT_FILENO );
1540
+ printRawVariant (LatestSemaDiags);
1533
1541
return 0 ;
1534
1542
}
1535
1543
@@ -2106,16 +2114,14 @@ static void printFoundUSR(sourcekitd_variant_t Info,
2106
2114
static void printNormalizedDocComment (sourcekitd_variant_t Info) {
2107
2115
sourcekitd_variant_t Source =
2108
2116
sourcekitd_variant_dictionary_get_value (Info, KeySourceText);
2109
- sourcekitd_variant_description_dump_filedesc (Source, STDOUT_FILENO );
2117
+ printRawVariant (Source);
2110
2118
}
2111
2119
2112
2120
static void printDocInfo (sourcekitd_variant_t Info, StringRef Filename) {
2113
2121
const char *text =
2114
2122
sourcekitd_variant_dictionary_get_string (Info, KeySourceText);
2115
- llvm::raw_fd_ostream OS (STDOUT_FILENO, /* shouldClose=*/ false );
2116
2123
if (text) {
2117
- OS << text << ' \n ' ;
2118
- OS.flush ();
2124
+ llvm::outs () << text << ' \n ' ;
2119
2125
}
2120
2126
2121
2127
sourcekitd_variant_t annotations =
@@ -2126,11 +2132,11 @@ static void printDocInfo(sourcekitd_variant_t Info, StringRef Filename) {
2126
2132
sourcekitd_variant_t diags =
2127
2133
sourcekitd_variant_dictionary_get_value (Info, KeyDiagnostics);
2128
2134
2129
- sourcekitd_variant_description_dump_filedesc (annotations, STDOUT_FILENO );
2130
- sourcekitd_variant_description_dump_filedesc (entities, STDOUT_FILENO );
2135
+ printRawVariant (annotations);
2136
+ printRawVariant (entities);
2131
2137
2132
2138
if (sourcekitd_variant_get_type (diags) != SOURCEKITD_VARIANT_TYPE_NULL)
2133
- sourcekitd_variant_description_dump_filedesc (diags, STDOUT_FILENO );
2139
+ printRawVariant (diags);
2134
2140
}
2135
2141
2136
2142
static void checkTextIsASCII (const char *Text) {
@@ -2278,8 +2284,7 @@ static void printInterfaceGen(sourcekitd_variant_t Info, bool CheckASCII) {
2278
2284
sourcekitd_variant_dictionary_get_string (Info, KeySourceText);
2279
2285
2280
2286
if (text) {
2281
- llvm::raw_fd_ostream OS (STDOUT_FILENO, /* shouldClose=*/ false );
2282
- OS << text << ' \n ' ;
2287
+ llvm::outs () << text << ' \n ' ;
2283
2288
}
2284
2289
2285
2290
if (CheckASCII) {
@@ -2288,13 +2293,13 @@ static void printInterfaceGen(sourcekitd_variant_t Info, bool CheckASCII) {
2288
2293
2289
2294
sourcekitd_variant_t syntaxmap =
2290
2295
sourcekitd_variant_dictionary_get_value (Info, KeySyntaxMap);
2291
- sourcekitd_variant_description_dump_filedesc (syntaxmap, STDOUT_FILENO );
2296
+ printRawVariant (syntaxmap);
2292
2297
sourcekitd_variant_t annotations =
2293
2298
sourcekitd_variant_dictionary_get_value (Info, KeyAnnotations);
2294
- sourcekitd_variant_description_dump_filedesc (annotations, STDOUT_FILENO );
2299
+ printRawVariant (annotations);
2295
2300
sourcekitd_variant_t structure =
2296
2301
sourcekitd_variant_dictionary_get_value (Info, KeySubStructure);
2297
- sourcekitd_variant_description_dump_filedesc (structure, STDOUT_FILENO );
2302
+ printRawVariant (structure);
2298
2303
}
2299
2304
2300
2305
static void printRelatedIdents (sourcekitd_variant_t Info, StringRef Filename,
0 commit comments