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
[SR-13765] Index store does not contain reference occurrence for labeled parameters #56162
Comments
Comment by Ian Leitch (JIRA) I'm willing to have a go at fixing this, though I've no idea where to start looking /cc @benlangmuir @rintaro |
This is behaving as designed. The general rule is that we do not index local variables, which includes function parameters. We made a compromise to index parameters that match their argument label, because we need that information for global rename to work correctly. If we wanted to change the rule here, we could either
My suspicion is that option (1) would be too expensive to enable by default, and it's unclear to me what the value of (2) is on its own. Do you have a specific use case for having parameters in the index without having all local declarations? |
I think a frontend flag to opt-in and enable indexing locals would be reasonable. |
Comment by Ian Leitch (JIRA) Context: I'm the author of Periphery, and I'm working on migrating from SourceKit to using the IndexStore exclusively, if possible. I noticed recently that the IndexStore now indexed parameters, which I thought might provide a way forward to migrating the unused parameter detection feature. The current implementation uses SwiftSyntax + a SourceKit cursor info query to then associate the parameters with the function declaration by USR. If we're to resolve this in the index store, (2) sounds reasonable to me. However perhaps it's better that I investigate another method to associate parameters parsed with SwiftSyntax to indexed functions that doesn't depend upon SourceKit. I'll report back if I find a reliable solution. |
Comment by Ian Leitch (JIRA) @akyrtzi In general that would be nice, since then Periphery could also report unused local variables. One caveat is that Periphery would need to rebuild the project being analyzed from scratch with the new flag applied. Periphery actually does already always build projects from scratch in order to obtain the correct compiler flags for SourceKit, though I'd been hoping to avoid doing that with a potential switch to using the index store exclusively. |
Comment by Ian Leitch (JIRA) I've implemented a workaround that allows me to use SwiftSyntax again for identifying unused parameters. We can close this now unless you'd like to keep it open to track work towards (1) or (2). |
Comment by Ian Leitch (JIRA) This was implemented in Periphery by parsing the AST. |
Environment
Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin19.6.0
Xcode 12.2
Build version 12B5035g
Additional Detail from JIRA
md5: 5a0394619470c3593109b43635315023
Issue Description:
Given the above code, the index store should contain an occurrence with the 'reference' role for the use of `foo` in the print statement. This bug only exists for labeled parameters, and the name of the label appears to make no difference.
The text was updated successfully, but these errors were encountered: