-
Notifications
You must be signed in to change notification settings - Fork 314
Add workspace/symbols support #118
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
Conversation
return symbolOccurenceResults | ||
} | ||
|
||
func workspaceSymbols(_ req: Request<WorkspaceSymbolsRequest>, workspace: Workspace) { |
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.
Much of the other functionality seems to be done in SwiftLanguageServer, but I think I need to do this here to have access to index. Is that correct?
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.
Yep, this is the right place for it. Language-agnostic functionality belongs here, which is why we also implement e.g. jump to definition here.
let symbolLocation = Location( | ||
url: URL(fileURLWithPath: symbolOccurrence.location.path), | ||
range: Range(symbolPosition)) | ||
// TODO: symbol kind, detail, and containerName should be added |
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 would like some guidance on how to get kind, detail, and containerName.
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.
-
kind: We have a symbol kind in the index that we should expose on
class Symbol
. Then we can convert it to an LSPSymbolKind
here. -
detail: This isn't a field on
SymbolInformation
AFAICT. Did you mix it up withDocumentSymbol
? -
containerName: Ah didn't realize we'd need this. For this we would need to expose the
SymbolOccurrence
's relations in the index. The C++ version of this isSymbolOccurrence::getRelations
, we just need to thread it through the C and Swift interfaces. Since you already have the canonical occurrence, you would find the related symbol that has relation rolechildOf
and use that symbol's name.
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.
You are correct that detail came from DocumentSymbol
.
for containerName, it looks like I will have to pass an ArrayPointer to Swift, which I can't find a good example of. Maybe I could use unsafeBufferPointer
as mentioned here, but it looks like that involves copying which I think we want to avoid. is there a better way to do this?
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.
Copying should be fine, since the number of relations for a single occurrence will generally be small, and we can do the copy lazily only when you ask for related symbols. Here's a sketch of the C API I would start with. We can always optimize this later if needed.
typedef void *indexstoredb_symbol_relation_t;
...
INDEXSTOREDB_PUBLIC uint64_t
indexstoredb_symbol_relation_get_roles(_Nonnull indexstoredb_symbol_relation_t);
INDEXSTOREDB_PUBLIC indexstoredb_symbol_t
indexstoredb_symbol_relation_get_symbol(_Nonnull indexstoredb_symbol_relation_t);
/// The relations are owned by the occurrence and shall not be used after the occurrence is freed.
INDEXSTOREDB_PUBLIC bool
indexstoredb_symbol_occurrence_relations(_Nonnull indexstoredb_occurrence_t,
bool(^applier)(indexstoredb_symbol_relation_t));
On the Swift side, this can lazily create an array from the occurrence.
subsequence: true, | ||
ignoreCase: true | ||
) {symbol in | ||
if !symbol.location.isSystem && !symbol.roles.contains(.accessorOf) { |
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'm not sure what roles should be included. I've excluded accessorOf
because otherwise getters and setters of variables were returned in addition to the variable itself.
https://bugs.swift.org/browse/SR-10806
Feedback welcome!
This branch builds on changes made in this PR of indexstore-db
This is the feature that is activated in VSCode with CMD+T