8000 "Find all references" support for ivars and cvars. by jvilk-stripe · Pull Request #1257 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

"Find all references" support for ivars and cvars. #1257

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

Merged
merged 1 commit into from
Jul 11, 2019

Conversation

jvilk-stripe
Copy link
Collaborator

"Find all references" support for ivars and cvars.

Adds logic to DefLocSaver that saves references to instance and class variables.

Also contains logic to dedupe locations, as certain queries may return multiple identical results.

Motivation

Improving find all references and go-to-def.

Test plan

See included automated tests.

Adds logic to `DefLocSaver` that saves references to instance and class variables.

Also contains logic to dedupe locations, as certain queries may return multiple identical results.
@jvilk-stripe jvilk-stripe requested a review from a team July 10, 2019 23:33
@ghost ghost requested review from aisamanra and removed request for a team July 10, 2019 23:33
@@ -47,4 +45,33 @@ unique_ptr<ast::MethodDef> DefLocSaver::postTransformMethodDef(core::Context ctx
return methodDef;
}

unique_ptr<ast::UnresolvedIdent> DefLocSaver::postTransformUnresolvedIdent(core::Context ctx,
Copy link
Collaborator Author
@jvilk-stripe jvilk-stripe Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lose this information when building the CFG, so we have to capture it in the AST.

In the CFG, references to ivars and cvars are represented as operations on local variables that alias the field symbol.

Copy link
Collaborator
@DarkDimius DarkDimius Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, CFG is not the right location for this, having it as a separate pass is the right call.

@@ -202,6 +202,9 @@ class LSPLoop {
const DocumentSymbolParams &params);
LSPResult handleWorkspaceSymbols(std::unique_ptr<core::GlobalState> gs, const MessageId &id,
const WorkspaceSymbolParams &params);
std::pair<std::unique_ptr<core::GlobalState>, std::vector<std::unique_ptr<Location>>>
getReferencesToSymbol(std::unique_ptr<core::GlobalState> gs, core::SymbolRef symbol,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new helper method that cleans up duplicated logic in references.cc.

vector<unique_ptr<Location>>
LSPLoop::extractLocations(const core::GlobalState &gs,
const vector<unique_ptr<core::lsp::QueryResponse>> &queryResponses,
vector<unique_ptr<Location>> locations) {
for (auto &q : queryResponses) {
addLocIfExists(gs, locations, q->getLoc());
}
// Dedupe locations
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may report some identical matches from the AST and the CFG now, so we need to dedupe the list of locations returned for a "Find all references" request.

gs = move(run2.gs);
response->result = extractLocations(*gs, run2.responses);
}
tie(gs, response->result) = getReferencesToSymbol(move(gs), constResp->symbol);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor cleanups to move duplicated logic into a helper method.

@@ -1061,6 +1061,14 @@ class AllNamesCollector {
handleUnresolvedConstantLit(ctx, original.get());
return original;
}

unique_ptr<ast::UnresolvedIdent> postTransformUnresolvedIdent(core::Context ctx,
Copy link
Collaborator Author
@jvilk-stripe jvilk-stripe Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make 'find all refs' fast, we store a list of all Names encountered in each file, and use that as a filter for "give me all references to symbol x".

This change stores the names of ivars and cvars into that list.

Copy link
Contributor
@aisamanra aisamanra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks good to me!

@jvilk-stripe jvilk-stripe merged commit d38e71a into master Jul 11, 2019
@jvilk-stripe jvilk-stripe deleted the jvilk-definitions-references-ivars branch July 11, 2019 17:38
pje pushed a commit to pje/sorbet that referenced this pull request Jul 15, 2019
Adds logic to `DefLocSaver` that saves references to instance and class variables.

Also contains logic to dedupe locations, as certain queries may return multiple identical results.
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.

3 participants
0