-
Notifications
You must be signed in to change notification settings - Fork 565
"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
Conversation
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.
@@ -47,4 +45,33 @@ unique_ptr<ast::MethodDef> DefLocSaver::postTransformMethodDef(core::Context ctx | |||
return methodDef; | |||
} | |||
|
|||
unique_ptr<ast::UnresolvedIdent> DefLocSaver::postTransformUnresolvedIdent(core::Context ctx, |
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.
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.
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.
+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 ¶ms); | |||
LSPResult handleWorkspaceSymbols(std::unique_ptr<core::GlobalState> gs, const MessageId &id, | |||
const WorkspaceSymbolParams ¶ms); | |||
std::pair<std::unique_ptr<core::GlobalState>, std::vector<std::unique_ptr<Location>>> | |||
getReferencesToSymbol(std::unique_ptr<core::GlobalState> gs, core::SymbolRef symbol, |
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.
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 |
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.
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); |
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.
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, |
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 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.
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 all looks good to me!
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.
"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.