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

Resolve syntactic symbol at request range #63189

Merged
merged 11 commits into from
Jun 12, 2024
Merged
8 changes: 4 additions & 4 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4486,8 +4486,8 @@ def go_dependencies():
name = "com_github_montanaflynn_stats",
build_file_proto_mode = "disable_global",
importpath = "github.com/montanaflynn/stats",
sum = "h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU=",
version = "v0.7.0",
sum = "h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=",
version = "v0.7.1",
)
go_repository(
name = "com_github_morikuni_aec",
Expand Down Expand Up @@ -5724,8 +5724,8 @@ def go_dependencies():
patches = [
"//third_party/com_github_sourcegraph_scip:add_parser_h_to_srcs.patch",
],
sum = "h1:3EOkChYOntwHl0pPSAju7rj0oRuujh8owC4vjGDEr0s=",
version = "v0.3.3",
sum = "h1:Tqf5ThVlPu8fV+WeTkJEbW34fPOfDUpbxQWU4iLvaQI=",
version = "v0.4.0",
)
go_repository(
name = "com_github_sourcegraph_sourcegraph_accounts_sdk_go",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ require (
github.com/sourcegraph/managed-services-platform-cdktf/gen/slack v0.0.0-20240513203650-e2b1273f1c1a
github.com/sourcegraph/managed-services-platform-cdktf/gen/tfe v0.0.0-20240513203650-e2b1273f1c1a
github.com/sourcegraph/notionreposync v0.0.0-20240517090426-98b2d4b017d7
github.com/sourcegraph/scip v0.3.3
github.com/sourcegraph/scip v0.4.0
github.com/sourcegraph/sourcegraph-accounts-sdk-go v0.0.0-20240531163352-fe74c17cf0d1
github.com/sourcegraph/sourcegraph/lib v0.0.0-20240524140455-2589fef13ea8
github.com/sourcegraph/sourcegraph/lib/managedservicesplatform v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1757,8 +1757,8 @@ github.com/sourcegraph/notionreposync v0.0.0-20240517090426-98b2d4b017d7 h1:1uwY
github.com/sourcegraph/notionreposync v0.0.0-20240517090426-98b2d4b017d7/go.mod h1:p8BpoweXljSzz6OAlra0Q+CuzoFfCsm+/J1ZiNmQxrE=
github.com/sourcegraph/run v0.12.0 h1:3A8w5e8HIYPfafHekvmdmmh42RHKGVhmiTZAPJclg7I=
github.com/sourcegraph/run v0.12.0/go.mod h1:PwaP936BTnAJC1cqR5rSbG5kOs/EWStTK3lqvMX5GUA=
github.com/sourcegraph/scip v0.3.3 h1:3EOkChYOntwHl0pPSAju7rj0oRuujh8owC4vjGDEr0s=
github.com/sourcegraph/scip v0.3.3/go.mod h1:Q67VaoTpftINIy/CLrkYQOMwlsx67h8ys+ligmdUcqM=
github.com/sourcegraph/scip v0.4.0 h1:Tqf5ThVlPu8fV+WeTkJEbW34fPOfDUpbxQWU4iLvaQI=
github.com/sourcegraph/scip v0.4.0/go.mod h1:bmBqGJCl3nJw55jt8WXXqx4+TXR5WPO80qw7KoCvXZU=
github.com/sourcegraph/sourcegraph-accounts-sdk-go v0.0.0-20240531163352-fe74c17cf0d1 h1:+7J5NMA9FJDaf0IhNpIcTEg+Gzu/GN5dRT40wdFU10I=
github.com/sourcegraph/sourcegraph-accounts-sdk-go v0.0.0-20240531163352-fe74c17cf0d1/go.mod h1:/MWl0sFvn6w26Y067CkEJgklfxx8gCzbEJ3q6cBzDro=
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
Expand Down
2 changes: 2 additions & 0 deletions internal/codeintel/codenav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"init.go",
"observability.go",
"request_state.go",
"scip_utils.go",
"service.go",
"service_new.go",
"types.go",
Expand Down Expand Up @@ -51,6 +52,7 @@ go_test(
srcs = [
"gittree_translator_test.go",
"mocks_test.go",
"scip_utils_test.go",
"service_closest_uploads_test.go",
"service_definitions_test.go",
"service_diagnostics_test.go",
Expand Down
1 change: 0 additions & 1 deletion internal/codeintel/codenav/internal/lsifstore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
"scan.go",
"store.go",
"symbols_by_position.go",
"util.go",
],
importpath = "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/lsifstore",
tags = [TAG_PLATFORM_GRAPH],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *store) GetStencil(ctx context.Context, bundleID int, path string) (_ []

ranges := make([]shared.Range, 0, len(documentData.SCIPData.Occurrences))
for _, occurrence := range documentData.SCIPData.Occurrences {
ranges = append(ranges, translateRange(scip.NewRange(occurrence.Range)))
ranges = append(ranges, shared.TranslateRange(scip.NewRangeUnchecked(occurrence.Range)))
}

return ranges, nil
Expand Down Expand Up @@ -100,7 +100,8 @@ func (s *store) GetRanges(ctx context.Context, bundleID int, path string, startL

var ranges []shared.CodeIntelligenceRange
for _, occurrence := range documentData.SCIPData.Occurrences {
r := translateRange(scip.NewRange(occurrence.Range))

r := shared.TranslateRange(scip.NewRangeUnchecked(occurrence.Range))

if (startLine <= r.Start.Line && r.Start.Line < endLine) || (startLine <= r.End.Line && r.End.Line < endLine) {
data := extractOccurrenceData(documentData.SCIPData, occurrence)
Expand Down Expand Up @@ -131,13 +132,13 @@ WHERE
LIMIT 1
`

func convertSCIPRangesToLocations(ranges []*scip.Range, uploadID int, path string) []shared.Location {
func convertSCIPRangesToLocations(ranges []scip.Range, uploadID int, path string) []shared.Location {
locations := make([]shared.Location, 0, len(ranges))
for _, r := range ranges {
locations = append(locations, shared.Location{
UploadID: uploadID,
Path: path,
Range: translateRange(r),
Range: shared.TranslateRange(r),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@ func TestGetRanges(t *testing.T) {
)

var (
nonEmptyDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 16, 15, 24)}}
tDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 25, 15, 26)}}
valueDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 28, 15, 33)}}
nonEmptyDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 16, 15, 24)}}
tDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 25, 15, 26)}}
valueDefinitionLocations = []shared.Location{{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 28, 15, 33)}}

nonEmptyReferenceLocations = []shared.Location{}
tReferenceLocations = []shared.Location{
{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 35, 15, 36)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 39, 15, 40)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 73, 15, 74)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 77, 15, 78)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 35, 15, 36)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 39, 15, 40)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 73, 15, 74)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 77, 15, 78)},
}
valueReferenceLocations = []shared.Location{
{UploadID: testSCIPUploadID, Path: path, Range: newRange(15, 64, 15, 69)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(16, 13, 16, 18)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(16, 38, 16, 43)},
{UploadID: testSCIPUploadID, Path: path, Range: newRange(16, 48, 16, 53)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(15, 64, 15, 69)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(16, 13, 16, 18)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(16, 38, 16, 43)},
{UploadID: testSCIPUploadID, Path: path, Range: shared.NewRange(16, 48, 16, 53)},
}

nonEmptyImplementationLocations = []shared.Location(nil)
Expand All @@ -182,63 +182,63 @@ func TestGetRanges(t *testing.T) {
expectedRanges := []shared.CodeIntelligenceRange{
{
// `nonEmpty`
Range: newRange(15, 16, 15, 24),
Range: shared.NewRange(15, 16, 15, 24),
Definitions: nonEmptyDefinitionLocations,
References: nonEmptyReferenceLocations,
Implementations: nonEmptyImplementationLocations,
HoverText: nonEmptyHoverText,
},
{
// `T`
Range: newRange(15, 25, 15, 26),
Range: shared.NewRange(15, 25, 15, 26),
Definitions: tDefinitionLocations,
References: tReferenceLocations,
Implementations: tImplementationLocations,
HoverText: tHoverText,
},
{
// `value`
Range: newRange(15, 28, 15, 33),
Range: shared.NewRange(15, 28, 15, 33),
Definitions: valueDefinitionLocations,
References: valueReferenceLocations,
Implementations: valueImplementationLocations,
HoverText: valueHoverText,
},
{
// `T`
Range: newRange(15, 35, 15, 36),
Range: shared.NewRange(15, 35, 15, 36),
Definitions: tDefinitionLocations,
References: tReferenceLocations,
Implementations: tImplementationLocations,
HoverText: tHoverText,
},
{
// `T`
Range: newRange(15, 39, 15, 40),
Range: shared.NewRange(15, 39, 15, 40),
Definitions: tDefinitionLocations,
References: tReferenceLocations,
Implementations: tImplementationLocations,
HoverText: tHoverText,
},
{
// `value`
Range: newRange(15, 64, 15, 69),
Range: shared.NewRange(15, 64, 15, 69),
Definitions: valueDefinitionLocations,
References: valueReferenceLocations,
Implementations: valueImplementationLocations,
HoverText: valueHoverText,
},
{
// `T`
Range: newRange(15, 73, 15, 74),
Range: shared.NewRange(15, 73, 15, 74),
Definitions: tDefinitionLocations,
References: tReferenceLocations,
Implementations: tImplementationLocations,
HoverText: tHoverText,
},
{
// `T`
Range: newRange(15, 77, 15, 78),
Range: shared.NewRange(15, 77, 15, 78),
Definitions: tDefinitionLocations,
References: tReferenceLocations,
Implementations: tImplementationLocations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ outer:
locations = append(locations, shared.Location{
UploadID: monikerLocations.UploadID,
Path: row.URI,
Range: newRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
Range: shared.NewRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
})

if len(locations) >= limit {
Expand Down Expand Up @@ -128,7 +128,7 @@ ORDER BY ss.upload_id, msn.symbol_name
func (s *store) getLocations(
ctx context.Context,
scipFieldName string,
scipExtractor func(*scip.Document, *scip.Occurrence) []*scip.Range,
scipExtractor func(*scip.Document, *scip.Occurrence) []scip.Range,
operation *observation.Operation,
bundleID int,
path string,
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *store) getLocations(
locations = append(locations, shared.Location{
UploadID: monikerLocation.UploadID,
Path: row.URI,
Range: newRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
Range: shared.NewRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
})
}
}
Expand Down Expand Up @@ -237,26 +237,26 @@ WHERE
`

type extractedOccurrenceData struct {
definitions []*scip.Range
references []*scip.Range
implementations []*scip.Range
prototypes []*scip.Range
definitions []scip.Range
references []scip.Range
implementations []scip.Range
prototypes []scip.Range
hoverText []string
}

func extractDefinitionRanges(document *scip.Document, occurrence *scip.Occurrence) []*scip.Range {
func extractDefinitionRanges(document *scip.Document, occurrence *scip.Occurrence) []scip.Range {
return extractOccurrenceData(document, occurrence).definitions
}

func extractReferenceRanges(document *scip.Document, occurrence *scip.Occurrence) []*scip.Range {
func extractReferenceRanges(document *scip.Document, occurrence *scip.Occurrence) []scip.Range {
return extractOccurrenceData(document, occurrence).references
}

func extractImplementationRanges(document *scip.Document, occurrence *scip.Occurrence) []*scip.Range {
func extractImplementationRanges(document *scip.Document, occurrence *scip.Occurrence) []scip.Range {
return extractOccurrenceData(document, occurrence).implementations
}

func extractPrototypesRanges(document *scip.Document, occurrence *scip.Occurrence) []*scip.Range {
func extractPrototypesRanges(document *scip.Document, occurrence *scip.Occurrence) []scip.Range {
return extractOccurrenceData(document, occurrence).prototypes
}

Expand Down Expand Up @@ -309,10 +309,10 @@ func extractOccurrenceData(document *scip.Document, occurrence *scip.Occurrence)
}
}

definitions := []*scip.Range{}
references := []*scip.Range{}
implementations := []*scip.Range{}
prototypes := []*scip.Range{}
definitions := []scip.Range{}
references := []scip.Range{}
implementations := []scip.Range{}
prototypes := []scip.Range{}

// Include original symbol names for reference search below
referencesBySymbol.Add(occurrence.Symbol)
Expand All @@ -325,22 +325,22 @@ func extractOccurrenceData(document *scip.Document, occurrence *scip.Occurrence)

// This occurrence defines this symbol
if definitionSymbol == occ.Symbol && isDefinition {
definitions = append(definitions, scip.NewRange(occ.Range))
definitions = append(definitions, scip.NewRangeUnchecked(occ.Range))
}

// This occurrence references this symbol (or a sibling of it)
if !isDefinition && referencesBySymbol.Has(occ.Symbol) {
references = append(references, scip.NewRange(occ.Range))
references = append(references, scip.NewRangeUnchecked(occ.Range))
}

// This occurrence is a definition of a symbol with an implementation relationship
if isDefinition && implementationsBySymbol.Has(occ.Symbol) && definitionSymbol != occ.Symbol {
implementations = append(implementations, scip.NewRange(occ.Range))
implementations = append(implementations, scip.NewRangeUnchecked(occ.Range))
}

// This occurrence is a definition of a symbol with a prototype relationship
if isDefinition && prototypeBySymbol.Has(occ.Symbol) {
prototypes = append(prototypes, scip.NewRange(occ.Range))
prototypes = append(prototypes, scip.NewRangeUnchecked(occ.Range))
}
}

Expand Down Expand Up @@ -434,7 +434,7 @@ func symbolExtractPrototype(document *scip.Document, symbolName string) (symbols

func (s *store) extractLocationsFromPosition(
ctx context.Context,
extractRanges func(document *scip.Document, occurrence *scip.Occurrence) []*scip.Range,
extractRanges func(document *scip.Document, occurrence *scip.Occurrence) []scip.Range,
extractSymbolNames func(document *scip.Document, symbolName string) []string,
operation *observation.Operation,
locationKey LocationKey,
Expand Down Expand Up @@ -578,7 +578,7 @@ outer:
locations = append(locations, shared.Location{
UploadID: monikerLocations.UploadID,
Path: row.URI,
Range: newRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
Range: shared.NewRange(row.StartLine, row.StartCharacter, row.EndLine, row.EndCharacter),
})

if len(locations) >= limit {
Expand Down
Loading
Loading