Skip to content

Commit a588d92

Browse files
authored
Merge pull request #204 from ahoppen/6.0/cherry-picks
2 parents 4122238 + 54f9771 commit a588d92

File tree

7 files changed

+106
-80
lines changed

7 files changed

+106
-80
lines changed

Sources/ISDBTestSupport/TestLocation.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ extension SymbolLocation {
6262
extension Symbol {
6363

6464
/// Returns a SymbolOccurrence with the given location and roles.
65-
public func at(_ location: TestLocation, moduleName: String = TestLocation.unknownModuleName, roles: SymbolRole) -> SymbolOccurrence {
66-
return self.at(SymbolLocation(location, moduleName: moduleName), roles: roles)
65+
public func at(_ location: TestLocation, moduleName: String = TestLocation.unknownModuleName, roles: SymbolRole, symbolProvider: SymbolProviderKind) -> SymbolOccurrence {
66+
return self.at(SymbolLocation(location, moduleName: moduleName), symbolProvider: symbolProvider, roles: roles)
6767
}
6868
}
6969

Sources/IndexStoreDB/IndexStoreDB.swift

+14-10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ public struct PathMapping {
3939
public enum SymbolProviderKind {
4040
case clang
4141
case swift
42+
43+
init?(_ cKind: indexstoredb_symbol_provider_kind_t) {
44+
switch cKind {
45+
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT:
46+
self = .swift
47+
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG:
48+
self = .clang
49+
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN:
50+
return nil
51+
default:
52+
preconditionFailure("Unknown enum case in indexstoredb_symbol_provider_kind_t")
53+
}
54+
}
4255
}
4356

4457
/// IndexStoreDB index.
@@ -289,16 +302,7 @@ public final class IndexStoreDB {
289302
public func symbolProvider(for sourceFilePath: String) -> SymbolProviderKind? {
290303
var result: SymbolProviderKind? = nil
291304
indexstoredb_index_units_containing_file(impl, sourceFilePath) { unit in
292-
let providerKind: SymbolProviderKind? = switch indexstoredb_unit_info_symbol_provider_kind(unit) {
293-
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT:
294-
.swift
295-
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG:
296-
.clang
297-
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN:
298-
nil
299-
default:
300-
preconditionFailure("Unknown enum case in indexstoredb_symbol_provider_kind_t")
301-
}
305+
let providerKind = SymbolProviderKind(indexstoredb_unit_info_symbol_provider_kind(unit))
302306

303307
let mainFilePath = String(cString: indexstoredb_unit_info_main_file_path(unit))
304308
if providerKind == .swift && mainFilePath != sourceFilePath {

Sources/IndexStoreDB/Symbol.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ extension Symbol {
110110
}
111111

112112
/// Returns a SymbolOccurrence with the given location and roles.
113-
public func at(_ location: SymbolLocation, roles: SymbolRole) -> SymbolOccurrence {
114-
return SymbolOccurrence(symbol: self, location: location, roles: roles)
113+
public func at(_ location: SymbolLocation, symbolProvider: SymbolProviderKind, roles: SymbolRole) -> SymbolOccurrence {
114+
return SymbolOccurrence(symbol: self, location: location, roles: roles, symbolProvider: symbolProvider)
115115
}
116116
}
117117

Sources/IndexStoreDB/SymbolOccurrence.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ public struct SymbolOccurrence: Equatable {
1717
public var symbol: Symbol
1818
public var location: SymbolLocation
1919
public var roles: SymbolRole
20+
public var symbolProvider: SymbolProviderKind
2021
public var relations: [SymbolRelation]
2122

22-
public init(symbol: Symbol, location: SymbolLocation, roles: SymbolRole, relations: [SymbolRelation] = []) {
23+
public init(symbol: Symbol, location: SymbolLocation, roles: SymbolRole, symbolProvider: SymbolProviderKind, relations: [SymbolRelation] = []) {
2324
self.symbol = symbol
2425
self.location = location
2526
self.roles = roles
27+
self.symbolProvider = symbolProvider
2628
self.relations = relations
2729
}
2830
}
@@ -72,6 +74,8 @@ extension SymbolOccurrence {
7274
symbol: Symbol(indexstoredb_symbol_occurrence_symbol(value)),
7375
location: SymbolLocation(indexstoredb_symbol_occurrence_location(value)),
7476
roles: SymbolRole(rawValue: indexstoredb_symbol_occurrence_roles(value)),
77+
// Force unwrap is OK because `indexstoredb_symbol_occurrence_symbol_provider_kind` never returns `INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN`
78+
symbolProvider: SymbolProviderKind(indexstoredb_symbol_occurrence_symbol_provider_kind(value))!,
7579
relations: relations)
7680
}
7781
}

0 commit comments

Comments
 (0)