Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Correctly re-map source ranges in new SCIP-based APIs#63630

Merged
kritzcreek merged 11 commits into
mainfrom
vg/scip-document-fix
Jul 11, 2024
Merged

Correctly re-map source ranges in new SCIP-based APIs#63630
kritzcreek merged 11 commits into
mainfrom
vg/scip-document-fix

Conversation

@varungandhi-src

@varungandhi-src varungandhi-src commented Jul 4, 2024

Copy link
Copy Markdown
Contributor

This PR fixes the following:

  • Handles source range translation in the occurrences API
    (Fixes https://linear.app/sourcegraph/issue/GRAPH-705)
  • Handles range translation when comparing with document occurrences in
    search-based and syntactic usagesForSymbol implementations

Throwing this PR up in its current state as I think adding the bulk conversion
API will be a somewhat complex task, so we should split them into separate
PRs anyways, and I don't have time to continue working on this right now.

TODO:

  • Updating tests
  • Some basic manual testing for occurrences and usagesForSymbol
  • New tests with mocks?
  • Adds a new API for TraceLogger, that should be split into a separate PR?

Some design notes:

  • We want to avoid passing around full CompletedUpload and RequestState objects,
    which is why I chose to create a smaller UploadSummary type and decided to pass
    around GitTreeTranslator as that is the minimal thing we need to handle range re-mapping.
    • Yes, this PR increases the surface of the UploadLike type, but I think it's still quite manageable.

Test plan

TODO

Changelog

@cla-bot cla-bot Bot added the cla-signed label Jul 4, 2024
@github-actions github-actions Bot added team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform labels Jul 4, 2024
@kritzcreek kritzcreek self-requested a review July 9, 2024 07:29
@kritzcreek

Copy link
Copy Markdown
Contributor

I'll take this PR over and start pushing commits onto the branch.

@kritzcreek kritzcreek force-pushed the vg/scip-document-fix branch from ba32a70 to 4f062f4 Compare July 9, 2024 07:43
Comment thread internal/codeintel/codenav/transport/graphql/root_resolver_test.go Outdated
@kritzcreek kritzcreek force-pushed the vg/scip-document-fix branch 3 times, most recently from a8c24b3 to 78f6262 Compare July 11, 2024 03:35
@kritzcreek kritzcreek self-requested a review July 11, 2024 03:36
@kritzcreek kritzcreek force-pushed the vg/scip-document-fix branch from 78f6262 to c8e271e Compare July 11, 2024 04:42
@kritzcreek

Copy link
Copy Markdown
Contributor

I ran some manual tests and see occurrences being shifted accordingly. Because this PR doesn't really change any of the GitTreeTranslator code, I'm assuming that to be correct for now.
As we've discussed yesterday I have some plans for making a MappedIndex component/struct that will allow seperating some logic and testing things individually.
I'd be happy to merge this PR as is.

@kritzcreek kritzcreek marked this pull request as ready for review July 11, 2024 05:00
@kritzcreek kritzcreek force-pushed the vg/scip-document-fix branch from 6774bab to c457861 Compare July 11, 2024 05:16
Comment thread internal/codeintel/codenav/service.go Outdated
// This Range is the range of the symbol in the requested commit,
// which can be different from the range of the symbol in the syntactic
// upload, iff it was adjusted by the git tree translator.
Range scip.Range

@varungandhi-src varungandhi-src Jul 11, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't Range be equal to scip.NewRangeUnchecked(occ.Range)? I'm not sure why we need to record it separately here? 🤔

We should be updating the range on the Occurrence value, right? Similar to the other API?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It won't be, because this call is fetching from lsifStore.SCIPDocument so it returns the unmapped ranges. I'm a bit worried about modifying the occurrence in place, because if there is any caching anywhere we might end up remapping the location twice.
I'll change the SyntacticMatch type to not return *scip.Occurrence and instead return symbol and range separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done in 9768955

@varungandhi-src

Copy link
Copy Markdown
Contributor Author

I'm assuming that to be correct for now.

This assumption keeps biting us again and again. 🙈 I think aiming for "not more incorrect than before" is good enough for now. 😆😭

As we've discussed yesterday I have some plans for making a MappedIndex component/struct that will allow seperating some logic and testing things individually.

That's OK. I would also support introducing wrapper types such as AtRequestedCommit[T] and AtIndexedCommit[T] (or maybe AtCommit[T, Requested | Indexed]( (maybe with more compact names?) to make the code easier-to-follow, I find the usage of generic source and target a bit too confusing.

This way we don't have two conflicting ranges around
@kritzcreek kritzcreek enabled auto-merge (squash) July 11, 2024 06:54
@kritzcreek kritzcreek merged commit be0cd09 into main Jul 11, 2024
@kritzcreek kritzcreek deleted the vg/scip-document-fix branch July 11, 2024 06:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants