mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:51:57 +00:00
Removes the old GitTreeTranslator API (#64027)
Following through after #63938 ## Test plan Existing tests continue to pass
This commit is contained in:
parent
dc7da57edb
commit
19db59b72c
@ -10,7 +10,6 @@ type config struct {
|
||||
env.BaseConfig
|
||||
|
||||
LSIFUploadStoreConfig *lsifuploadstore.Config
|
||||
HunkCacheSize int
|
||||
MaximumIndexesPerMonikerSearch int
|
||||
}
|
||||
|
||||
@ -20,7 +19,6 @@ func (c *config) Load() {
|
||||
c.LSIFUploadStoreConfig = &lsifuploadstore.Config{}
|
||||
c.LSIFUploadStoreConfig.Load()
|
||||
|
||||
c.HunkCacheSize = c.GetInt("PRECISE_CODE_INTEL_HUNK_CACHE_SIZE", "1000", "The capacity of the git diff hunk cache.")
|
||||
c.MaximumIndexesPerMonikerSearch = c.GetInt("PRECISE_CODE_INTEL_MAXIMUM_INDEXES_PER_MONIKER_SEARCH", "500", "The maximum number of indexes to search at once when doing cross-index code navigation.")
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ func Init(
|
||||
preciseIndexResolverFactory,
|
||||
)
|
||||
|
||||
codenavRootResolver, err := codenavgraphql.NewRootResolver(
|
||||
codenavRootResolver := codenavgraphql.NewRootResolver(
|
||||
scopedContext("codenav"),
|
||||
codeIntelServices.CodenavService,
|
||||
codeIntelServices.AutoIndexingService,
|
||||
@ -83,12 +83,8 @@ func Init(
|
||||
autoIndexJobLoaderFactory,
|
||||
preciseIndexResolverFactory,
|
||||
locationResolverFactory,
|
||||
ConfigInst.HunkCacheSize,
|
||||
ConfigInst.MaximumIndexesPerMonikerSearch,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
policyRootResolver := policiesgraphql.NewRootResolver(
|
||||
scopedContext("policies"),
|
||||
|
||||
14
deps.bzl
14
deps.bzl
@ -1524,13 +1524,6 @@ def go_dependencies():
|
||||
sum = "h1:AxjTubpVyozMvbBCtXcsWEyGGgUZutC5YGrfxPNVOcQ=",
|
||||
version = "v1.4.1",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_dgraph_io_ristretto",
|
||||
build_file_proto_mode = "disable_global",
|
||||
importpath = "github.com/dgraph-io/ristretto",
|
||||
sum = "h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=",
|
||||
version = "v0.1.1",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_dgrijalva_jwt_go",
|
||||
build_file_proto_mode = "disable_global",
|
||||
@ -1538,13 +1531,6 @@ def go_dependencies():
|
||||
sum = "h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=",
|
||||
version = "v3.2.0+incompatible",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_dgryski_go_farm",
|
||||
build_file_proto_mode = "disable_global",
|
||||
importpath = "github.com/dgryski/go-farm",
|
||||
sum = "h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=",
|
||||
version = "v0.0.0-20190423205320-6a90982ecee2",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_dgryski_go_rendezvous",
|
||||
build_file_proto_mode = "disable_global",
|
||||
|
||||
2
go.mod
2
go.mod
@ -99,7 +99,6 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
|
||||
github.com/daviddengcn/go-colortext v1.0.0
|
||||
github.com/derision-test/glock v1.0.0
|
||||
github.com/dgraph-io/ristretto v0.1.1
|
||||
github.com/distribution/distribution/v3 v3.0.0-20220128175647-b60926597a1b
|
||||
github.com/dnaeon/go-vcr v1.2.0
|
||||
github.com/docker/docker-credential-helpers v0.8.1
|
||||
@ -579,7 +578,6 @@ require (
|
||||
github.com/go-stack/stack v1.8.1 // indirect
|
||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/golang/glog v1.2.1 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
|
||||
|
||||
5
go.sum
5
go.sum
@ -1056,11 +1056,7 @@ github.com/dghubble/gologin/v2 v2.4.0 h1:Ga0dxZ2C/8MrMtC0qFLIg1K7cVjZQWSbTj/MIgF
|
||||
github.com/dghubble/gologin/v2 v2.4.0/go.mod h1:85FO9Je/O6n9/KdHTUtVDSaXQjR6Ducx7blL/3CUfnw=
|
||||
github.com/dghubble/sling v1.4.1 h1:AxjTubpVyozMvbBCtXcsWEyGGgUZutC5YGrfxPNVOcQ=
|
||||
github.com/dghubble/sling v1.4.1/go.mod h1:QoMB1KL3GAo+7HsD8Itd6S+6tW91who8BGZzuLvpOyc=
|
||||
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
|
||||
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
@ -2986,7 +2982,6 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -47,7 +47,6 @@ go_library(
|
||||
"//lib/codeintel/precise",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_dgraph_io_ristretto//:ristretto",
|
||||
"@com_github_life4_genesis//slices",
|
||||
"@com_github_sourcegraph_conc//:conc",
|
||||
"@com_github_sourcegraph_conc//iter",
|
||||
@ -69,7 +68,6 @@ go_test(
|
||||
"mapped_index_test.go",
|
||||
"scip_utils_test.go",
|
||||
"service_closest_uploads_test.go",
|
||||
"service_definitions_test.go",
|
||||
"service_diagnostics_test.go",
|
||||
"service_hover_test.go",
|
||||
"service_new_test.go",
|
||||
|
||||
@ -5,16 +5,13 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/dgraph-io/ristretto"
|
||||
genslices "github.com/life4/genesis/slices"
|
||||
"github.com/sourcegraph/go-diff/diff"
|
||||
"github.com/sourcegraph/scip/bindings/go/scip"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
@ -22,150 +19,8 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// GitTreeTranslator translates a position within a git tree at a source commit into the
|
||||
// equivalent position in a target commit. The git tree translator instance carries
|
||||
// along with it the source commit.
|
||||
//
|
||||
// NOTE(id: codenav-file-rename-detection) At the moment, this code cannot handle positions/ranges
|
||||
// going from one file to another (notice that the return values don't contain any updated
|
||||
// path), because there is no way in gitserver to get rename detection without requesting
|
||||
// a diff of the full repo (which may be quite large).
|
||||
//
|
||||
// Additionally, it's not clear if reusing the Document at path P1 in an older commit,
|
||||
// at a different path P2 in a newer commit is even reliably useful, since symbol names
|
||||
// may change based on the file name or directory name depending on the language.
|
||||
//
|
||||
// TODO(id: GitTreeTranslator-cleanup): Instead of storing the TranslationBase, we should
|
||||
// take that as an argument. Specifically, use a struct with two fields, AncestorCommit
|
||||
// and DescendantCommit, and avoid Source/Target terminology (which becomes confusing to
|
||||
// understand with the reverse parameter). Instead, we can use an enum MappingDirection
|
||||
// FromDescendantToAncestor | FromAncestorToDescendant if really needed (to avoid
|
||||
// inconsistency when modifying the APIs below, as they take different values for 'reverse'
|
||||
// in production).
|
||||
// GitTreeTranslator translates positions within a git tree between commits.
|
||||
type GitTreeTranslator interface {
|
||||
// GetTargetCommitPositionFromSourcePosition translates the given position from the source commit into the given
|
||||
// target commit. The target commit's position is returned, along with a boolean flag
|
||||
// indicating that the translation was successful. If reverse is true, then the source and
|
||||
// target commits are swapped.
|
||||
//
|
||||
// TODO(id: GitTreeTranslator-cleanup): The reverse parameter is always false in production,
|
||||
// let's remove the extra parameter.
|
||||
GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, path string, px shared.Position, reverse bool) (shared.Position, bool, error)
|
||||
|
||||
// GetTargetCommitRangeFromSourceRange translates the given range from the source commit into the given target
|
||||
// commit. The target commit's range is returned, along with a boolean flag indicating
|
||||
// that the translation was successful. If reverse is true, then the source and target commits
|
||||
// are swapped.
|
||||
//
|
||||
// TODO(id: GitTreeTranslator-cleanup): The reverse parameter is always true in production,
|
||||
// let's remove the extra parameter.
|
||||
GetTargetCommitRangeFromSourceRange(ctx context.Context, commit string, path string, rx shared.Range, reverse bool) (shared.Range, bool, error)
|
||||
|
||||
GetSourceCommit() api.CommitID
|
||||
|
||||
// TODO(id: add-bulk-translation-api) Add an API which can map a bunch of ranges all at once
|
||||
// so as to avoid iterating over the hunks repeatedly. So long as there is no error getting
|
||||
// the hunks, the API should try to convert as many ranges as possible instead of fail-fast
|
||||
// behavior. It is OK to expect the input set of ranges to be sorted.
|
||||
// Might be useful to add a simple benchmark too.
|
||||
}
|
||||
|
||||
type gitTreeTranslator struct {
|
||||
compact CompactGitTreeTranslator
|
||||
client gitserver.Client
|
||||
base *TranslationBase
|
||||
hunkCache HunkCache
|
||||
}
|
||||
|
||||
// TODO(id: GitTreeTranslator-cleanup): Strictly speaking, calling this TranslationBase is not
|
||||
// quite correct as things can flip around based on the reverse parameter. So get rid
|
||||
// of the commit field and pass that as a parameter for increased clarity at call-sites.
|
||||
type TranslationBase struct {
|
||||
Repo *sgtypes.Repo
|
||||
Commit api.CommitID
|
||||
}
|
||||
|
||||
func (r *TranslationBase) GetRepoID() int {
|
||||
return int(r.Repo.ID)
|
||||
}
|
||||
|
||||
// HunkCache is a concurrency-safe LRU cache that holds git diff hunks.
|
||||
//
|
||||
// WARNING: It is NOT safe to modify the return value of Get or to
|
||||
// modify key or value passed to Set. Not 100% sure about this, filed:
|
||||
// https://github.com/dgraph-io/ristretto/issues/381
|
||||
type HunkCache interface {
|
||||
// Get returns the value (if any) and a boolean representing whether the value was
|
||||
// found or not.
|
||||
Get(key any) (any, bool)
|
||||
|
||||
// Set attempts to add the key-value item to the cache with the given cost. If it
|
||||
// returns false, then the value as dropped and the item isn't added to the cache.
|
||||
Set(key, value any, cost int64) bool
|
||||
}
|
||||
|
||||
// NewHunkCache creates a data cache instance with the given maximum capacity.
|
||||
func NewHunkCache(size int) (HunkCache, error) {
|
||||
return ristretto.NewCache(&ristretto.Config{
|
||||
NumCounters: int64(size) * 10,
|
||||
MaxCost: int64(size),
|
||||
BufferItems: 64,
|
||||
})
|
||||
}
|
||||
|
||||
// NewGitTreeTranslator creates a new GitTreeTranslator with the given repository and source commit.
|
||||
func NewGitTreeTranslator(client gitserver.Client, base *TranslationBase, hunkCache HunkCache) GitTreeTranslator {
|
||||
return &gitTreeTranslator{
|
||||
client: client,
|
||||
compact: NewCompactGitTreeTranslator(client, *base.Repo),
|
||||
hunkCache: hunkCache,
|
||||
base: base,
|
||||
}
|
||||
}
|
||||
|
||||
// GetTargetCommitPositionFromSourcePosition translates the given position from the source commit into the given
|
||||
// target commit. The target commit position is returned, along with a boolean flag
|
||||
// indicating that the translation was successful. If reverse is true, then the source and
|
||||
// target commits are swapped.
|
||||
func (g *gitTreeTranslator) GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, path string, px shared.Position, reverse bool) (shared.Position, bool, error) {
|
||||
from, to := g.base.Commit, api.CommitID(commit)
|
||||
if reverse {
|
||||
from, to = to, from
|
||||
}
|
||||
posOpt, err := g.compact.TranslatePosition(ctx, from, to, core.NewRepoRelPathUnchecked(path), px.ToSCIPPosition())
|
||||
if err != nil {
|
||||
return shared.Position{}, false, err
|
||||
}
|
||||
pos, ok := posOpt.Get()
|
||||
return shared.TranslatePosition(pos), ok, nil
|
||||
}
|
||||
|
||||
// GetTargetCommitRangeFromSourceRange translates the given range from the source commit into the given target
|
||||
// commit. The target commit range is returned, along with a boolean flag indicating
|
||||
// that the translation was successful. If reverse is true, then the source and target commits
|
||||
// are swapped.
|
||||
func (g *gitTreeTranslator) GetTargetCommitRangeFromSourceRange(ctx context.Context, commit string, path string, rx shared.Range, reverse bool) (shared.Range, bool, error) {
|
||||
from, to := g.base.Commit, api.CommitID(commit)
|
||||
if reverse {
|
||||
from, to = to, from
|
||||
}
|
||||
posOpt, err := g.compact.TranslateRange(ctx, from, to, core.NewRepoRelPathUnchecked(path), rx.ToSCIPRange())
|
||||
if err != nil {
|
||||
return shared.Range{}, false, err
|
||||
}
|
||||
range_, ok := posOpt.Get()
|
||||
return shared.TranslateRange(range_), ok, nil
|
||||
}
|
||||
|
||||
func (g *gitTreeTranslator) GetSourceCommit() api.CommitID {
|
||||
return g.base.Commit
|
||||
}
|
||||
|
||||
func makeKey(parts ...string) string {
|
||||
return strings.Join(parts, ":")
|
||||
}
|
||||
|
||||
type CompactGitTreeTranslator interface {
|
||||
// TranslatePosition returns None if the given position is on a line that was removed or modified
|
||||
// between from and to
|
||||
TranslatePosition(
|
||||
@ -182,7 +37,7 @@ type CompactGitTreeTranslator interface {
|
||||
Prefetch(ctx context.Context, from api.CommitID, to api.CommitID, paths []core.RepoRelPath)
|
||||
}
|
||||
|
||||
func NewCompactGitTreeTranslator(client gitserver.Client, repo sgtypes.Repo) CompactGitTreeTranslator {
|
||||
func NewGitTreeTranslator(client gitserver.Client, repo sgtypes.Repo) GitTreeTranslator {
|
||||
return &newTranslator{
|
||||
client: client,
|
||||
repo: repo,
|
||||
|
||||
@ -14,14 +14,15 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
var mockTranslationBase = TranslationBase{
|
||||
Repo: &sgtypes.Repo{ID: 50},
|
||||
Commit: "deadbeef1",
|
||||
var mockRepo sgtypes.Repo = sgtypes.Repo{ID: 50}
|
||||
|
||||
func rp(path string) core.RepoRelPath {
|
||||
return core.NewRepoRelPathUnchecked(path)
|
||||
}
|
||||
|
||||
func diffMock(diff string) gitserver.Client {
|
||||
@ -34,15 +35,15 @@ func diffMock(diff string) gitserver.Client {
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
client := diffMock(hugoDiff)
|
||||
posIn := shared.Position{Line: 302, Character: 15}
|
||||
args := &mockTranslationBase
|
||||
posIn := scip.Position{Line: 302, Character: 15}
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
posOut, ok, err := adjuster.GetTargetCommitPositionFromSourcePosition(context.Background(), "deadbeef2", "resources/image.go", posIn, false)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
posOutOpt, err := adjuster.TranslatePosition(context.Background(), "deadbeef1", "deadbeef2", rp("resources/image.go"), posIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
posOut, ok := posOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
expectedPos := shared.Position{Line: 294, Character: 15}
|
||||
expectedPos := scip.Position{Line: 294, Character: 15}
|
||||
if diff := cmp.Diff(expectedPos, posOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
}
|
||||
@ -50,13 +51,13 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
|
||||
client := diffMock("")
|
||||
posIn := shared.Position{Line: 10, Character: 15}
|
||||
args := &mockTranslationBase
|
||||
posIn := scip.Position{Line: 10, Character: 15}
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
posOut, ok, err := adjuster.GetTargetCommitPositionFromSourcePosition(context.Background(), "deadbeef2", "resources/image.go", posIn, false)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
posOutOpt, err := adjuster.TranslatePosition(context.Background(), "deadbeef1", "deadbeef2", rp("resources/image.go"), posIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
posOut, ok := posOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
if diff := cmp.Diff(posOut, posIn); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
@ -65,15 +66,15 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
client := diffMock(hugoDiff)
|
||||
posIn := shared.Position{Line: 302, Character: 15}
|
||||
args := &mockTranslationBase
|
||||
posIn := scip.Position{Line: 302, Character: 15}
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
posOut, ok, err := adjuster.GetTargetCommitPositionFromSourcePosition(context.Background(), "deadbeef2", "resources/image.go", posIn, true)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
posOutOpt, err := adjuster.TranslatePosition(context.Background(), "deadbeef2", "deadbeef1", rp("resources/image.go"), posIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
posOut, ok := posOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
expectedPos := shared.Position{Line: 294, Character: 15}
|
||||
expectedPos := scip.Position{Line: 294, Character: 15}
|
||||
if diff := cmp.Diff(expectedPos, posOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
}
|
||||
@ -81,20 +82,20 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
client := diffMock(hugoDiff)
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := scip.Range{
|
||||
Start: scip.Position{Line: 302, Character: 15},
|
||||
End: scip.Position{Line: 305, Character: 20},
|
||||
}
|
||||
args := &mockTranslationBase
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
rOut, ok, err := adjuster.GetTargetCommitRangeFromSourceRange(context.Background(), "deadbeef2", "resources/image.go", rIn, false)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
rOutOpt, err := adjuster.TranslateRange(context.Background(), "deadbeef1", "deadbeef2", rp("resources/image.go"), rIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
rOut, ok := rOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
expectedRange := shared.Range{
|
||||
Start: shared.Position{Line: 294, Character: 15},
|
||||
End: shared.Position{Line: 297, Character: 20},
|
||||
expectedRange := scip.Range{
|
||||
Start: scip.Position{Line: 294, Character: 15},
|
||||
End: scip.Position{Line: 297, Character: 20},
|
||||
}
|
||||
if diff := cmp.Diff(expectedRange, rOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
@ -103,16 +104,16 @@ func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
|
||||
client := diffMock("")
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := scip.Range{
|
||||
Start: scip.Position{Line: 302, Character: 15},
|
||||
End: scip.Position{Line: 305, Character: 20},
|
||||
}
|
||||
args := &mockTranslationBase
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
rOut, ok, err := adjuster.GetTargetCommitRangeFromSourceRange(context.Background(), "deadbeef2", "resources/image.go", rIn, false)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
rOutOpt, err := adjuster.TranslateRange(context.Background(), "deadbeef1", "deadbeef2", rp("resources/image.go"), rIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
rOut, ok := rOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
if diff := cmp.Diff(rOut, rIn); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
@ -121,20 +122,20 @@ func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRangeReverse(t *testing.T) {
|
||||
client := diffMock(hugoDiff)
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := scip.Range{
|
||||
Start: scip.Position{Line: 302, Character: 15},
|
||||
End: scip.Position{Line: 305, Character: 20},
|
||||
}
|
||||
args := &mockTranslationBase
|
||||
|
||||
adjuster := NewGitTreeTranslator(client, args, nil)
|
||||
rOut, ok, err := adjuster.GetTargetCommitRangeFromSourceRange(context.Background(), "deadbeef2", "resources/image.go", rIn, true)
|
||||
adjuster := NewGitTreeTranslator(client, mockRepo)
|
||||
rOutOpt, err := adjuster.TranslateRange(context.Background(), "deadbeef2", "deadbeef1", rp("resources/image.go"), rIn)
|
||||
|
||||
require.NoError(t, err)
|
||||
rOut, ok := rOutOpt.Get()
|
||||
require.Truef(t, ok, "expected translation to succeed")
|
||||
expectedRange := shared.Range{
|
||||
Start: shared.Position{Line: 294, Character: 15},
|
||||
End: shared.Position{Line: 297, Character: 20},
|
||||
expectedRange := scip.Range{
|
||||
Start: scip.Position{Line: 294, Character: 15},
|
||||
End: scip.Position{Line: 297, Character: 20},
|
||||
}
|
||||
if diff := cmp.Diff(expectedRange, rOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/lsifstore"
|
||||
lsifstoremocks "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/lsifstore/mocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
@ -126,8 +125,8 @@ func shiftSCIPRange(r scip.Range, numLines int) scip.Range {
|
||||
})
|
||||
}
|
||||
|
||||
func shiftPos(pos shared.Position, numLines int) shared.Position {
|
||||
return shared.Position{
|
||||
func shiftPos(pos scip.Position, numLines int32) scip.Position {
|
||||
return scip.Position{
|
||||
Line: pos.Line + numLines,
|
||||
Character: pos.Character,
|
||||
}
|
||||
@ -136,43 +135,42 @@ func shiftPos(pos shared.Position, numLines int) shared.Position {
|
||||
// A GitTreeTranslator that returns positions and ranges shifted by numLines
|
||||
// and returns failed translations for path/range pairs if shouldFail returns true
|
||||
func fakeTranslator(
|
||||
targetCommit api.CommitID,
|
||||
from, to api.CommitID,
|
||||
numLines int,
|
||||
shouldFail func(string, shared.Range) bool,
|
||||
shouldFail func(core.RepoRelPath, scip.Range) bool,
|
||||
) GitTreeTranslator {
|
||||
translator := NewMockGitTreeTranslator()
|
||||
translator.GetSourceCommitFunc.SetDefaultReturn(targetCommit)
|
||||
translator.GetTargetCommitPositionFromSourcePositionFunc.SetDefaultHook(func(ctx context.Context, commit string, path string, pos shared.Position, reverse bool) (shared.Position, bool, error) {
|
||||
translator.TranslatePositionFunc.SetDefaultHook(func(ctx context.Context, f, t api.CommitID, path core.RepoRelPath, pos scip.Position) (core.Option[scip.Position], error) {
|
||||
numLines := numLines
|
||||
if reverse {
|
||||
if f == to && t == from {
|
||||
numLines = -numLines
|
||||
}
|
||||
if shouldFail(path, shared.Range{Start: pos, End: pos}) {
|
||||
return shared.Position{}, false, nil
|
||||
if shouldFail(path, scip.Range{Start: pos, End: pos}) {
|
||||
return core.None[scip.Position](), nil
|
||||
}
|
||||
return shiftPos(pos, numLines), true, nil
|
||||
return core.Some(shiftPos(pos, int32(numLines))), nil
|
||||
})
|
||||
translator.GetTargetCommitRangeFromSourceRangeFunc.SetDefaultHook(func(ctx context.Context, commit string, path string, rg shared.Range, reverse bool) (shared.Range, bool, error) {
|
||||
translator.TranslateRangeFunc.SetDefaultHook(func(ctx context.Context, f, t api.CommitID, path core.RepoRelPath, range_ scip.Range) (core.Option[scip.Range], error) {
|
||||
numLines := numLines
|
||||
if reverse {
|
||||
if f == to && t == from {
|
||||
numLines = -numLines
|
||||
}
|
||||
if shouldFail(path, rg) {
|
||||
return shared.Range{}, false, nil
|
||||
if shouldFail(path, range_) {
|
||||
return core.None[scip.Range](), nil
|
||||
}
|
||||
return shared.Range{Start: shiftPos(rg.Start, numLines), End: shiftPos(rg.End, numLines)}, true, nil
|
||||
return core.Some(shiftSCIPRange(range_, numLines)), nil
|
||||
})
|
||||
return translator
|
||||
}
|
||||
|
||||
// A GitTreeTranslator that returns all positions and ranges shifted by numLines.
|
||||
func shiftAllTranslator(targetCommit api.CommitID, numLines int) GitTreeTranslator {
|
||||
return fakeTranslator(targetCommit, numLines, func(path string, rg shared.Range) bool { return false })
|
||||
func shiftAllTranslator(from, to api.CommitID, numLines int) GitTreeTranslator {
|
||||
return fakeTranslator(from, to, numLines, func(path core.RepoRelPath, range_ scip.Range) bool { return false })
|
||||
}
|
||||
|
||||
// A GitTreeTranslator that returns all positions and ranges unchanged
|
||||
func noopTranslator(targetCommit api.CommitID) GitTreeTranslator {
|
||||
return shiftAllTranslator(targetCommit, 0)
|
||||
func noopTranslator() GitTreeTranslator {
|
||||
return shiftAllTranslator("a", "b", 0)
|
||||
}
|
||||
|
||||
type MatchLike interface {
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/lsifstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
)
|
||||
|
||||
@ -41,12 +40,13 @@ func NewMappedIndexFromTranslator(
|
||||
lsifStore lsifstore.LsifStore,
|
||||
gitTreeTranslator GitTreeTranslator,
|
||||
upload core.UploadLike,
|
||||
targetCommit api.CommitID,
|
||||
) MappedIndex {
|
||||
return mappedIndex{
|
||||
lsifStore: lsifStore,
|
||||
gitTreeTranslator: gitTreeTranslator,
|
||||
upload: upload,
|
||||
targetCommit: gitTreeTranslator.GetSourceCommit(),
|
||||
targetCommit: targetCommit,
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,17 +118,17 @@ func cloneOccurrence(occ *scip.Occurrence) *scip.Occurrence {
|
||||
func (d *mappedDocument) mapAllOccurrences(ctx context.Context) ([]*scip.Occurrence, error) {
|
||||
newOccurrences := make([]*scip.Occurrence, 0)
|
||||
for _, occ := range d.document.inner.Occurrences {
|
||||
sharedRange := shared.TranslateRange(scip.NewRangeUnchecked(occ.Range))
|
||||
mappedRange, ok, err := d.gitTreeTranslator.GetTargetCommitRangeFromSourceRange(ctx, string(d.indexCommit), d.path.RawValue(), sharedRange, true)
|
||||
mappedRangeOpt, err := d.gitTreeTranslator.TranslateRange(
|
||||
ctx, d.indexCommit, d.targetCommit, d.path, scip.NewRangeUnchecked(occ.Range),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
if mappedRange, ok := mappedRangeOpt.Get(); ok {
|
||||
newOccurrence := cloneOccurrence(occ)
|
||||
newOccurrence.Range = mappedRange.SCIPRange()
|
||||
newOccurrences = append(newOccurrences, newOccurrence)
|
||||
}
|
||||
newOccurrence := cloneOccurrence(occ)
|
||||
newOccurrence.Range = mappedRange.ToSCIPRange().SCIPRange()
|
||||
newOccurrences = append(newOccurrences, newOccurrence)
|
||||
}
|
||||
return newOccurrences, nil
|
||||
}
|
||||
@ -165,17 +165,16 @@ func (d *mappedDocument) GetOccurrencesAtRange(ctx context.Context, range_ scip.
|
||||
}
|
||||
d.document.lock.RUnlock()
|
||||
|
||||
mappedRg, ok, err := d.gitTreeTranslator.GetTargetCommitRangeFromSourceRange(
|
||||
ctx, string(d.indexCommit), d.path.RawValue(), shared.TranslateRange(range_), false,
|
||||
)
|
||||
mappedRgOpt, err := d.gitTreeTranslator.TranslateRange(ctx, d.targetCommit, d.indexCommit, d.path, range_)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mappedRg, ok := mappedRgOpt.Get()
|
||||
if !ok {
|
||||
// The range was changed/removed in the target commit, so return no occurrences
|
||||
return nil, nil
|
||||
}
|
||||
pastMatchingOccurrences := FindOccurrencesWithEqualRange(occurrences, mappedRg.ToSCIPRange())
|
||||
pastMatchingOccurrences := FindOccurrencesWithEqualRange(occurrences, mappedRg)
|
||||
scipRange := range_.SCIPRange()
|
||||
return genslices.Map(pastMatchingOccurrences, func(occ *scip.Occurrence) *scip.Occurrence {
|
||||
newOccurrence := cloneOccurrence(occ)
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/lsifstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
)
|
||||
@ -29,8 +28,8 @@ func setupSimpleUpload() (api.CommitID, uploadsshared.CompletedUpload, lsifstore
|
||||
|
||||
func TestMappedIndex_GetDocumentNoTranslation(t *testing.T) {
|
||||
targetCommit, upload, lsifStore := setupSimpleUpload()
|
||||
translator := noopTranslator(targetCommit)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload)
|
||||
translator := noopTranslator()
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload, targetCommit)
|
||||
|
||||
ctx := context.Background()
|
||||
unknownDoc, err := mappedIndex.GetDocument(ctx, core.NewRepoRelPathUnchecked("indexRoot/unknown.go"))
|
||||
@ -57,10 +56,8 @@ func TestMappedIndex_GetDocumentNoTranslation(t *testing.T) {
|
||||
|
||||
func TestMappedIndex_GetDocumentWithTranslation(t *testing.T) {
|
||||
targetCommit, upload, lsifStore := setupSimpleUpload()
|
||||
// The translator passed to NewMappedIndex uses the targetCommit as its base.
|
||||
// This -2 thus means going from index -> target shifts by +2 lines.
|
||||
translator := shiftAllTranslator(targetCommit, -2)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload)
|
||||
translator := shiftAllTranslator(upload.GetCommit(), targetCommit, 2)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload, targetCommit)
|
||||
|
||||
ctx := context.Background()
|
||||
mappedDocumentOption, err := mappedIndex.GetDocument(ctx, core.NewRepoRelPathUnchecked("indexRoot/a.go"))
|
||||
@ -85,8 +82,8 @@ func TestMappedIndex_GetDocumentWithTranslation(t *testing.T) {
|
||||
// we're testing that the `isMapped` logic does not change the results of GetOccurrencesAtRange
|
||||
func TestMappedIndex_GetOccurrencesAtRangeAfterGetOccurrences(t *testing.T) {
|
||||
targetCommit, upload, lsifStore := setupSimpleUpload()
|
||||
translator := shiftAllTranslator(targetCommit, -2)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload)
|
||||
translator := shiftAllTranslator(upload.GetCommit(), targetCommit, 2)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload, targetCommit)
|
||||
|
||||
ctx := context.Background()
|
||||
mappedDocumentOption, err := mappedIndex.GetDocument(ctx, core.NewRepoRelPathUnchecked("indexRoot/a.go"))
|
||||
@ -109,10 +106,10 @@ func TestMappedIndex_GetOccurrencesAtRangeAfterGetOccurrences(t *testing.T) {
|
||||
|
||||
func TestMappedIndex_GetDocumentsFiltersFailedTranslation(t *testing.T) {
|
||||
targetCommit, upload, lsifStore := setupSimpleUpload()
|
||||
translator := fakeTranslator(targetCommit, 0, func(path string, rg shared.Range) bool {
|
||||
return rg.ToSCIPRange().CompareStrict(testRange(1)) == 0
|
||||
translator := fakeTranslator(upload.GetCommit(), targetCommit, 0, func(path core.RepoRelPath, rg scip.Range) bool {
|
||||
return rg.CompareStrict(testRange(1)) == 0
|
||||
})
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload, targetCommit)
|
||||
|
||||
ctx := context.Background()
|
||||
mappedDocumentOption, err := mappedIndex.GetDocument(ctx, core.NewRepoRelPathUnchecked("indexRoot/a.go"))
|
||||
@ -125,10 +122,10 @@ func TestMappedIndex_GetDocumentsFiltersFailedTranslation(t *testing.T) {
|
||||
|
||||
func TestMappedIndex_GetDocumentFailedTranslation(t *testing.T) {
|
||||
targetCommit, upload, lsifStore := setupSimpleUpload()
|
||||
translator := fakeTranslator(targetCommit, 0, func(path string, rg shared.Range) bool {
|
||||
return path == "indexRoot/b.go" || rg.ToSCIPRange().CompareStrict(testRange(1)) == 0
|
||||
translator := fakeTranslator(upload.GetCommit(), targetCommit, 0, func(path core.RepoRelPath, rg scip.Range) bool {
|
||||
return path.RawValue() == "indexRoot/b.go" || rg.CompareStrict(testRange(1)) == 0
|
||||
})
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload)
|
||||
mappedIndex := NewMappedIndexFromTranslator(lsifStore, translator, upload, targetCommit)
|
||||
|
||||
ctx := context.Background()
|
||||
mappedDocumentOption, err := mappedIndex.GetDocument(ctx, core.NewRepoRelPathUnchecked("indexRoot/b.go"))
|
||||
|
||||
@ -10,9 +10,10 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
scip "github.com/sourcegraph/scip/bindings/go/scip"
|
||||
api "github.com/sourcegraph/sourcegraph/internal/api"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
core "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
precise "github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
@ -21,17 +22,15 @@ import (
|
||||
// github.com/sourcegraph/sourcegraph/internal/codeintel/codenav) used for
|
||||
// unit testing.
|
||||
type MockGitTreeTranslator struct {
|
||||
// GetSourceCommitFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetSourceCommit.
|
||||
GetSourceCommitFunc *GitTreeTranslatorGetSourceCommitFunc
|
||||
// GetTargetCommitPositionFromSourcePositionFunc is an instance of a
|
||||
// mock function object controlling the behavior of the method
|
||||
// GetTargetCommitPositionFromSourcePosition.
|
||||
GetTargetCommitPositionFromSourcePositionFunc *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc
|
||||
// GetTargetCommitRangeFromSourceRangeFunc is an instance of a mock
|
||||
// function object controlling the behavior of the method
|
||||
// GetTargetCommitRangeFromSourceRange.
|
||||
GetTargetCommitRangeFromSourceRangeFunc *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc
|
||||
// PrefetchFunc is an instance of a mock function object controlling the
|
||||
// behavior of the method Prefetch.
|
||||
PrefetchFunc *GitTreeTranslatorPrefetchFunc
|
||||
// TranslatePositionFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method TranslatePosition.
|
||||
TranslatePositionFunc *GitTreeTranslatorTranslatePositionFunc
|
||||
// TranslateRangeFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method TranslateRange.
|
||||
TranslateRangeFunc *GitTreeTranslatorTranslateRangeFunc
|
||||
}
|
||||
|
||||
// NewMockGitTreeTranslator creates a new mock of the GitTreeTranslator
|
||||
@ -39,18 +38,18 @@ type MockGitTreeTranslator struct {
|
||||
// overwritten.
|
||||
func NewMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
return &MockGitTreeTranslator{
|
||||
GetSourceCommitFunc: &GitTreeTranslatorGetSourceCommitFunc{
|
||||
defaultHook: func() (r0 api.CommitID) {
|
||||
PrefetchFunc: &GitTreeTranslatorPrefetchFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath) {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetTargetCommitPositionFromSourcePositionFunc: &GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Position, bool) (r0 shared.Position, r1 bool, r2 error) {
|
||||
TranslatePositionFunc: &GitTreeTranslatorTranslatePositionFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (r0 core.Option[scip.Position], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetTargetCommitRangeFromSourceRangeFunc: &GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Range, bool) (r0 shared.Range, r1 bool, r2 error) {
|
||||
TranslateRangeFunc: &GitTreeTranslatorTranslateRangeFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (r0 core.Option[scip.Range], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -62,19 +61,19 @@ func NewMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
// overwritten.
|
||||
func NewStrictMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
return &MockGitTreeTranslator{
|
||||
GetSourceCommitFunc: &GitTreeTranslatorGetSourceCommitFunc{
|
||||
defaultHook: func() api.CommitID {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.GetSourceCommit")
|
||||
PrefetchFunc: &GitTreeTranslatorPrefetchFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.Prefetch")
|
||||
},
|
||||
},
|
||||
GetTargetCommitPositionFromSourcePositionFunc: &GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.GetTargetCommitPositionFromSourcePosition")
|
||||
TranslatePositionFunc: &GitTreeTranslatorTranslatePositionFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.TranslatePosition")
|
||||
},
|
||||
},
|
||||
GetTargetCommitRangeFromSourceRangeFunc: &GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.GetTargetCommitRangeFromSourceRange")
|
||||
TranslateRangeFunc: &GitTreeTranslatorTranslateRangeFunc{
|
||||
defaultHook: func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.TranslateRange")
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -85,49 +84,47 @@ func NewStrictMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
// implementation, unless overwritten.
|
||||
func NewMockGitTreeTranslatorFrom(i GitTreeTranslator) *MockGitTreeTranslator {
|
||||
return &MockGitTreeTranslator{
|
||||
GetSourceCommitFunc: &GitTreeTranslatorGetSourceCommitFunc{
|
||||
defaultHook: i.GetSourceCommit,
|
||||
PrefetchFunc: &GitTreeTranslatorPrefetchFunc{
|
||||
defaultHook: i.Prefetch,
|
||||
},
|
||||
GetTargetCommitPositionFromSourcePositionFunc: &GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc{
|
||||
defaultHook: i.GetTargetCommitPositionFromSourcePosition,
|
||||
TranslatePositionFunc: &GitTreeTranslatorTranslatePositionFunc{
|
||||
defaultHook: i.TranslatePosition,
|
||||
},
|
||||
GetTargetCommitRangeFromSourceRangeFunc: &GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc{
|
||||
defaultHook: i.GetTargetCommitRangeFromSourceRange,
|
||||
TranslateRangeFunc: &GitTreeTranslatorTranslateRangeFunc{
|
||||
defaultHook: i.TranslateRange,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetSourceCommitFunc describes the behavior when the
|
||||
// GetSourceCommit method of the parent MockGitTreeTranslator instance is
|
||||
// invoked.
|
||||
type GitTreeTranslatorGetSourceCommitFunc struct {
|
||||
defaultHook func() api.CommitID
|
||||
hooks []func() api.CommitID
|
||||
history []GitTreeTranslatorGetSourceCommitFuncCall
|
||||
// GitTreeTranslatorPrefetchFunc describes the behavior when the Prefetch
|
||||
// method of the parent MockGitTreeTranslator instance is invoked.
|
||||
type GitTreeTranslatorPrefetchFunc struct {
|
||||
defaultHook func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath)
|
||||
hooks []func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath)
|
||||
history []GitTreeTranslatorPrefetchFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetSourceCommit delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockGitTreeTranslator) GetSourceCommit() api.CommitID {
|
||||
r0 := m.GetSourceCommitFunc.nextHook()()
|
||||
m.GetSourceCommitFunc.appendCall(GitTreeTranslatorGetSourceCommitFuncCall{r0})
|
||||
return r0
|
||||
// Prefetch delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockGitTreeTranslator) Prefetch(v0 context.Context, v1 api.CommitID, v2 api.CommitID, v3 []core.RepoRelPath) {
|
||||
m.PrefetchFunc.nextHook()(v0, v1, v2, v3)
|
||||
m.PrefetchFunc.appendCall(GitTreeTranslatorPrefetchFuncCall{v0, v1, v2, v3})
|
||||
return
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the GetSourceCommit
|
||||
// method of the parent MockGitTreeTranslator instance is invoked and the
|
||||
// hook queue is empty.
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) SetDefaultHook(hook func() api.CommitID) {
|
||||
// SetDefaultHook sets function that is called when the Prefetch method of
|
||||
// the parent MockGitTreeTranslator instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *GitTreeTranslatorPrefetchFunc) SetDefaultHook(hook func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetSourceCommit method of the parent MockGitTreeTranslator instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) PushHook(hook func() api.CommitID) {
|
||||
// Prefetch method of the parent MockGitTreeTranslator instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *GitTreeTranslatorPrefetchFunc) PushHook(hook func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -135,20 +132,20 @@ func (f *GitTreeTranslatorGetSourceCommitFunc) PushHook(hook func() api.CommitID
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) SetDefaultReturn(r0 api.CommitID) {
|
||||
f.SetDefaultHook(func() api.CommitID {
|
||||
return r0
|
||||
func (f *GitTreeTranslatorPrefetchFunc) SetDefaultReturn() {
|
||||
f.SetDefaultHook(func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath) {
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) PushReturn(r0 api.CommitID) {
|
||||
f.PushHook(func() api.CommitID {
|
||||
return r0
|
||||
func (f *GitTreeTranslatorPrefetchFunc) PushReturn() {
|
||||
f.PushHook(func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath) {
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) nextHook() func() api.CommitID {
|
||||
func (f *GitTreeTranslatorPrefetchFunc) nextHook() func(context.Context, api.CommitID, api.CommitID, []core.RepoRelPath) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -161,76 +158,83 @@ func (f *GitTreeTranslatorGetSourceCommitFunc) nextHook() func() api.CommitID {
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) appendCall(r0 GitTreeTranslatorGetSourceCommitFuncCall) {
|
||||
func (f *GitTreeTranslatorPrefetchFunc) appendCall(r0 GitTreeTranslatorPrefetchFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of GitTreeTranslatorGetSourceCommitFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *GitTreeTranslatorGetSourceCommitFunc) History() []GitTreeTranslatorGetSourceCommitFuncCall {
|
||||
// History returns a sequence of GitTreeTranslatorPrefetchFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *GitTreeTranslatorPrefetchFunc) History() []GitTreeTranslatorPrefetchFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]GitTreeTranslatorGetSourceCommitFuncCall, len(f.history))
|
||||
history := make([]GitTreeTranslatorPrefetchFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetSourceCommitFuncCall is an object that describes an
|
||||
// invocation of method GetSourceCommit on an instance of
|
||||
// MockGitTreeTranslator.
|
||||
type GitTreeTranslatorGetSourceCommitFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// GitTreeTranslatorPrefetchFuncCall is an object that describes an
|
||||
// invocation of method Prefetch on an instance of MockGitTreeTranslator.
|
||||
type GitTreeTranslatorPrefetchFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Result0 api.CommitID
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 api.CommitID
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 api.CommitID
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 []core.RepoRelPath
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetSourceCommitFuncCall) Args() []interface{} {
|
||||
func (c GitTreeTranslatorPrefetchFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorPrefetchFuncCall) Results() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetSourceCommitFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc describes
|
||||
// the behavior when the GetTargetCommitPositionFromSourcePosition method of
|
||||
// the parent MockGitTreeTranslator instance is invoked.
|
||||
type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc struct {
|
||||
defaultHook func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error)
|
||||
hooks []func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error)
|
||||
history []GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall
|
||||
// GitTreeTranslatorTranslatePositionFunc describes the behavior when the
|
||||
// TranslatePosition method of the parent MockGitTreeTranslator instance is
|
||||
// invoked.
|
||||
type GitTreeTranslatorTranslatePositionFunc struct {
|
||||
defaultHook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error)
|
||||
hooks []func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error)
|
||||
history []GitTreeTranslatorTranslatePositionFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetTargetCommitPositionFromSourcePosition delegates to the next hook
|
||||
// function in the queue and stores the parameter and result values of this
|
||||
// invocation.
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitPositionFromSourcePosition(v0 context.Context, v1 string, v2 string, v3 shared.Position, v4 bool) (shared.Position, bool, error) {
|
||||
r0, r1, r2 := m.GetTargetCommitPositionFromSourcePositionFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.GetTargetCommitPositionFromSourcePositionFunc.appendCall(GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall{v0, v1, v2, v3, v4, r0, r1, r2})
|
||||
return r0, r1, r2
|
||||
// TranslatePosition delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockGitTreeTranslator) TranslatePosition(v0 context.Context, v1 api.CommitID, v2 api.CommitID, v3 core.RepoRelPath, v4 scip.Position) (core.Option[scip.Position], error) {
|
||||
r0, r1 := m.TranslatePositionFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.TranslatePositionFunc.appendCall(GitTreeTranslatorTranslatePositionFuncCall{v0, v1, v2, v3, v4, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetTargetCommitPositionFromSourcePosition method of the parent
|
||||
// MockGitTreeTranslator instance is invoked and the hook queue is empty.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultHook(hook func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error)) {
|
||||
// SetDefaultHook sets function that is called when the TranslatePosition
|
||||
// method of the parent MockGitTreeTranslator instance is invoked and the
|
||||
// hook queue is empty.
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) SetDefaultHook(hook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetTargetCommitPositionFromSourcePosition method of the parent
|
||||
// MockGitTreeTranslator instance invokes the hook at the front of the queue
|
||||
// and discards it. After the queue is empty, the default hook function is
|
||||
// invoked for any future action.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushHook(hook func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error)) {
|
||||
// TranslatePosition method of the parent MockGitTreeTranslator instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) PushHook(hook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -238,20 +242,20 @@ func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushHoo
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultReturn(r0 shared.Position, r1 bool, r2 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error) {
|
||||
return r0, r1, r2
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) SetDefaultReturn(r0 core.Option[scip.Position], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushReturn(r0 shared.Position, r1 bool, r2 error) {
|
||||
f.PushHook(func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error) {
|
||||
return r0, r1, r2
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) PushReturn(r0 core.Option[scip.Position], r1 error) {
|
||||
f.PushHook(func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) nextHook() func(context.Context, string, string, shared.Position, bool) (shared.Position, bool, error) {
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) nextHook() func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Position) (core.Option[scip.Position], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -264,99 +268,93 @@ func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) nextHoo
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) appendCall(r0 GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall) {
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) appendCall(r0 GitTreeTranslatorTranslatePositionFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of
|
||||
// GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall
|
||||
// History returns a sequence of GitTreeTranslatorTranslatePositionFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) History() []GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall {
|
||||
func (f *GitTreeTranslatorTranslatePositionFunc) History() []GitTreeTranslatorTranslatePositionFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall, len(f.history))
|
||||
history := make([]GitTreeTranslatorTranslatePositionFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall is an
|
||||
// object that describes an invocation of method
|
||||
// GetTargetCommitPositionFromSourcePosition on an instance of
|
||||
// GitTreeTranslatorTranslatePositionFuncCall is an object that describes an
|
||||
// invocation of method TranslatePosition on an instance of
|
||||
// MockGitTreeTranslator.
|
||||
type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall struct {
|
||||
type GitTreeTranslatorTranslatePositionFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 string
|
||||
Arg1 api.CommitID
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
Arg2 api.CommitID
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 shared.Position
|
||||
Arg3 core.RepoRelPath
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 bool
|
||||
Arg4 scip.Position
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 shared.Position
|
||||
Result0 core.Option[scip.Position]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 bool
|
||||
// Result2 is the value of the 3rd result returned from this method
|
||||
// invocation.
|
||||
Result2 error
|
||||
Result1 error
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall) Args() []interface{} {
|
||||
func (c GitTreeTranslatorTranslatePositionFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1, c.Result2}
|
||||
func (c GitTreeTranslatorTranslatePositionFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc describes the
|
||||
// behavior when the GetTargetCommitRangeFromSourceRange method of the
|
||||
// parent MockGitTreeTranslator instance is invoked.
|
||||
type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc struct {
|
||||
defaultHook func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error)
|
||||
hooks []func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error)
|
||||
history []GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall
|
||||
// GitTreeTranslatorTranslateRangeFunc describes the behavior when the
|
||||
// TranslateRange method of the parent MockGitTreeTranslator instance is
|
||||
// invoked.
|
||||
type GitTreeTranslatorTranslateRangeFunc struct {
|
||||
defaultHook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error)
|
||||
hooks []func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error)
|
||||
history []GitTreeTranslatorTranslateRangeFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetTargetCommitRangeFromSourceRange delegates to the next hook function
|
||||
// in the queue and stores the parameter and result values of this
|
||||
// invocation.
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitRangeFromSourceRange(v0 context.Context, v1 string, v2 string, v3 shared.Range, v4 bool) (shared.Range, bool, error) {
|
||||
r0, r1, r2 := m.GetTargetCommitRangeFromSourceRangeFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.GetTargetCommitRangeFromSourceRangeFunc.appendCall(GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall{v0, v1, v2, v3, v4, r0, r1, r2})
|
||||
return r0, r1, r2
|
||||
// TranslateRange delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockGitTreeTranslator) TranslateRange(v0 context.Context, v1 api.CommitID, v2 api.CommitID, v3 core.RepoRelPath, v4 scip.Range) (core.Option[scip.Range], error) {
|
||||
r0, r1 := m.TranslateRangeFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.TranslateRangeFunc.appendCall(GitTreeTranslatorTranslateRangeFuncCall{v0, v1, v2, v3, v4, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetTargetCommitRangeFromSourceRange method of the parent
|
||||
// MockGitTreeTranslator instance is invoked and the hook queue is empty.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultHook(hook func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error)) {
|
||||
// SetDefaultHook sets function that is called when the TranslateRange
|
||||
// method of the parent MockGitTreeTranslator instance is invoked and the
|
||||
// hook queue is empty.
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) SetDefaultHook(hook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetTargetCommitRangeFromSourceRange method of the parent
|
||||
// MockGitTreeTranslator instance invokes the hook at the front of the queue
|
||||
// and discards it. After the queue is empty, the default hook function is
|
||||
// invoked for any future action.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushHook(hook func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error)) {
|
||||
// TranslateRange method of the parent MockGitTreeTranslator instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) PushHook(hook func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -364,20 +362,20 @@ func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushHook(hook
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultReturn(r0 shared.Range, r1 bool, r2 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error) {
|
||||
return r0, r1, r2
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) SetDefaultReturn(r0 core.Option[scip.Range], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushReturn(r0 shared.Range, r1 bool, r2 error) {
|
||||
f.PushHook(func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error) {
|
||||
return r0, r1, r2
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) PushReturn(r0 core.Option[scip.Range], r1 error) {
|
||||
f.PushHook(func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) nextHook() func(context.Context, string, string, shared.Range, bool) (shared.Range, bool, error) {
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) nextHook() func(context.Context, api.CommitID, api.CommitID, core.RepoRelPath, scip.Range) (core.Option[scip.Range], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -390,65 +388,60 @@ func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) nextHook() fu
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) appendCall(r0 GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall) {
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) appendCall(r0 GitTreeTranslatorTranslateRangeFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of
|
||||
// GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) History() []GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall {
|
||||
// History returns a sequence of GitTreeTranslatorTranslateRangeFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *GitTreeTranslatorTranslateRangeFunc) History() []GitTreeTranslatorTranslateRangeFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall, len(f.history))
|
||||
history := make([]GitTreeTranslatorTranslateRangeFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall is an object
|
||||
// that describes an invocation of method
|
||||
// GetTargetCommitRangeFromSourceRange on an instance of
|
||||
// GitTreeTranslatorTranslateRangeFuncCall is an object that describes an
|
||||
// invocation of method TranslateRange on an instance of
|
||||
// MockGitTreeTranslator.
|
||||
type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall struct {
|
||||
type GitTreeTranslatorTranslateRangeFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 string
|
||||
Arg1 api.CommitID
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
Arg2 api.CommitID
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 shared.Range
|
||||
Arg3 core.RepoRelPath
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 bool
|
||||
Arg4 scip.Range
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 shared.Range
|
||||
Result0 core.Option[scip.Range]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 bool
|
||||
// Result2 is the value of the 3rd result returned from this method
|
||||
// invocation.
|
||||
Result2 error
|
||||
Result1 error
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall) Args() []interface{} {
|
||||
func (c GitTreeTranslatorTranslateRangeFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1, c.Result2}
|
||||
func (c GitTreeTranslatorTranslateRangeFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// MockUploadService is a mock implementation of the UploadService interface
|
||||
@ -477,12 +470,12 @@ type MockUploadService struct {
|
||||
func NewMockUploadService() *MockUploadService {
|
||||
return &MockUploadService{
|
||||
GetCompletedUploadsByIDsFunc: &UploadServiceGetCompletedUploadsByIDsFunc{
|
||||
defaultHook: func(context.Context, []int) (r0 []shared1.CompletedUpload, r1 error) {
|
||||
defaultHook: func(context.Context, []int) (r0 []shared.CompletedUpload, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetCompletedUploadsWithDefinitionsForMonikersFunc: &UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc{
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) (r0 []shared1.CompletedUpload, r1 error) {
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) (r0 []shared.CompletedUpload, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -492,7 +485,7 @@ func NewMockUploadService() *MockUploadService {
|
||||
},
|
||||
},
|
||||
InferClosestUploadsFunc: &UploadServiceInferClosestUploadsFunc{
|
||||
defaultHook: func(context.Context, shared1.UploadMatchingOptions) (r0 []shared1.CompletedUpload, r1 error) {
|
||||
defaultHook: func(context.Context, shared.UploadMatchingOptions) (r0 []shared.CompletedUpload, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -504,12 +497,12 @@ func NewMockUploadService() *MockUploadService {
|
||||
func NewStrictMockUploadService() *MockUploadService {
|
||||
return &MockUploadService{
|
||||
GetCompletedUploadsByIDsFunc: &UploadServiceGetCompletedUploadsByIDsFunc{
|
||||
defaultHook: func(context.Context, []int) ([]shared1.CompletedUpload, error) {
|
||||
defaultHook: func(context.Context, []int) ([]shared.CompletedUpload, error) {
|
||||
panic("unexpected invocation of MockUploadService.GetCompletedUploadsByIDs")
|
||||
},
|
||||
},
|
||||
GetCompletedUploadsWithDefinitionsForMonikersFunc: &UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc{
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error) {
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error) {
|
||||
panic("unexpected invocation of MockUploadService.GetCompletedUploadsWithDefinitionsForMonikers")
|
||||
},
|
||||
},
|
||||
@ -519,7 +512,7 @@ func NewStrictMockUploadService() *MockUploadService {
|
||||
},
|
||||
},
|
||||
InferClosestUploadsFunc: &UploadServiceInferClosestUploadsFunc{
|
||||
defaultHook: func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error) {
|
||||
defaultHook: func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error) {
|
||||
panic("unexpected invocation of MockUploadService.InferClosestUploads")
|
||||
},
|
||||
},
|
||||
@ -550,15 +543,15 @@ func NewMockUploadServiceFrom(i UploadService) *MockUploadService {
|
||||
// GetCompletedUploadsByIDs method of the parent MockUploadService instance
|
||||
// is invoked.
|
||||
type UploadServiceGetCompletedUploadsByIDsFunc struct {
|
||||
defaultHook func(context.Context, []int) ([]shared1.CompletedUpload, error)
|
||||
hooks []func(context.Context, []int) ([]shared1.CompletedUpload, error)
|
||||
defaultHook func(context.Context, []int) ([]shared.CompletedUpload, error)
|
||||
hooks []func(context.Context, []int) ([]shared.CompletedUpload, error)
|
||||
history []UploadServiceGetCompletedUploadsByIDsFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetCompletedUploadsByIDs delegates to the next hook function in the queue
|
||||
// and stores the parameter and result values of this invocation.
|
||||
func (m *MockUploadService) GetCompletedUploadsByIDs(v0 context.Context, v1 []int) ([]shared1.CompletedUpload, error) {
|
||||
func (m *MockUploadService) GetCompletedUploadsByIDs(v0 context.Context, v1 []int) ([]shared.CompletedUpload, error) {
|
||||
r0, r1 := m.GetCompletedUploadsByIDsFunc.nextHook()(v0, v1)
|
||||
m.GetCompletedUploadsByIDsFunc.appendCall(UploadServiceGetCompletedUploadsByIDsFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
@ -567,7 +560,7 @@ func (m *MockUploadService) GetCompletedUploadsByIDs(v0 context.Context, v1 []in
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCompletedUploadsByIDs method of the parent MockUploadService instance
|
||||
// is invoked and the hook queue is empty.
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) SetDefaultHook(hook func(context.Context, []int) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) SetDefaultHook(hook func(context.Context, []int) ([]shared.CompletedUpload, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -576,7 +569,7 @@ func (f *UploadServiceGetCompletedUploadsByIDsFunc) SetDefaultHook(hook func(con
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) PushHook(hook func(context.Context, []int) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) PushHook(hook func(context.Context, []int) ([]shared.CompletedUpload, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -584,20 +577,20 @@ func (f *UploadServiceGetCompletedUploadsByIDsFunc) PushHook(hook func(context.C
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) SetDefaultReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []int) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) SetDefaultReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []int) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) PushReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, []int) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) PushReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, []int) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) nextHook() func(context.Context, []int) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsByIDsFunc) nextHook() func(context.Context, []int) ([]shared.CompletedUpload, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -640,7 +633,7 @@ type UploadServiceGetCompletedUploadsByIDsFuncCall struct {
|
||||
Arg1 []int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.CompletedUpload
|
||||
Result0 []shared.CompletedUpload
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -662,8 +655,8 @@ func (c UploadServiceGetCompletedUploadsByIDsFuncCall) Results() []interface{} {
|
||||
// the behavior when the GetCompletedUploadsWithDefinitionsForMonikers
|
||||
// method of the parent MockUploadService instance is invoked.
|
||||
type UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc struct {
|
||||
defaultHook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error)
|
||||
hooks []func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error)
|
||||
defaultHook func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error)
|
||||
hooks []func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error)
|
||||
history []UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
@ -671,7 +664,7 @@ type UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc struct {
|
||||
// GetCompletedUploadsWithDefinitionsForMonikers delegates to the next hook
|
||||
// function in the queue and stores the parameter and result values of this
|
||||
// invocation.
|
||||
func (m *MockUploadService) GetCompletedUploadsWithDefinitionsForMonikers(v0 context.Context, v1 []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error) {
|
||||
func (m *MockUploadService) GetCompletedUploadsWithDefinitionsForMonikers(v0 context.Context, v1 []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error) {
|
||||
r0, r1 := m.GetCompletedUploadsWithDefinitionsForMonikersFunc.nextHook()(v0, v1)
|
||||
m.GetCompletedUploadsWithDefinitionsForMonikersFunc.appendCall(UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
@ -680,7 +673,7 @@ func (m *MockUploadService) GetCompletedUploadsWithDefinitionsForMonikers(v0 con
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCompletedUploadsWithDefinitionsForMonikers method of the parent
|
||||
// MockUploadService instance is invoked and the hook queue is empty.
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) SetDefaultHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) SetDefaultHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -689,7 +682,7 @@ func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) SetDefa
|
||||
// MockUploadService instance invokes the hook at the front of the queue and
|
||||
// discards it. After the queue is empty, the default hook function is
|
||||
// invoked for any future action.
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) PushHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) PushHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -697,20 +690,20 @@ func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) PushHoo
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) SetDefaultReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) SetDefaultReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) PushReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) PushReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) nextHook() func(context.Context, []precise.QualifiedMonikerData) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFunc) nextHook() func(context.Context, []precise.QualifiedMonikerData) ([]shared.CompletedUpload, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -754,7 +747,7 @@ type UploadServiceGetCompletedUploadsWithDefinitionsForMonikersFuncCall struct {
|
||||
Arg1 []precise.QualifiedMonikerData
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.CompletedUpload
|
||||
Result0 []shared.CompletedUpload
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -909,15 +902,15 @@ func (c UploadServiceGetUploadIDsWithReferencesFuncCall) Results() []interface{}
|
||||
// InferClosestUploads method of the parent MockUploadService instance is
|
||||
// invoked.
|
||||
type UploadServiceInferClosestUploadsFunc struct {
|
||||
defaultHook func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error)
|
||||
hooks []func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error)
|
||||
defaultHook func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error)
|
||||
hooks []func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error)
|
||||
history []UploadServiceInferClosestUploadsFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// InferClosestUploads delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error) {
|
||||
func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 shared.UploadMatchingOptions) ([]shared.CompletedUpload, error) {
|
||||
r0, r1 := m.InferClosestUploadsFunc.nextHook()(v0, v1)
|
||||
m.InferClosestUploadsFunc.appendCall(UploadServiceInferClosestUploadsFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
@ -926,7 +919,7 @@ func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 shared1.U
|
||||
// SetDefaultHook sets function that is called when the InferClosestUploads
|
||||
// method of the parent MockUploadService instance is invoked and the hook
|
||||
// queue is empty.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -935,7 +928,7 @@ func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error)) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -943,20 +936,20 @@ func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Contex
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushReturn(r0 []shared1.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushReturn(r0 []shared.CompletedUpload, r1 error) {
|
||||
f.PushHook(func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceInferClosestUploadsFunc) nextHook() func(context.Context, shared1.UploadMatchingOptions) ([]shared1.CompletedUpload, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) nextHook() func(context.Context, shared.UploadMatchingOptions) ([]shared.CompletedUpload, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -995,10 +988,10 @@ type UploadServiceInferClosestUploadsFuncCall struct {
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 shared1.UploadMatchingOptions
|
||||
Arg1 shared.UploadMatchingOptions
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.CompletedUpload
|
||||
Result0 []shared.CompletedUpload
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
|
||||
@ -56,7 +56,6 @@ func NewRequestState(
|
||||
commit api.CommitID,
|
||||
path core.RepoRelPath,
|
||||
maxIndexes int,
|
||||
hunkCache HunkCache,
|
||||
) RequestState {
|
||||
r := &RequestState{
|
||||
// repoStore: repoStore,
|
||||
@ -66,7 +65,7 @@ func NewRequestState(
|
||||
}
|
||||
r.SetUploadsDataLoader(uploads)
|
||||
r.SetAuthChecker(authChecker)
|
||||
r.SetLocalGitTreeTranslator(gitserverClient, repo, commit, hunkCache)
|
||||
r.SetLocalGitTreeTranslator(gitserverClient, repo)
|
||||
r.SetLocalCommitCache(repoStore, gitserverClient)
|
||||
r.SetMaximumIndexesPerMonikerSearch(maxIndexes)
|
||||
|
||||
@ -96,13 +95,8 @@ func (r *RequestState) SetUploadsDataLoader(uploads []shared.CompletedUpload) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RequestState) SetLocalGitTreeTranslator(client gitserver.Client, repo *sgTypes.Repo, commit api.CommitID, hunkCache HunkCache) {
|
||||
args := &TranslationBase{
|
||||
Repo: repo,
|
||||
Commit: commit,
|
||||
}
|
||||
|
||||
r.GitTreeTranslator = NewGitTreeTranslator(client, args, hunkCache)
|
||||
func (r *RequestState) SetLocalGitTreeTranslator(client gitserver.Client, repo *sgTypes.Repo) {
|
||||
r.GitTreeTranslator = NewGitTreeTranslator(client, *repo)
|
||||
}
|
||||
|
||||
func (r *RequestState) SetLocalCommitCache(repoStore database.RepoStore, client gitserver.Client) {
|
||||
|
||||
@ -314,11 +314,12 @@ func (s *Service) getSourceRange(ctx context.Context, args RequestArgs, requestS
|
||||
// No diffs between distinct repositories
|
||||
return commit, rng, true, nil
|
||||
}
|
||||
|
||||
if sourceRange, ok, err := requestState.GitTreeTranslator.GetTargetCommitRangeFromSourceRange(ctx, commit, path.RawValue(), rng, true); err != nil {
|
||||
sourceRangeOpt, err := requestState.GitTreeTranslator.TranslateRange(ctx, api.CommitID(commit), args.Commit, path, rng.ToSCIPRange())
|
||||
if err != nil {
|
||||
return "", shared.Range{}, false, errors.Wrap(err, "gitTreeTranslator.GetTargetCommitRangeFromSourceRange")
|
||||
} else if ok {
|
||||
return string(args.Commit), sourceRange, true, nil
|
||||
}
|
||||
if sourceRange, ok := sourceRangeOpt.Get(); ok {
|
||||
return string(args.Commit), shared.TranslateRange(sourceRange), true, nil
|
||||
}
|
||||
|
||||
return commit, rng, false, nil
|
||||
@ -809,21 +810,20 @@ func (s *Service) getVisibleUploads(ctx context.Context, line, character int, r
|
||||
// getVisibleUpload returns the current target path and the given position for the given upload. If
|
||||
// the upload cannot be adjusted, a false-valued flag is returned.
|
||||
func (s *Service) getVisibleUpload(ctx context.Context, line, character int, upload uploadsshared.CompletedUpload, r RequestState) (visibleUpload, bool, error) {
|
||||
position := shared.Position{
|
||||
Line: line,
|
||||
Character: character,
|
||||
position := scip.Position{
|
||||
Line: int32(line),
|
||||
Character: int32(character),
|
||||
}
|
||||
|
||||
basePath := r.Path.RawValue()
|
||||
targetPosition, ok, err := r.GitTreeTranslator.GetTargetCommitPositionFromSourcePosition(ctx, upload.Commit, basePath, position, false)
|
||||
if err != nil || !ok {
|
||||
targetPosition, err := r.GitTreeTranslator.TranslatePosition(ctx, r.Commit, upload.GetCommit(), r.Path, position)
|
||||
if err != nil || targetPosition.IsNone() {
|
||||
return visibleUpload{}, false, errors.Wrap(err, "gitTreeTranslator.GetTargetCommitPositionFromSourcePosition")
|
||||
}
|
||||
|
||||
return visibleUpload{
|
||||
Upload: upload,
|
||||
TargetPath: r.Path,
|
||||
TargetPosition: targetPosition,
|
||||
TargetPosition: shared.TranslatePosition(targetPosition.Unwrap()),
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
@ -879,15 +879,10 @@ func (s *Service) SnapshotForDocument(ctx context.Context, repositoryID api.Repo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// cache is keyed by repoID:sourceCommit:targetCommit:path, so we only need a size of 1
|
||||
hunkcache, err := NewHunkCache(1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gittranslator := NewGitTreeTranslator(s.gitserver, &TranslationBase{
|
||||
Repo: repo,
|
||||
Commit: commit,
|
||||
}, hunkcache)
|
||||
gittranslator := NewGitTreeTranslator(s.gitserver, *repo)
|
||||
|
||||
linemap := newLinemap(string(file))
|
||||
formatter := scip.LenientVerboseSymbolFormatter
|
||||
@ -965,19 +960,17 @@ func (s *Service) SnapshotForDocument(ctx context.Context, repositoryID api.Repo
|
||||
}
|
||||
}
|
||||
|
||||
newRange, ok, err := gittranslator.GetTargetCommitPositionFromSourcePosition(ctx, upload.Commit, path.RawValue(), shared.Position{
|
||||
Line: int(originalRange.Start.Line),
|
||||
Character: int(originalRange.Start.Character),
|
||||
}, false)
|
||||
newPositionOpt, err := gittranslator.TranslatePosition(ctx, commit, upload.GetCommit(), path, originalRange.Start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newPosition, ok := newPositionOpt.Get()
|
||||
// if the line was changed, then we're not providing precise codeintel for this line, so skip it
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
snapshotData.DocumentOffset = linemap.positions[newRange.Line+1]
|
||||
snapshotData.DocumentOffset = linemap.positions[newPosition.Line+1]
|
||||
|
||||
data = append(data, snapshotData)
|
||||
}
|
||||
@ -985,7 +978,7 @@ func (s *Service) SnapshotForDocument(ctx context.Context, repositoryID api.Repo
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) SCIPDocument(ctx context.Context, gitTreeTranslator GitTreeTranslator, upload core.UploadLike, path core.RepoRelPath) (*scip.Document, error) {
|
||||
func (s *Service) SCIPDocument(ctx context.Context, gitTreeTranslator GitTreeTranslator, upload core.UploadLike, targetCommit api.CommitID, path core.RepoRelPath) (*scip.Document, error) {
|
||||
optRawDocument, err := s.lsifstore.SCIPDocument(ctx, upload.GetID(), core.NewUploadRelPath(upload, path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -994,28 +987,24 @@ func (s *Service) SCIPDocument(ctx context.Context, gitTreeTranslator GitTreeTra
|
||||
if !ok {
|
||||
return nil, errors.New("document not found")
|
||||
}
|
||||
// TODO(efritz)
|
||||
// The caller shouldn't need to care whether the document was uploaded
|
||||
// for a different root or not.
|
||||
rawDocument.RelativePath = path.RawValue()
|
||||
if gitTreeTranslator.GetSourceCommit() == upload.GetCommit() {
|
||||
if upload.GetCommit() == targetCommit {
|
||||
return rawDocument, nil
|
||||
}
|
||||
translated := make([]*scip.Occurrence, 0, len(rawDocument.Occurrences))
|
||||
for _, occ := range rawDocument.Occurrences {
|
||||
sourceRange := scip.NewRangeUnchecked(occ.Range)
|
||||
sourceSharedRange := shared.TranslateRange(sourceRange)
|
||||
// TODO: This will be ~quadratic in document size; see TODO(id: add-bulk-translation-api)
|
||||
targetSharedRange, success, err := gitTreeTranslator.GetTargetCommitRangeFromSourceRange(
|
||||
ctx, string(upload.GetCommit()), path.RawValue(), sourceSharedRange, true,
|
||||
)
|
||||
targetRangeOpt, err := gitTreeTranslator.TranslateRange(ctx, upload.GetCommit(), targetCommit, path, sourceRange)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "While translating ranges between commits")
|
||||
}
|
||||
targetRange, success := targetRangeOpt.Get()
|
||||
if !success {
|
||||
continue
|
||||
}
|
||||
occ.Range = targetSharedRange.ToSCIPRange().SCIPRange()
|
||||
occ.Range = targetRange.SCIPRange()
|
||||
translated = append(translated, occ)
|
||||
}
|
||||
rawDocument.Occurrences = translated
|
||||
@ -1144,7 +1133,7 @@ func (s *Service) SyntacticUsages(
|
||||
if err != nil {
|
||||
return SyntacticUsagesResult{}, PreviousSyntacticSearch{}, err
|
||||
}
|
||||
index := NewMappedIndexFromTranslator(s.lsifstore, gitTreeTranslator, upload)
|
||||
index := NewMappedIndexFromTranslator(s.lsifstore, gitTreeTranslator, upload, args.Commit)
|
||||
return syntacticUsagesImpl(ctx, trace, s.searchClient, index, args)
|
||||
}
|
||||
|
||||
@ -1230,7 +1219,7 @@ func (s *Service) SearchBasedUsages(
|
||||
if uploadErr != nil {
|
||||
trace.Info("no syntactic upload found, return all search-based results", log.Error(err))
|
||||
} else {
|
||||
syntacticIndex = core.Some[MappedIndex](NewMappedIndexFromTranslator(s.lsifstore, gitTreeTranslator, upload))
|
||||
syntacticIndex = core.Some[MappedIndex](NewMappedIndexFromTranslator(s.lsifstore, gitTreeTranslator, upload, args.Commit))
|
||||
}
|
||||
}
|
||||
return searchBasedUsagesImpl(ctx, trace, s.searchClient, args, symbolName, language, syntacticIndex)
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
package codenav
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
)
|
||||
|
||||
func mockedGitTreeTranslator() GitTreeTranslator {
|
||||
mockPositionAdjuster := NewMockGitTreeTranslator()
|
||||
mockPositionAdjuster.GetTargetCommitPositionFromSourcePositionFunc.SetDefaultHook(func(ctx context.Context, commit string, path string, pos shared.Position, _ bool) (shared.Position, bool, error) {
|
||||
return pos, true, nil
|
||||
})
|
||||
mockPositionAdjuster.GetTargetCommitRangeFromSourceRangeFunc.SetDefaultHook(func(ctx context.Context, commit string, path string, rx shared.Range, _ bool) (shared.Range, bool, error) {
|
||||
return rx, true, nil
|
||||
})
|
||||
|
||||
return mockPositionAdjuster
|
||||
}
|
||||
@ -30,7 +30,6 @@ func TestDiagnostics(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -38,7 +37,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{})
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -106,7 +105,6 @@ func TestDiagnosticsWithSubRepoPermissions(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -114,7 +112,7 @@ func TestDiagnosticsWithSubRepoPermissions(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{})
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/client"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
@ -27,7 +26,6 @@ func TestHover(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -35,7 +33,7 @@ func TestHover(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{ID: 42}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -84,7 +82,6 @@ func TestHoverRemote(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -92,7 +89,7 @@ func TestHoverRemote(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{ID: 42}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef"},
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ func TestGetDefinitions(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -36,7 +35,7 @@ func TestGetDefinitions(t *testing.T) {
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
mockRequest := PositionalRequestArgs{
|
||||
RequestArgs: RequestArgs{
|
||||
RepositoryID: 51,
|
||||
@ -90,7 +89,6 @@ func TestGetDefinitions(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -98,8 +96,8 @@ func TestGetDefinitions(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{ID: 42}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = mockedGitTreeTranslator()
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{ID: 42})
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
uploads1 := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -213,7 +211,6 @@ func TestGetReferences(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -221,7 +218,7 @@ func TestGetReferences(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -279,7 +276,6 @@ func TestGetReferences(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -287,7 +283,7 @@ func TestGetReferences(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -461,7 +457,6 @@ func TestGetImplementations(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
// Init service
|
||||
svc := newService(observation.TestContextTB(t), mockRepoStore, mockLsifStore, mockUploadSvc, mockGitserverClient, mockSearchClient, log.NoOp())
|
||||
@ -469,7 +464,7 @@ func TestGetImplementations(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.GitTreeTranslator = noopTranslator()
|
||||
|
||||
// Empty result set (prevents nil pointer as scanner is always non-nil)
|
||||
mockUploadSvc.GetUploadIDsWithReferencesFunc.PushReturn([]int{}, 0, 0, nil)
|
||||
|
||||
@ -46,7 +46,6 @@ func TestRanges(t *testing.T) {
|
||||
return gitserver.NewDiffFileIterator(io.NopCloser(bytes.NewReader([]byte{}))), nil
|
||||
})
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
mockLsifStore.FindDocumentIDsFunc.SetDefaultHook(findDocumentIDsFuncAllowAny())
|
||||
|
||||
@ -56,7 +55,7 @@ func TestRanges(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{})
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef1", Root: "sub1/", RepositoryID: 42},
|
||||
{ID: 51, Commit: "deadbeef1", Root: "sub2/", RepositoryID: 42},
|
||||
|
||||
@ -23,7 +23,6 @@ func TestStencil(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
mockLsifStore.FindDocumentIDsFunc.SetDefaultHook(findDocumentIDsFuncAllowAny())
|
||||
|
||||
@ -33,7 +32,7 @@ func TestStencil(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{})
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
@ -84,7 +83,6 @@ func TestStencilWithDuplicateRanges(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockSearchClient := client.NewMockSearchClient()
|
||||
hunkCache, _ := NewHunkCache(50)
|
||||
|
||||
mockLsifStore.FindDocumentIDsFunc.SetDefaultHook(findDocumentIDsFuncAllowAny())
|
||||
|
||||
@ -94,7 +92,7 @@ func TestStencilWithDuplicateRanges(t *testing.T) {
|
||||
// Set up request state
|
||||
mockRequestState := RequestState{}
|
||||
mockRequestState.SetLocalCommitCache(mockRepoStore, mockGitserverClient)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{}, mockCommit, hunkCache)
|
||||
mockRequestState.SetLocalGitTreeTranslator(mockGitserverClient, &sgtypes.Repo{})
|
||||
uploads := []uploadsshared.CompletedUpload{
|
||||
{ID: 50, Commit: "deadbeef", Root: "sub1/"},
|
||||
{ID: 51, Commit: "deadbeef", Root: "sub2/"},
|
||||
|
||||
@ -5,10 +5,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/sourcegraph/log"
|
||||
"github.com/sourcegraph/scip/bindings/go/scip"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
@ -55,7 +55,7 @@ func TestSearchBasedUsages_SyntacticMatchesGetRemovedFromSearchBasedResults(t *t
|
||||
commit := api.CommitID("deadbeef")
|
||||
mockSearchClient := FakeSearchClient().WithFile("path.java", commentRange, syntacticRange).Build()
|
||||
upload, lsifStore := setupUpload(commit, "", doc("path.java", ref("ref", syntacticRange)))
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(commit), upload)
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(), upload, commit)
|
||||
|
||||
usages, err := searchBasedUsagesImpl(
|
||||
context.Background(), observation.TestTraceLogger(log.NoOp()), mockSearchClient,
|
||||
@ -84,7 +84,7 @@ func TestSyntacticUsages(t *testing.T) {
|
||||
local("lcl", localRange)),
|
||||
doc("initial.java",
|
||||
ref("initial", initialRange)))
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(commit), upload)
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(), upload, commit)
|
||||
|
||||
syntacticUsages, _, err := syntacticUsagesImpl(
|
||||
context.Background(), observation.TestTraceLogger(log.NoOp()),
|
||||
@ -112,7 +112,7 @@ func TestSyntacticUsages_DocumentNotInIndex(t *testing.T) {
|
||||
upload, lsifStore := setupUpload(commit, "",
|
||||
doc("initial.java",
|
||||
ref("initial", initialRange)))
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(commit), upload)
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, noopTranslator(), upload, commit)
|
||||
syntacticUsages, _, err := syntacticUsagesImpl(
|
||||
context.Background(), observation.TestTraceLogger(log.NoOp()),
|
||||
mockSearchClient, fakeMappedIndex, UsagesForSymbolArgs{
|
||||
@ -143,11 +143,12 @@ func TestSyntacticUsages_IndexCommitTranslated(t *testing.T) {
|
||||
ref("ref", shiftSCIPRange(refRange, 2)),
|
||||
ref("edited", shiftSCIPRange(editedRange, 2)),
|
||||
ref("noMatch", noMatchRange)))
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, fakeTranslator(targetCommit, 2,
|
||||
func(_ string, r shared.Range) bool {
|
||||
// Ranges in the index are shifted by +2, so the translator needs to shift by -2 to match up with the search results.
|
||||
fakeMappedIndex := NewMappedIndexFromTranslator(lsifStore, fakeTranslator(upload.GetCommit(), targetCommit, -2,
|
||||
func(_ core.RepoRelPath, r scip.Range) bool {
|
||||
// When a line was edited in a diff we invalidate all occurrences on that line.
|
||||
return r.ToSCIPRange().CompareStrict(editedRange) == 0
|
||||
}), upload)
|
||||
return r.CompareStrict(editedRange) == 0
|
||||
}), upload, targetCommit)
|
||||
|
||||
syntacticUsages, _, err := syntacticUsagesImpl(
|
||||
context.Background(), observation.TestTraceLogger(log.NoOp()),
|
||||
|
||||
@ -26,7 +26,7 @@ type CodeNavService interface {
|
||||
GetClosestCompletedUploadsForBlob(context.Context, uploadsshared.UploadMatchingOptions) (_ []uploadsshared.CompletedUpload, err error)
|
||||
VisibleUploadsForPath(ctx context.Context, requestState codenav.RequestState) ([]uploadsshared.CompletedUpload, error)
|
||||
SnapshotForDocument(ctx context.Context, repositoryID api.RepoID, commit api.CommitID, path core.RepoRelPath, uploadID int) (data []shared.SnapshotData, err error)
|
||||
SCIPDocument(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error)
|
||||
SCIPDocument(_ context.Context, _ codenav.GitTreeTranslator, _ core.UploadLike, targetCommit api.CommitID, _ core.RepoRelPath) (*scip.Document, error)
|
||||
SyntacticUsages(context.Context, codenav.GitTreeTranslator, codenav.UsagesForSymbolArgs) (codenav.SyntacticUsagesResult, codenav.PreviousSyntacticSearch, *codenav.SyntacticUsagesError)
|
||||
SearchBasedUsages(context.Context, codenav.GitTreeTranslator, codenav.UsagesForSymbolArgs, core.Option[codenav.PreviousSyntacticSearch]) ([]codenav.SearchBasedMatch, error)
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ func NewMockCodeNavService() *MockCodeNavService {
|
||||
},
|
||||
},
|
||||
SCIPDocumentFunc: &CodeNavServiceSCIPDocumentFunc{
|
||||
defaultHook: func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (r0 *scip.Document, r1 error) {
|
||||
defaultHook: func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (r0 *scip.Document, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -353,7 +353,7 @@ func NewStrictMockCodeNavService() *MockCodeNavService {
|
||||
},
|
||||
},
|
||||
SCIPDocumentFunc: &CodeNavServiceSCIPDocumentFunc{
|
||||
defaultHook: func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error) {
|
||||
defaultHook: func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error) {
|
||||
panic("unexpected invocation of MockCodeNavService.SCIPDocument")
|
||||
},
|
||||
},
|
||||
@ -1479,24 +1479,24 @@ func (c CodeNavServiceGetStencilFuncCall) Results() []interface{} {
|
||||
// CodeNavServiceSCIPDocumentFunc describes the behavior when the
|
||||
// SCIPDocument method of the parent MockCodeNavService instance is invoked.
|
||||
type CodeNavServiceSCIPDocumentFunc struct {
|
||||
defaultHook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error)
|
||||
hooks []func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error)
|
||||
defaultHook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error)
|
||||
hooks []func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error)
|
||||
history []CodeNavServiceSCIPDocumentFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// SCIPDocument delegates to the next hook function in the queue and stores
|
||||
// the parameter and result values of this invocation.
|
||||
func (m *MockCodeNavService) SCIPDocument(v0 context.Context, v1 codenav.GitTreeTranslator, v2 core.UploadLike, v3 core.RepoRelPath) (*scip.Document, error) {
|
||||
r0, r1 := m.SCIPDocumentFunc.nextHook()(v0, v1, v2, v3)
|
||||
m.SCIPDocumentFunc.appendCall(CodeNavServiceSCIPDocumentFuncCall{v0, v1, v2, v3, r0, r1})
|
||||
func (m *MockCodeNavService) SCIPDocument(v0 context.Context, v1 codenav.GitTreeTranslator, v2 core.UploadLike, v3 api.CommitID, v4 core.RepoRelPath) (*scip.Document, error) {
|
||||
r0, r1 := m.SCIPDocumentFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.SCIPDocumentFunc.appendCall(CodeNavServiceSCIPDocumentFuncCall{v0, v1, v2, v3, v4, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the SCIPDocument method
|
||||
// of the parent MockCodeNavService instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) SetDefaultHook(hook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error)) {
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) SetDefaultHook(hook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -1504,7 +1504,7 @@ func (f *CodeNavServiceSCIPDocumentFunc) SetDefaultHook(hook func(context.Contex
|
||||
// SCIPDocument method of the parent MockCodeNavService instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) PushHook(hook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error)) {
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) PushHook(hook func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -1513,19 +1513,19 @@ func (f *CodeNavServiceSCIPDocumentFunc) PushHook(hook func(context.Context, cod
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) SetDefaultReturn(r0 *scip.Document, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error) {
|
||||
f.SetDefaultHook(func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) PushReturn(r0 *scip.Document, r1 error) {
|
||||
f.PushHook(func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error) {
|
||||
f.PushHook(func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) nextHook() func(context.Context, codenav.GitTreeTranslator, core.UploadLike, core.RepoRelPath) (*scip.Document, error) {
|
||||
func (f *CodeNavServiceSCIPDocumentFunc) nextHook() func(context.Context, codenav.GitTreeTranslator, core.UploadLike, api.CommitID, core.RepoRelPath) (*scip.Document, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -1569,7 +1569,10 @@ type CodeNavServiceSCIPDocumentFuncCall struct {
|
||||
Arg2 core.UploadLike
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 core.RepoRelPath
|
||||
Arg3 api.CommitID
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 core.RepoRelPath
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 *scip.Document
|
||||
@ -1581,7 +1584,7 @@ type CodeNavServiceSCIPDocumentFuncCall struct {
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c CodeNavServiceSCIPDocumentFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3}
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
|
||||
@ -41,7 +41,6 @@ type rootResolver struct {
|
||||
uploadLoaderFactory uploadsgraphql.UploadLoaderFactory
|
||||
autoIndexJobLoaderFactory uploadsgraphql.AutoIndexJobLoaderFactory
|
||||
locationResolverFactory *gitresolvers.CachedLocationResolverFactory
|
||||
hunkCache codenav.HunkCache
|
||||
indexResolverFactory *uploadsgraphql.PreciseIndexResolverFactory
|
||||
maximumIndexesPerMonikerSearch int
|
||||
operations *operations
|
||||
@ -59,13 +58,7 @@ func NewRootResolver(
|
||||
indexResolverFactory *uploadsgraphql.PreciseIndexResolverFactory,
|
||||
locationResolverFactory *gitresolvers.CachedLocationResolverFactory,
|
||||
maxIndexSearch int,
|
||||
hunkCacheSize int,
|
||||
) (resolverstubs.CodeNavServiceResolver, error) {
|
||||
hunkCache, err := codenav.NewHunkCache(hunkCacheSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
) resolverstubs.CodeNavServiceResolver {
|
||||
return &rootResolver{
|
||||
svc: svc,
|
||||
autoindexingSvc: autoindexingSvc,
|
||||
@ -76,10 +69,9 @@ func NewRootResolver(
|
||||
autoIndexJobLoaderFactory: autoIndexJobLoaderFactory,
|
||||
indexResolverFactory: indexResolverFactory,
|
||||
locationResolverFactory: locationResolverFactory,
|
||||
hunkCache: hunkCache,
|
||||
maximumIndexesPerMonikerSearch: maxIndexSearch,
|
||||
operations: newOperations(observationCtx),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for query resolution
|
||||
@ -119,7 +111,6 @@ func (r *rootResolver) makeRequestState(ctx context.Context, repo *types.Repo, o
|
||||
opts.Commit,
|
||||
opts.Path,
|
||||
r.maximumIndexesPerMonikerSearch,
|
||||
r.hunkCache,
|
||||
)
|
||||
return &reqState, nil
|
||||
}
|
||||
@ -132,9 +123,7 @@ func (r *rootResolver) CodeGraphData(ctx context.Context, opts *resolverstubs.Co
|
||||
return nil, ErrNotEnabled
|
||||
}
|
||||
|
||||
// TODO: The resolvers may be invoked in parallel. Is GitTreeTranslator
|
||||
// concurrency-safe? It looks like
|
||||
gitTreeTranslator := r.MakeGitTreeTranslator(opts.Repo, opts.Commit)
|
||||
gitTreeTranslator := r.MakeGitTreeTranslator(opts.Repo)
|
||||
makeResolvers := func(prov resolverstubs.CodeGraphDataProvenance) ([]resolverstubs.CodeGraphDataResolver, error) {
|
||||
indexer := ""
|
||||
if prov == resolverstubs.ProvenanceSyntactic {
|
||||
@ -205,7 +194,7 @@ func (r *rootResolver) CodeGraphDataByID(ctx context.Context, rawID graphql.ID)
|
||||
/*document*/ nil,
|
||||
/*documentRetrievalError*/ nil,
|
||||
r.svc,
|
||||
r.MakeGitTreeTranslator(repo, id.Commit),
|
||||
r.MakeGitTreeTranslator(repo),
|
||||
id.UploadData,
|
||||
&opts,
|
||||
id.CodeGraphDataProvenance,
|
||||
@ -274,7 +263,7 @@ func (r *rootResolver) UsagesForSymbol(ctx context.Context, unresolvedArgs *reso
|
||||
SymbolRange: args.Range,
|
||||
}
|
||||
|
||||
gitTreeTranslator := r.MakeGitTreeTranslator(&args.Repo, args.CommitID)
|
||||
gitTreeTranslator := r.MakeGitTreeTranslator(&args.Repo)
|
||||
|
||||
var previousSyntacticSearch core.Option[codenav.PreviousSyntacticSearch]
|
||||
if remainingCount > 0 && provsForSCIPData.Syntactic {
|
||||
@ -327,8 +316,8 @@ func (r *rootResolver) UsagesForSymbol(ctx context.Context, unresolvedArgs *reso
|
||||
return nil, errors.New("Not implemented yet")
|
||||
}
|
||||
|
||||
func (r *rootResolver) MakeGitTreeTranslator(repo *sgtypes.Repo, baseCommit api.CommitID) codenav.GitTreeTranslator {
|
||||
return codenav.NewGitTreeTranslator(r.gitserverClient, &codenav.TranslationBase{repo, baseCommit}, r.hunkCache)
|
||||
func (r *rootResolver) MakeGitTreeTranslator(repo *sgtypes.Repo) codenav.GitTreeTranslator {
|
||||
return codenav.NewGitTreeTranslator(r.gitserverClient, *repo)
|
||||
}
|
||||
|
||||
// gitBlobLSIFDataResolver is the main interface to bundle-related operations exposed to the GraphQL API. This
|
||||
@ -498,7 +487,7 @@ func (c *codeGraphDataResolver) tryRetrieveDocument(ctx context.Context) (*scip.
|
||||
// from the database, we can avoid performing a JOIN between codeintel_scip_document_lookup
|
||||
// and codeintel_scip_documents
|
||||
c.retrievedDocument.Do(func() {
|
||||
c.document, c.documentRetrievalError = c.svc.SCIPDocument(ctx, c.gitTreeTranslator, c.upload, c.opts.Path)
|
||||
c.document, c.documentRetrievalError = c.svc.SCIPDocument(ctx, c.gitTreeTranslator, c.upload, c.opts.Commit, c.opts.Path)
|
||||
})
|
||||
return c.document, c.documentRetrievalError
|
||||
}
|
||||
|
||||
@ -450,7 +450,7 @@ func makeTestResolver(t *testing.T) resolverstubs.CodeGraphDataResolver {
|
||||
errUploadNotFound := errors.New("upload not found")
|
||||
errDocumentNotFound := errors.New("document not found")
|
||||
testUpload := uploadsshared.CompletedUpload{ID: 82}
|
||||
codeNavSvc.SCIPDocumentFunc.SetDefaultHook(func(_ context.Context, _ codenav.GitTreeTranslator, upload core.UploadLike, path core.RepoRelPath) (*scip.Document, error) {
|
||||
codeNavSvc.SCIPDocumentFunc.SetDefaultHook(func(_ context.Context, _ codenav.GitTreeTranslator, upload core.UploadLike, _ api.CommitID, path core.RepoRelPath) (*scip.Document, error) {
|
||||
if upload.GetID() != testUpload.ID {
|
||||
return nil, errUploadNotFound
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user