Skip to content

Expose the symbol provider of a SymbolOccurrence via the Swift API #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/ISDBTestSupport/TestLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ extension SymbolLocation {
extension Symbol {

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

Expand Down
24 changes: 14 additions & 10 deletions Sources/IndexStoreDB/IndexStoreDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public struct PathMapping {
public enum SymbolProviderKind {
case clang
case swift

init?(_ cKind: indexstoredb_symbol_provider_kind_t) {
switch cKind {
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT:
self = .swift
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG:
self = .clang
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN:
return nil
default:
preconditionFailure("Unknown enum case in indexstoredb_symbol_provider_kind_t")
}
}
}

/// IndexStoreDB index.
Expand Down Expand Up @@ -289,16 +302,7 @@ public final class IndexStoreDB {
public func symbolProvider(for sourceFilePath: String) -> SymbolProviderKind? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this API was added for what's now using the provider from the occurrence instead, should we just remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(#177)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll remove it in a follow-up PR.

var result: SymbolProviderKind? = nil
indexstoredb_index_units_containing_file(impl, sourceFilePath) { unit in
let providerKind: SymbolProviderKind? = switch indexstoredb_unit_info_symbol_provider_kind(unit) {
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT:
.swift
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG:
.clang
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN:
nil
default:
preconditionFailure("Unknown enum case in indexstoredb_symbol_provider_kind_t")
}
let providerKind = SymbolProviderKind(indexstoredb_unit_info_symbol_provider_kind(unit))

let mainFilePath = String(cString: indexstoredb_unit_info_main_file_path(unit))
if providerKind == .swift && mainFilePath != sourceFilePath {
Expand Down
4 changes: 2 additions & 2 deletions Sources/IndexStoreDB/Symbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ extension Symbol {
}

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

Expand Down
6 changes: 5 additions & 1 deletion Sources/IndexStoreDB/SymbolOccurrence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public struct SymbolOccurrence: Equatable {
public var symbol: Symbol
public var location: SymbolLocation
public var roles: SymbolRole
public var symbolProvider: SymbolProviderKind
public var relations: [SymbolRelation]

public init(symbol: Symbol, location: SymbolLocation, roles: SymbolRole, relations: [SymbolRelation] = []) {
public init(symbol: Symbol, location: SymbolLocation, roles: SymbolRole, symbolProvider: SymbolProviderKind, relations: [SymbolRelation] = []) {
self.symbol = symbol
self.location = location
self.roles = roles
self.symbolProvider = symbolProvider
self.relations = relations
}
}
Expand Down Expand Up @@ -72,6 +74,8 @@ extension SymbolOccurrence {
symbol: Symbol(indexstoredb_symbol_occurrence_symbol(value)),
location: SymbolLocation(indexstoredb_symbol_occurrence_location(value)),
roles: SymbolRole(rawValue: indexstoredb_symbol_occurrence_roles(value)),
// Force unwrap is OK because `indexstoredb_symbol_occurrence_symbol_provider_kind` never returns `INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN`
symbolProvider: SymbolProviderKind(indexstoredb_symbol_occurrence_symbol_provider_kind(value))!,
relations: relations)
}
}
Expand Down
Loading