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
Add ability to find symbols by name #29
Conversation
fa6a230
to
c281bec
Compare
I've created a (WIP) branch in the sourcekit-lsp project with that side of this change. |
This can be used in lsp projects to find all symbols in a workspace that match a string. https://bugs.swift.org/browse/SR-10806
c281bec
to
313cc12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this and exposing more APIs to Swift! I've made some suggestions for changes.
@@ -80,6 +80,49 @@ public final class IndexStoreDB { | |||
return body(SymbolOccurrence(occur)) | |||
} | |||
} | |||
|
|||
public func forEachCanonicalSymbolOccurrenceByName(symbolName: String, body: @escaping (SymbolOccurrence) -> Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the name forEachCanonicalSymbolOccurrence(byName:body:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also return Bool
and have @discardableResult
like the other functions. Same with forEachCanonicalSymbolOccurrence
.
/// @param index an IndexStoreDB object which contains the symbols | ||
/// @param receiver a function to be called for each symbol, the CString of the symbol will be passed in to this function. | ||
/// The function should return a boolean indicating whether the looping should continue. | ||
bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comments should go in the header, not the .cpp file. Please capitalize the first word as well. Same for the other functions.
} | ||
} | ||
|
||
public func findSymbols(matching query: String) -> [SymbolOccurrence] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method seems like it's fairly specific to what you want to do in sourcekit-lsp and the name doesn't make it clear what it's doing (e.g. skipping system occurrences?). I suggest we remove it from the index API and just call forEachCanonicalSymbolOccurrence(containing:...)
from sourcekit-lsp
.
lib/CIndexStoreDB/CIndexStoreDB.cpp
Outdated
bool | ||
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern( | ||
indexstoredb_index_t index, | ||
const char *_Nonnull Pattern, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new C++ code, let's stick to lowerCamelCase names in variables. This applies to the other function parameters as well.
indexstoredb_for_each_symbol_name(_Nonnull indexstoredb_index_t index, _Nonnull indexstoredb_symbol_name_receiver); | ||
|
||
INDEXSTOREDB_PUBLIC bool | ||
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with the other symbol names, I suggest the following:
indexstoredb_index_symbol_names
indexstoredb_index_canonical_symbol_occurences_containing_pattern
indexstoredb_index_canonical_symbol_occurences_by_name
We've been using "index_" in the name since these are effectively methods of the index object, and I've been using plurals instead of "for_each". I'm not wed to these names, but it would be good to be consistent.
Add discardableResult to new functions. Return Bool in new functions. Make all new variables lowercase. Rename functions to match existing patterns.
I believe I've addressed all of the comments again. Thank you again for the feedback! |
@swift-ci Please test |
This can be used in lsp projects to find
all symbols in a workspace that match a string.
https://bugs.swift.org/browse/SR-10806