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

Search-based usages for new codenav API#63464

Merged
kritzcreek merged 10 commits into
mainfrom
christoph/search-based-usages
Jun 28, 2024
Merged

Search-based usages for new codenav API#63464
kritzcreek merged 10 commits into
mainfrom
christoph/search-based-usages

Conversation

@kritzcreek

@kritzcreek kritzcreek commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

Closes https://linear.app/sourcegraph/issue/GRAPH-703/syntactic-filtered-search-based-usages

This initial implementation adds search-based usages for the new codenav API.

I'll work on a follow-up PR(https://github.com/sourcegraph/sourcegraph/pull/63509) to get us to feature parity with the current search-based implementation. https://linear.app/sourcegraph/issue/GRAPH-712/determine-usage-kind-for-search-based-usages-by-running-symbol-search

Additionally I've added an implementation note for when I work on pagination next cycle here: https://linear.app/sourcegraph/issue/GRAPH-696/implement-pagination-for-syntactic-and-search-based-usages

Test plan

Using the API console

@cla-bot cla-bot Bot added the cla-signed label Jun 25, 2024
@kritzcreek kritzcreek force-pushed the christoph/search-based-usages branch 7 times, most recently from 3c67ec0 to 884e3d8 Compare June 27, 2024 03:45
@kritzcreek kritzcreek marked this pull request as ready for review June 27, 2024 03:46
@kritzcreek kritzcreek force-pushed the christoph/search-based-usages branch 2 times, most recently from d27bd6e to 70a9171 Compare June 28, 2024 08:15
@kritzcreek kritzcreek force-pushed the christoph/search-based-usages branch 2 times, most recently from 05c4691 to f3b044f Compare June 28, 2024 10:30
@kritzcreek kritzcreek force-pushed the christoph/search-based-usages branch from f3b044f to dd036d6 Compare June 28, 2024 10:33
@kritzcreek

Copy link
Copy Markdown
Contributor Author

@varungandhi-src I think I addressed all the feedback you gave in the other PR over here. Could you take another look?

Comment thread internal/codeintel/codenav/service.go

@varungandhi-src varungandhi-src left a comment

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.

Please simplify some of the code before merging.

Comment thread internal/codeintel/codenav/service.go Outdated
Comment on lines +1345 to +1355
var syntacticUploadID int
if previousSyntacticSearch.Found {
syntacticUploadID = previousSyntacticSearch.UploadID
} else {
syntacticUpload, err := s.getSyntacticUpload(ctx, trace, repo, commit, path)
if err != nil {
trace.Info("no syntactic upload found, return all search-based results", log.Error(err))
} else {
syntacticUploadID = syntacticUpload.ID
}
}

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.

AFAICT, there is no data dependency between this if and the findCandidateOccurrencesViaSearch call. Please combine all the if previousSyntacticSearch.Found checks in one place, so it's clear at a glance. If you rename the type to something more generic, you can fold the logic into a single immediately-invoked-func that returns struct { uploadID, symbolName, language }, error, and only that func needs to look at previousSyntacticSearch

Comment thread internal/codeintel/codenav/service.go Outdated

results := [][]SearchBasedMatch{}
for pair := candidateMatches.Oldest(); pair != nil; pair = pair.Next() {
if syntacticUploadID != 0 {

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.

I think 0 is potentially a valid UploadID? Please don't check for 0 here.

Comment on lines +42 to +44
if identifier == "" {
return *orderedmap.New[core.RepoRelPath, candidateFile](), nil
}

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.

If we're getting an empty string here, that's likely a mistake in the API client, right? In that case, we should return an error from this function, or the caller should guarantee that the identifier is non-empty.

SnapshotForDocument(ctx context.Context, repositoryID int, commit string, path core.RepoRelPath, uploadID int) (data []shared.SnapshotData, err error)
SCIPDocument(ctx context.Context, uploadID int, path core.RepoRelPath) (*scip.Document, error)
SyntacticUsages(ctx context.Context, repo types.Repo, commit api.CommitID, path core.RepoRelPath, symbolRange scip.Range) ([]codenav.SyntacticMatch, *codenav.SyntacticUsagesError)
SyntacticUsages(ctx context.Context, repo types.Repo, commit api.CommitID, path core.RepoRelPath, symbolRange scip.Range) (codenav.SyntacticUsagesResult, codenav.PreviousSyntacticSearch, *codenav.SyntacticUsagesError)

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.

Perhaps we can bundle the repo, commit, path, symbolRange into a ResolvedRangeInput analogous to the distinction between UsagesForSymbolArgs and UsagesForSymbolResolvedArgs?

@kritzcreek kritzcreek merged commit 8c34a62 into main Jun 28, 2024
@kritzcreek kritzcreek deleted the christoph/search-based-usages branch June 28, 2024 13:46
@kritzcreek

Copy link
Copy Markdown
Contributor Author

I think I got them all, but if I missed a comment I'm happy to implement it over in #63509 next week

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