Native: fix cinterop for Swift-produced Objective-C categories

For some reason, libclang's indexer doesn't index categories with
__attribute__((external_source_symbol(language="Swift",...))),
so we have to additionally enumerate them explicitly.

^KT-49455 Fixed
This commit is contained in:
Svyatoslav Scherbina
2022-02-10 17:36:19 +03:00
committed by Space
parent f1623347d8
commit d8b1992fde
4 changed files with 48 additions and 0 deletions
@@ -988,6 +988,13 @@ public open class NativeIndexImpl(val library: NativeLibrary, val verbose: Boole
getObjCProtocolAt(cursor)
}
}
fun indexObjCCategory(cursor: CValue<CXCursor>) {
if (isAvailable(cursor)) {
getObjCCategoryAt(cursor)
}
}
protected open fun String.isUnknownTemplate() = false
private fun getParentName(cursor: CValue<CXCursor>, pkg: List<String> = emptyList()) : String? {
@@ -1225,6 +1232,13 @@ private fun indexDeclarations(nativeIndex: NativeIndexImpl): CompilationWithPCH
when (cursor.kind) {
CXCursorKind.CXCursor_ObjCInterfaceDecl -> nativeIndex.indexObjCClass(cursor)
CXCursorKind.CXCursor_ObjCProtocolDecl -> nativeIndex.indexObjCProtocol(cursor)
CXCursorKind.CXCursor_ObjCCategoryDecl -> {
// This fixes https://youtrack.jetbrains.com/issue/KT-49455, which effectively seems to be a bug in libclang:
// the libclang indexer doesn't properly index categories with
// `__attribute__((external_source_symbol(language="Swift",...)))`.
// As a workaround, additionally enumerate all the categories explicitly.
nativeIndex.indexObjCCategory(cursor)
}
else -> {}
}
}