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
scip: Generate symbols for local crates. #13456
Conversation
@tjdevries @Veykril can you review? Thanks! |
@olafurpg / @varungandhi-src Is this generally how we deal w/ locals? I thought we restarted the local count for every file intentionally (particularly because of later goals of incremental compilation) I think the actual problem must be that I missed some cases of when things should be exposed as non-local (i.e. a pub struct should not be a local, I think) |
Right now ~everything defined in the current workspace uses a local symbol, I think. It makes sense to me off-hand, what should the symbol for Foo be in the test-case above otherwise? Happy to try to work on a better fix if given some pointers :) |
(Given the rust compilation unit is the crate, not the file, it might be ~ok to do this regardless tho?) |
Local symbols should only be used if the symbol cannot be referenced outside the file. In the case above, the In scip-typescript, we emit global symbol for seemingly local variables. For example, see this test case where where we emit the definition of a global symbol for the key of a local object literal because the property |
41a070a
to
7f4a80c
Compare
Ok, so I dug a bit and I think I found the root cause. The issue is that the moniker code was requiring a crate to have a repository in order to generate a moniker for it. So if you're doing a scip index of a local crate which isn't published (which is our use case) then all symbols are incorrectly turned into local. The fix I went for is to just allow the I added some tests to the scip code that fail without this patch. |
crates/ide/src/moniker.rs
Outdated
repo?, | ||
krate.version(db)?, | ||
repo.unwrap_or_default(), | ||
krate.version(db).unwrap_or_default(), |
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.
An alternative would be to use unwrap_or_else(|| "file:///crate/path".into())
and unwrap_or_else(|| "v0.0.0".into())
or so.
Let me know if that's somehow preferable (though that would make the symbols for local crates non-deterministic, which would be somewhat unfortunate).
@emilio you can use a period character “.” for anonymous package names and versions. The only limitation from doing this is that you can’t support cross-repo navigation to your repo (only from your repo to external dependencies). I can’t remember how well this is documented but scip-java uses this feature for almost all regular repositories (since cross-repo navigation works exclusively to packages where the name + version are easily accessible). |
7f4a80c
to
69ddcec
Compare
69ddcec
to
8039a07
Compare
Cool, I've used the |
Gentle ping? Is there anything needed to get this reviewed? Thanks a lot in advance. |
I am not familiar with scip, so if anyone of the sourcegraph team could drop another small review that would be appreciated |
One other option would be to allow passing the git hash of the project in for the current version -- not sure how much work that would be to do though. Otherwise the PR looks good to me |
Ye I don't think we can easily do that, I'll merge this then, thanks! |
☀️ Test successful - checks-actions |
Thanks! |
Consider something like:
Without this there's no way to disambiguate whether "local 1" references "Bar" or "Foo".