Skip to content

Expose the name of every symbol in the index #74

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 3 commits into from
Mar 13, 2020
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
21 changes: 21 additions & 0 deletions Sources/IndexStoreDB/IndexStoreDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ public final class IndexStoreDB {
}
return result
}

/// Iterates over the name of every symbol in the index.
///
/// - Parameter body: A closure to be called for each symbol. The closure should return true to
/// continue iterating.
@discardableResult
public func forEachSymbolName(body: @escaping (String) -> Bool) -> Bool {
return indexstoredb_index_symbol_names(impl) { name in
body(String(cString: name))
}
}

/// Returns an array with every symbol name in the index.
public func allSymbolNames() -> [String] {
var result: [String] = []
forEachSymbolName { name in
result.append(name)
return true
}
return result
}
}

public protocol IndexStoreLibraryProvider {
Expand Down
10 changes: 10 additions & 0 deletions Tests/IndexStoreDBTests/IndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,14 @@ final class IndexTests: XCTestCase {
XCTAssertEqual(mainFiles(unknown, true), [])
XCTAssertEqual(mainFiles(unknown, false), [])
}

func testAllSymbolNames() throws {
guard let ws = try staticTibsTestWorkspace(name: "proj1") else { return }
try ws.buildAndIndex()
let index = ws.index

let expectedSymbolNames = ["a()", "b()", "c()"]

XCTAssertEqual(index.allSymbolNames(), expectedSymbolNames)
}
}
1 change: 1 addition & 0 deletions Tests/IndexStoreDBTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension IndexTests {
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__IndexTests = [
("testAllSymbolNames", testAllSymbolNames),
("testBasic", testBasic),
("testDelegate", testDelegate),
("testEditsSimple", testEditsSimple),
Expand Down