Skip to content

Commit 4450b67

Browse files
committed
Remove lsp-specific function
Add discardableResult to new functions. Return Bool in new functions. Make all new variables lowercase. Rename functions to match existing patterns.
1 parent 22bba1f commit 4450b67

File tree

3 files changed

+51
-69
lines changed

3 files changed

+51
-69
lines changed

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ public final class IndexStoreDB {
8181
}
8282
}
8383

84-
public func forEachCanonicalSymbolOccurrenceByName(symbolName: String, body: @escaping (SymbolOccurrence) -> Bool) {
85-
indexstoredb_for_each_canonical_symbol_occurence_by_name(impl, symbolName) { (occur) -> Bool in
86-
body(SymbolOccurrence(occur))
84+
@discardableResult public func forEachCanonicalSymbolOccurrence(byName: String, body: @escaping (SymbolOccurrence) -> Bool) -> Bool {
85+
return indexstoredb_index_canonical_symbol_occurences_by_name(impl, byName) { occur in
86+
return body(SymbolOccurrence(occur))
8787
}
8888
}
8989

90-
public func forEachCanonicalSymbolOccurrence(
90+
@discardableResult public func forEachCanonicalSymbolOccurrence(
9191
containing pattern: String,
9292
anchorStart: Bool,
9393
anchorEnd: Bool,
9494
subsequence: Bool,
9595
ignoreCase: Bool,
9696
body: @escaping (SymbolOccurrence) -> Bool
97-
){
98-
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern(
97+
) -> Bool {
98+
return indexstoredb_index_canonical_symbol_occurences_containing_pattern(
9999
impl,
100100
pattern,
101101
anchorStart,
@@ -107,22 +107,6 @@ public final class IndexStoreDB {
107107
}
108108
}
109109

110-
public func findSymbols(matching query: String) -> [SymbolOccurrence] {
111-
var symbolOccurenceResults: [SymbolOccurrence] = []
112-
forEachCanonicalSymbolOccurrence(
113-
containing: query,
114-
anchorStart: false,
115-
anchorEnd: false,
116-
subsequence: true,
117-
ignoreCase: true
118-
) { (occurence) -> Bool in
119-
if !occurence.location.isSystem {
120-
symbolOccurenceResults.append(occurence)
121-
}
122-
return true
123-
}
124-
return symbolOccurenceResults
125-
}
126110
}
127111

128112
public struct SymbolRole: OptionSet {

include/CIndexStoreDB/CIndexStoreDB.h

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,45 @@ indexstoredb_error_get_description(_Nonnull indexstoredb_error_t);
162162
INDEXSTOREDB_PUBLIC void
163163
indexstoredb_error_dispose(_Nullable indexstoredb_error_t);
164164

165+
/// Loops through each symbol in the index and calls the receiver function with each symbol.
166+
/// @param index An IndexStoreDB object which contains the symbols.
167+
/// @param receiver A function to be called for each symbol, the CString of the symbol will be passed in to this function.
168+
/// The function should return a boolean indicating whether the looping should continue.
165169
INDEXSTOREDB_PUBLIC bool
166-
indexstoredb_for_each_symbol_name(_Nonnull indexstoredb_index_t index, _Nonnull indexstoredb_symbol_name_receiver);
167-
168-
INDEXSTOREDB_PUBLIC bool
169-
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern(
170-
_Nonnull indexstoredb_index_t index,
171-
const char *_Nonnull Pattern,
172-
bool AnchorStart,
173-
bool AnchorEnd,
174-
bool Subsequence,
175-
bool IgnoreCase,
176-
_Nonnull indexstoredb_symbol_occurrence_receiver_t receiver);
177-
178-
170+
indexstoredb_index_symbol_names(_Nonnull indexstoredb_index_t index, _Nonnull indexstoredb_symbol_name_receiver);
171+
172+
/// Loops through each canonical symbol that matches the string and performs the passed in function.
173+
/// @param index An IndexStoreDB object which contains the symbols.
174+
/// @param symbolName The name of the symbol whose canonical occurence should be found.
175+
/// @param receiver A function to be called for each canonical occurence.
176+
/// The SymbolOccurenceRef of the symbol will be passed in to this function.
177+
/// The function should return a boolean indicating whether the looping should continue.
179178
INDEXSTOREDB_PUBLIC bool
180-
indexstoredb_for_each_canonical_symbol_occurence_by_name(
179+
indexstoredb_index_canonical_symbol_occurences_by_name(
181180
indexstoredb_index_t _Nonnull index,
182181
const char *_Nonnull symbolName,
183182
indexstoredb_symbol_occurrence_receiver_t _Nonnull receiver
184183
);
185184

185+
/// Loops through each canonical symbol that matches the pattern and performs the passed in function.
186+
/// @param index An IndexStoreDB object which contains the symbols.
187+
/// @param anchorStart When true, symbol names should only be considered matching when the first characters of the symbol name match the pattern.
188+
/// @param anchorEnd When true, symbol names should only be considered matching when the first characters of the symbol name match the pattern.
189+
/// @param subsequence When true, symbols will be matched even if the pattern is not matched contiguously.
190+
/// @param ignoreCase When true, symbols may be returned even if the case of letters does not match the pattern.
191+
/// @param receiver A function to be called for each canonical occurence that matches the pattern.
192+
/// The SymbolOccurenceRef of the symbol will be passed in to this function.
193+
/// The function should return a boolean indicating whether the looping should continue.
194+
INDEXSTOREDB_PUBLIC bool
195+
indexstoredb_index_canonical_symbol_occurences_containing_pattern(
196+
_Nonnull indexstoredb_index_t index,
197+
const char *_Nonnull pattern,
198+
bool anchorStart,
199+
bool anchorEnd,
200+
bool subsequence,
201+
bool ignoreCase,
202+
_Nonnull indexstoredb_symbol_occurrence_receiver_t receiver);
203+
186204
INDEXSTOREDB_END_DECLS
187205

188206
#endif

lib/CIndexStoreDB/CIndexStoreDB.cpp

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,16 @@ indexstoredb_symbol_name(indexstoredb_symbol_t symbol) {
144144
return obj->value->getName().c_str();
145145
}
146146

147-
/// loops through each symbol in the index and calls the receiver function with each symbol
148-
/// @param index an IndexStoreDB object which contains the symbols
149-
/// @param receiver a function to be called for each symbol, the CString of the symbol will be passed in to this function.
150-
/// The function should return a boolean indicating whether the looping should continue.
151147
bool
152-
indexstoredb_for_each_symbol_name(indexstoredb_index_t index, indexstoredb_symbol_name_receiver receiver) {
153-
// indexSystem has foreachsymbolName.
148+
indexstoredb_index_symbol_names(indexstoredb_index_t index, indexstoredb_symbol_name_receiver receiver) {
154149
auto obj = (IndexStoreDBObject<std::shared_ptr<IndexSystem>> *)index;
155150
return obj->value->foreachSymbolName([&](StringRef ref) -> bool {
156151
return receiver(ref.str().c_str());
157152
});
158153
}
159154

160-
/// loops through each canonical symbol that matches the string, perform the passed in function
161-
/// @param index an IndexStoreDB object which contains the symbols
162-
/// @param symbolName the name of the symbol whose canonical occurence should be found
163-
/// @param receiver a function to be called for each canonical occurence,
164-
/// the SymbolOccurenceRef of the symbol will be passed in to this function.
165-
/// The function should return a boolean indicating whether the looping should continue.
166155
bool
167-
indexstoredb_for_each_canonical_symbol_occurence_by_name(
156+
indexstoredb_index_canonical_symbol_occurences_by_name(
168157
indexstoredb_index_t index,
169158
const char *_Nonnull symbolName,
170159
indexstoredb_symbol_occurrence_receiver_t receiver)
@@ -175,32 +164,23 @@ indexstoredb_for_each_canonical_symbol_occurence_by_name(
175164
});
176165
}
177166

178-
/// loops through each canonical symbol that matches the pattern, perform the passed in function
179-
/// @param index an IndexStoreDB object which contains the symbols.
180-
/// @param AnchorStart when true, symbol names should only be considered matching when the first characters of the symbol name match the pattern.
181-
/// @param AnchorEnd when true, symbol names should only be considered matching when the first characters of the symbol name match the pattern.
182-
/// @param Subsequence when true, symbols will be matched even if the pattern is not matched contiguously.
183-
/// @param IgnoreCase when true, symbols may be returned even if the case of letters does not match the pattern.
184-
/// @param receiver a function to be called for each canonical occurence that matches the pattern.
185-
/// The SymbolOccurenceRef of the symbol will be passed in to this function.
186-
/// The function should return a boolean indicating whether the looping should continue.
187167
bool
188-
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern(
168+
indexstoredb_index_canonical_symbol_occurences_containing_pattern(
189169
indexstoredb_index_t index,
190-
const char *_Nonnull Pattern,
191-
bool AnchorStart,
192-
bool AnchorEnd,
193-
bool Subsequence,
194-
bool IgnoreCase,
170+
const char *_Nonnull pattern,
171+
bool anchorStart,
172+
bool anchorEnd,
173+
bool subsequence,
174+
bool ignoreCase,
195175
indexstoredb_symbol_occurrence_receiver_t receiver)
196176
{
197177
auto obj = (IndexStoreDBObject<std::shared_ptr<IndexSystem>> *)index;
198178
return obj->value->foreachCanonicalSymbolOccurrenceContainingPattern(
199-
Pattern,
200-
AnchorStart,
201-
AnchorEnd,
202-
Subsequence,
203-
IgnoreCase,
179+
pattern,
180+
anchorStart,
181+
anchorEnd,
182+
subsequence,
183+
ignoreCase,
204184
[&](SymbolOccurrenceRef occur
205185
) -> bool {
206186
return receiver(make_object(occur));

0 commit comments

Comments
 (0)