[SourceKit] Add mechanism to load plugins for request handling into SourceKit

This allows us to load plugins into the sourcekitd service to handle requests (currently only used for code completion). This allows us to implement parts of sourcekitd in Swift and outside of the compiler repository, making it easier to iterated on them because the compiler doesn’t need to be rebuilt.
This commit is contained in:
Alex Hoppen
2025-01-03 14:04:21 +01:00
parent ed2f43e67d
commit b6c94aecc3
37 changed files with 3100 additions and 142 deletions

View File

@@ -59,14 +59,14 @@ public:
static bool
apply(sourcekitd_uid_t Kind, unsigned Offset, unsigned Length,
const char *USR,
llvm::function_ref<bool(sourcekitd_uid_t, sourcekitd_variant_t)>
applier) {
sourcekitd_variant_dictionary_applier_f_t applier,
void *context) {
#define APPLY(K, Ty, Field) \
do { \
sourcekitd_uid_t key = SKDUIDFromUIdent(K); \
sourcekitd_variant_t var = make##Ty##Variant(Field); \
if (!applier(key, var)) \
if (!applier(key, var, context)) \
return false; \
} while (0)
@@ -133,8 +133,8 @@ struct CompactVariantFuncs<DeclarationsArray> {
static bool dictionary_apply(
sourcekitd_variant_t dict,
llvm::function_ref<bool(sourcekitd_uid_t, sourcekitd_variant_t)>
applier) {
sourcekitd_variant_dictionary_applier_f_t applier,
void *context) {
void *Buf = (void *)dict.data[1];
size_t Index = dict.data[2];
@@ -143,7 +143,8 @@ struct CompactVariantFuncs<DeclarationsArray> {
unsigned Length;
const char *USR;
DeclarationsArray::readElements(Buf, Index, Kind, Offset, Length, USR);
return DeclarationsArray::apply(Kind, Offset, Length, USR, applier);
return DeclarationsArray::apply(Kind, Offset, Length, USR, applier,
context);
}
static int64_t dictionary_get_int64(sourcekitd_variant_t dict,
@@ -171,14 +172,17 @@ VariantFunctions CompactVariantFuncs<DeclarationsArray>::Funcs = {
get_type,
nullptr /*Annot_array_apply*/,
nullptr /*Annot_array_get_bool*/,
nullptr /*Annot_array_get_double*/,
nullptr /*Annot_array_get_count*/,
nullptr /*Annot_array_get_int64*/,
nullptr /*Annot_array_get_string*/,
nullptr /*Annot_array_get_uid*/,
nullptr /*Annot_array_get_value*/,
nullptr /*Annot_bool_get_value*/,
nullptr /*Annot_double_get_value*/,
dictionary_apply,
nullptr /*Annot_dictionary_get_bool*/,
nullptr /*Annot_dictionary_get_double*/,
dictionary_get_int64,
dictionary_get_string,
nullptr /*Annot_dictionary_get_value*/,