Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

literalpie
Copy link
Contributor

@literalpie literalpie commented Jul 6, 2019

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

@literalpie literalpie requested a review from benlangmuir as a code owner July 6, 2019 21:08
return symbolOccurenceResults
}

func workspaceSymbols(_ req: Request<WorkspaceSymbolsRequest>, workspace: Workspace) {
Copy link
Contributor Author

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?

Copy link
Contributor

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

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.

Copy link
Contributor

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 LSP SymbolKind here.

  • detail: This isn't a field on SymbolInformation AFAICT. Did you mix it up with DocumentSymbol?

  • 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 is SymbolOccurrence::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 role childOf and use that symbol's name.

Copy link
Contributor Author

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?

Copy link
Contributor

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) {
Copy link
Contributor Author

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.

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.

2 participants