Skip to content

Commit cdef2d9

Browse files
committed
Add support for UID arrays to sourcekitd API
1 parent 71a34ff commit cdef2d9

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

tools/SourceKit/tools/sourcekitd/include/sourcekitd/Internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class ResponseBuilder {
8383
void set(SourceKit::UIdent Key, int64_t val);
8484
void set(SourceKit::UIdent Key, llvm::ArrayRef<llvm::StringRef> Strs);
8585
void set(SourceKit::UIdent Key, llvm::ArrayRef<std::string> Strs);
86+
void set(SourceKit::UIdent Key, llvm::ArrayRef<SourceKit::UIdent> UIDs);
87+
void set(SourceKit::UIdent Key, llvm::ArrayRef<sourcekitd_uid_t> UIDs);
8688
void setBool(SourceKit::UIdent Key, bool val);
8789
Array setArray(SourceKit::UIdent Key);
8890
Dictionary setDictionary(SourceKit::UIdent Key);

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,11 @@ static void fillDictionaryForDiagnosticInfoBase(
28282828
Elem.set(KeyID, Info.ID);
28292829

28302830
if (!Info.Categories.empty()) {
2831-
SmallVector<sourcekitd_uid_t, 1> CategoryUIDs;
2831+
SmallVector<SourceKit::UIdent, 1> CategoryUIDs;
2832+
2833+
static UIdent UIDKindDiagDeprecation(KindDiagDeprecation.str());
2834+
static UIdent UIDKindDiagNoUsage(KindDiagNoUsage.str());
2835+
28322836
for (auto C : Info.Categories) {
28332837
switch (C) {
28342838
case DiagnosticCategory::Deprecation:

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-InProc.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,24 @@ void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
660660
static_cast<SKDObject *>(Impl)->set(SKDUIDFromUIdent(Key), ArrayObject);
661661
}
662662

663+
void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
664+
ArrayRef<SourceKit::UIdent> UIDs) {
665+
auto ArrayObject = new SKDArray();
666+
for (auto UID : UIDs) {
667+
ArrayObject->set(SOURCEKITD_ARRAY_APPEND, new SKDUID(SKDUIDFromUIdent(UID)));
668+
}
669+
static_cast<SKDObject *>(Impl)->set(SKDUIDFromUIdent(Key), ArrayObject);
670+
}
671+
672+
void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
673+
ArrayRef<sourcekitd_uid_t> UIDs) {
674+
auto ArrayObject = new SKDArray();
675+
for (auto UID : UIDs) {
676+
ArrayObject->set(SOURCEKITD_ARRAY_APPEND, new SKDUID(UID));
677+
}
678+
static_cast<SKDObject *>(Impl)->set(SKDUIDFromUIdent(Key), ArrayObject);
679+
}
680+
663681
void ResponseBuilder::Dictionary::setBool(UIdent Key, bool Val) {
664682
static_cast<SKDObject *>(Impl)->set(SKDUIDFromUIdent(Key), new SKDBool(Val));
665683
}

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-XPC.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@ void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
237237
xpc_release(arr);
238238
}
239239

240+
void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
241+
ArrayRef<SourceKit::UIdent> UIDs) {
242+
llvm::SmallString<128> Buf;
243+
xpc_object_t arr = xpc_array_create(nullptr, 0);
244+
for (auto UID : UIDs) {
245+
Buf = Str;
246+
xpc_array_set_uint64(arr, XPC_ARRAY_APPEND, uintptr_t(SKDUIDFromUIdent(UID)));
247+
}
248+
xpc_dictionary_set_value(Impl, Key.c_str(), arr);
249+
xpc_release(arr);
250+
}
251+
252+
void ResponseBuilder::Dictionary::set(SourceKit::UIdent Key,
253+
ArrayRef<sourcekitd_uid_t> UIDs) {
254+
llvm::SmallString<128> Buf;
255+
xpc_object_t arr = xpc_array_create(nullptr, 0);
256+
for (auto UID : UIDs) {
257+
Buf = Str;
258+
xpc_array_set_uint64(arr, XPC_ARRAY_APPEND, uintptr_t(UID));
259+
}
260+
xpc_dictionary_set_value(Impl, Key.c_str(), arr);
261+
xpc_release(arr);
262+
}
263+
240264
void ResponseBuilder::Dictionary::setBool(UIdent Key, bool val) {
241265
xpc_dictionary_set_bool(Impl, Key.c_str(), val);
242266
}

0 commit comments

Comments
 (0)