Skip to content
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

Merged
merged 3 commits into from Jul 4, 2019

Conversation

literalpie
Copy link
Contributor

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

@literalpie
Copy link
Contributor Author

literalpie commented Jun 29, 2019

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
Copy link
Member

@akyrtzi akyrtzi left a 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.

Sources/IndexStoreDB/IndexStoreDB.swift Outdated Show resolved Hide resolved
include/CIndexStoreDB/CIndexStoreDB.h Outdated Show resolved Hide resolved
lib/CIndexStoreDB/CIndexStoreDB.cpp Show resolved Hide resolved
@@ -80,6 +80,49 @@ public final class IndexStoreDB {
return body(SymbolOccurrence(occur))
}
}

public func forEachCanonicalSymbolOccurrenceByName(symbolName: String, body: @escaping (SymbolOccurrence) -> Bool) {
Copy link
Member

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:)

Copy link
Member

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
Copy link
Member

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.

lib/CIndexStoreDB/CIndexStoreDB.cpp Show resolved Hide resolved
}
}

public func findSymbols(matching query: String) -> [SymbolOccurrence] {
Copy link
Member

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.

bool
indexstoredb_for_each_canonical_symbol_occurence_containing_pattern(
indexstoredb_index_t index,
const char *_Nonnull Pattern,
Copy link
Member

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(
Copy link
Member

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.
@literalpie
Copy link
Contributor Author

I believe I've addressed all of the comments again. Thank you again for the feedback!

@akyrtzi
Copy link
Member

akyrtzi commented Jul 4, 2019

@swift-ci Please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants