feat: Fallback to swiftmodule interface when index lookup fails for definition

Currently, `indexBasedDefinition` relies heavily on IndexStoreDB. If a symbol
belongs to a binary framework or a library that hasn't been indexed (but has
module info provided by sourcekitd), the definition request fails or returns
empty results.

This change adds a fallback mechanism in `definitionLocations`. When no
occurrences are found in the index, we check if `systemModule` information
is available on the symbol. If so, we trigger `definitionInInterface` to
generate the textual interface (via `editor.open.interface`) and return that
location.

This improves navigation for binary dependencies (XCFrameworks) and SDKs
partially covered by the index.
This commit is contained in:
lijunliang.9819
2025-12-31 13:07:18 +08:00
parent 7495f5532f
commit c40476c191

View File

@@ -2027,8 +2027,23 @@ extension SourceKitLSPServer {
}
}
if occurrences.isEmpty, let bestLocalDeclaration = symbol.bestLocalDeclaration {
return [bestLocalDeclaration]
if occurrences.isEmpty {
if let bestLocalDeclaration = symbol.bestLocalDeclaration {
return [bestLocalDeclaration]
}
// Fallback: The symbol was not found in the index. This often happens with
// third-party binary frameworks or libraries where indexing data is missing.
// If module info is available, fallback to generating the textual interface.
if let systemModule = symbol.systemModule {
let location = try await self.definitionInInterface(
moduleName: systemModule.moduleName,
groupName: systemModule.groupName,
symbolUSR: symbol.usr,
originatorUri: uri,
languageService: languageService
)
return [location]
}
}
return occurrences.compactMap { indexToLSPLocation($0.location) }.sorted()