Skip to content

Commit b99f773

Browse files
authored
Merge pull request #74 from emixb/master
Expose the name of every symbol in the index
2 parents 591de07 + f575574 commit b99f773

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ public final class IndexStoreDB {
187187
}
188188
return result
189189
}
190+
191+
/// Iterates over the name of every symbol in the index.
192+
///
193+
/// - Parameter body: A closure to be called for each symbol. The closure should return true to
194+
/// continue iterating.
195+
@discardableResult
196+
public func forEachSymbolName(body: @escaping (String) -> Bool) -> Bool {
197+
return indexstoredb_index_symbol_names(impl) { name in
198+
body(String(cString: name))
199+
}
200+
}
201+
202+
/// Returns an array with every symbol name in the index.
203+
public func allSymbolNames() -> [String] {
204+
var result: [String] = []
205+
forEachSymbolName { name in
206+
result.append(name)
207+
return true
208+
}
209+
return result
210+
}
190211
}
191212

192213
public protocol IndexStoreLibraryProvider {

Tests/IndexStoreDBTests/IndexTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,14 @@ final class IndexTests: XCTestCase {
279279
XCTAssertEqual(mainFiles(unknown, true), [])
280280
XCTAssertEqual(mainFiles(unknown, false), [])
281281
}
282+
283+
func testAllSymbolNames() throws {
284+
guard let ws = try staticTibsTestWorkspace(name: "proj1") else { return }
285+
try ws.buildAndIndex()
286+
let index = ws.index
287+
288+
let expectedSymbolNames = ["a()", "b()", "c()"]
289+
290+
XCTAssertEqual(index.allSymbolNames(), expectedSymbolNames)
291+
}
282292
}

Tests/IndexStoreDBTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extension IndexTests {
1616
// `swift test --generate-linuxmain`
1717
// to regenerate.
1818
static let __allTests__IndexTests = [
19+
("testAllSymbolNames", testAllSymbolNames),
1920
("testBasic", testBasic),
2021
("testDelegate", testDelegate),
2122
("testEditsSimple", testEditsSimple),

0 commit comments

Comments
 (0)