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

Usages API: implement surroundingContent #63730

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

camdencheek
Copy link
Member

@camdencheek camdencheek commented Jul 9, 2024

Instead of fetching the file for every node, this passes in a request-scoped cache to minimize the number of gitserver roundtrips, but does no fetching if surroundingContent is not requested by the caller.

Fixes GRAPH-724

Test plan

Manual testing by using this in the web client.

@cla-bot cla-bot bot added the cla-signed label Jul 9, 2024
@camdencheek camdencheek force-pushed the cc/implement-surrounding-content branch from 413ba6b to df5bd16 Compare July 9, 2024 20:00
@@ -28,6 +28,8 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)

var ErrNotEnabled = errors.New("experimentalFeatures.scipBasedAPIs is not enabled")
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated, but it's most useful to me as a consumer to get a hard error if the API is disabled. Otherwise, I have no way of distinguishing "disabled" from "no results"

@camdencheek camdencheek force-pushed the cc/implement-surrounding-content branch from df5bd16 to 6701ff9 Compare July 9, 2024 20:08
@kritzcreek
Copy link
Contributor

kritzcreek commented Jul 10, 2024

Ahh I see. I was thinking that, because I can get the surrounding lines through the Search APIs (which I'm calling anyway, for non-precise usages), I'd just pass that data through, rather than going to back to gitserver to re-fetch the files.

But that would require knowing the number of surroundingLines at the "request" level for usagesForSymbol (which is why I made that comment on the issue)

@camdencheek
Copy link
Member Author

But that would require knowing the number of surroundingLines at the "request" level for usagesForSymbol (which is why I made that comment on the issue)

One option is to wrap the LineGetter in another layer that uses the search result in the case the chunk in the search result chunk is largh enough to satisfy the request

@kritzcreek
Copy link
Contributor

One option is to wrap the LineGetter in another layer that uses the search result in the case the chunk in the search result chunk is largh enough to satisfy the request

Varun said something like that as well. Use the size the frontend will request as a heuristic, and only re-fetch contents if the line count differs. Still feels a bit silly to me that the search API lets me specify exactly how many lines I want, and the requested count is specified in the request I'm currently fulfilling, but I can't get at that information because of the resolver structure GraphQL imposes.

@camdencheek
Copy link
Member Author

camdencheek commented Jul 10, 2024

feels a bit silly

Resolvers can, in fact, feel pretty silly 🙂 In particular, the GraphQL lib we use makes it impossible to inspect the request to determine ahead of time what data to fetch. See this issue that I've been subscribed to for years

@camdencheek
Copy link
Member Author

Use the size the frontend will request as a heuristic

FWIW, I have no plans to make the frontend request more than just the containing line. We could probably simplify the API by only supporting the containing line for now. If we ever need more than that, it would be a backwards-compatible change to add an argument that allows growing the selection.

@camdencheek camdencheek changed the title Usages API: implemented surroundingContent Usages API: implement surroundingContent Jul 10, 2024
@kritzcreek
Copy link
Contributor

FWIW, I have no plans to make the frontend request more than just the containing line. We could probably simplify the API by only supporting the containing line for now. If we ever need more than that, it would be a backwards-compatible change to add an argument that allows growing the selection.

Great! Let's do that. We might still end up needing the LineGetter for precise usages, but it should be easy enough to resurrect it from this PR.
If this PR lets you make progress in the meantime I'm happy to accept it and break the API in a follow-up PR.

@camdencheek
Copy link
Member Author

If this PR lets you make progress in the meantime I'm happy to accept it and break the API in a follow-up PR.

Let's do that then 🙂 To be explicit, from my end, you can assume for now that I will never pass an arg to surroundingContext and just returning the containing line is A-OK

@camdencheek camdencheek marked this pull request as ready for review July 10, 2024 16:18
@camdencheek camdencheek requested a review from kritzcreek July 10, 2024 16:18
@camdencheek camdencheek enabled auto-merge (squash) July 10, 2024 16:21
@camdencheek camdencheek merged commit c000c81 into main Jul 11, 2024
8 of 9 checks passed
@camdencheek camdencheek deleted the cc/implement-surrounding-content branch July 11, 2024 07:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants