Adds function to find candidate occurrences via search#63196
Adds function to find candidate occurrences via search#63196kritzcreek merged 16 commits intomainfrom
Conversation
3b4fcea to
377fdbb
Compare
| // Overlapping occurrences should lead to the same display name, but be scored separately. | ||
| // (Meaning we just need a single Searcher/Zoekt search) | ||
| // TODO: Assert this? | ||
| searchSymbol := symbols[0] |
There was a problem hiding this comment.
I don't quite understand what this means, but if we're only picking the first element of the slice, maybe the function getSyntacticSymbolsAtRange shouldn't be returning a slice?
| _, err = client.Execute(ctx, stream, plan) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
I'm wondering if we should handle a context timeout error in a special way here (or in the outermost loop maybe?) 🤔
We should add an operation for each public method (at least, that's the pattern we're following for now). So yes, we should have an operation for |
a2d5f6c to
debb7ba
Compare
|
I handled most of the feedback, but decided after a while that some of it is not actually required for the MVP stage. I've filed a follow-up issue for me to come back for some of these https://linear.app/sourcegraph/issue/GRAPH-683/syntactic-usages-tech-debt |
fb34473 to
286f9b0
Compare
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
varungandhi-src
left a comment
There was a problem hiding this comment.
Will do another pass after an hour or so.
| ) ([]struct{}, *SyntacticUsagesError) { | ||
| // The `nil` in the second argument is here, because `With` does not work with custom error types. | ||
| ctx, trace, endObservation := s.operations.syntacticUsages.With(ctx, nil, observation.Args{Attrs: []attribute.KeyValue{ | ||
| attribute.Int("repoId", int(repo.ID)), | ||
| attribute.String("commit", string(commit)), | ||
| attribute.String("path", path), | ||
| attribute.String("symbolRange", symbolRange.String()), | ||
| }}) | ||
| defer endObservation(1, observation.Args{}) |
There was a problem hiding this comment.
I just looked into this; it looks like endObservation will log the error if we pass in a proper pointer here. So if we really want to return SyntacticUsageError from this function, then we can do the following sequence.
| ) ([]struct{}, *SyntacticUsagesError) { | |
| // The `nil` in the second argument is here, because `With` does not work with custom error types. | |
| ctx, trace, endObservation := s.operations.syntacticUsages.With(ctx, nil, observation.Args{Attrs: []attribute.KeyValue{ | |
| attribute.Int("repoId", int(repo.ID)), | |
| attribute.String("commit", string(commit)), | |
| attribute.String("path", path), | |
| attribute.String("symbolRange", symbolRange.String()), | |
| }}) | |
| defer endObservation(1, observation.Args{}) | |
| ) (_ []struct{}, err *SyntacticUsagesError) { | |
| var erasedError error | |
| // The `nil` in the second argument is here, because `With` does not work with custom error types. | |
| ctx, trace, endObservation := s.operations.syntacticUsages.With(ctx, &erasedError, observation.Args{Attrs: []attribute.KeyValue{ | |
| attribute.Int("repoId", int(repo.ID)), | |
| attribute.String("commit", string(commit)), | |
| attribute.String("path", path), | |
| attribute.String("symbolRange", symbolRange.String()), | |
| }}) | |
| defer endObservation(1, observation.Args{}) | |
| defer func(){ if err != nil { erasedError = *err } }() |
| // (Meaning we just need a single Searcher/Zoekt search) | ||
| searchSymbol := symbolsAtRange[0] | ||
|
|
||
| langs, langErr := languages.GetLanguages(path, func() ([]byte, error) { return nil, errors.New("Ambiguous language") }) |
There was a problem hiding this comment.
- The function argument allows returning an error because content-fetching might return an error. If we don't have access to the content here, you can pass
nilfor the second argument. So there won't be any error returned from the API. - If there are multiple languages returned, we should do an
ANDinstead of taking the first one.
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
varungandhi-src
left a comment
There was a problem hiding this comment.
I updated the tech debt issue with more details. I'm OK with merging this as-is for now, but I don't want us to rush stuff like this purely for demo day, we can share a demo in Slack outside of demo day too.
Nothing about demo day and everything about the MVP milestone. This code doesn't need to deal with language ambiguity to check its viability, but that's what I want to be laser-focused on. |
|
Just want to clarify, I'm not saying I don't appreciate the thorough review, feedback, and discussion. I read every comment and definitely intend to get back to and address the rest of it. |
Closes https://linear.app/sourcegraph/issue/GRAPH-640/pre-filter-candidate-files-by-consulting-zoektsearcher
I'm wondering what to do about o11y here. Should I be adding something to the operations, or some more logging?
Test plan
Easiest way to test right now is to generate a syntactic index, upload it, pull up the site-admin api console and hit the occurrences API endpoint with: