Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/index/scip.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func Index(writer func(proto.Message), opts config.IndexOpts) error {
continue
}

enclosingNodeMap := map[*ast.Ident]ast.Node{}
visitors.EnclosingNodeMap(f, enclosingNodeMap)

// If possible, any state required for created a scip document
// should be contained in the visitor. This makes sure that we can
// garbage collect everything that's there after each loop,
Expand All @@ -142,6 +145,7 @@ func Index(writer func(proto.Message), opts config.IndexOpts) error {
allPackages,
pkgSymbols,
globalSymbols,
enclosingNodeMap,
)

// Traverse the file
Expand Down
2 changes: 2 additions & 0 deletions internal/testdata/snapshots/output/alias/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
// > ```
)

//⌄ enclosing_range_start github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().
func f(u U) {}
// ^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().
// documentation
Expand All @@ -80,4 +81,5 @@
// > ```
// ^ definition local 0
// ^ reference github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/U#
// ⌃ enclosing_range_end github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().

4 changes: 4 additions & 0 deletions internal/testdata/snapshots/output/embedded/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// ^^^ reference github.com/golang/go/src go1.22 `os/exec`/Cmd#
}

//⌄ enclosing_range_start 0.1.test `sg/embedded`/wrapExecCommand().
func wrapExecCommand(c *exec.Cmd) {
// ^^^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/wrapExecCommand().
// documentation
Expand All @@ -47,6 +48,7 @@
// ^^^ reference 0.1.test `sg/embedded`/osExecCommand#Cmd.
// ^ reference local 0
}
//⌃ enclosing_range_end 0.1.test `sg/embedded`/wrapExecCommand().

type Inner struct {
// ^^^^^ definition 0.1.test `sg/embedded`/Inner#
Expand Down Expand Up @@ -110,6 +112,7 @@
// > ```
}

//⌄ enclosing_range_start 0.1.test `sg/embedded`/useOfCompositeStructs().
func useOfCompositeStructs() {
// ^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/useOfCompositeStructs().
// documentation
Expand Down Expand Up @@ -145,4 +148,5 @@
// ^^^^^ reference 0.1.test `sg/embedded`/Outer#Inner.
// ^ reference 0.1.test `sg/embedded`/Inner#Y.
}
//⌃ enclosing_range_end 0.1.test `sg/embedded`/useOfCompositeStructs().

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ^^^^^^^^^^^ reference 0.1.test `sg/embedded`/
)

//⌄ enclosing_range_start 0.1.test `sg/embedded/internal`/Something().
func Something(recent embedded.RecentCommittersResults) {
// ^^^^^^^^^ definition 0.1.test `sg/embedded/internal`/Something().
// documentation
Expand All @@ -36,4 +37,5 @@
}
}
}
//⌃ enclosing_range_end 0.1.test `sg/embedded/internal`/Something().

2 changes: 2 additions & 0 deletions internal/testdata/snapshots/output/embedded/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// > ```
}

//⌄ enclosing_range_start 0.1.test `sg/embedded`/NestedExample().
func NestedExample(n NestedHandler) {
// ^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/NestedExample().
// documentation
Expand All @@ -57,4 +58,5 @@
// ^ reference local 0
// ^^^^^ reference 0.1.test `sg/embedded`/NestedHandler#Other.
}
//⌃ enclosing_range_end 0.1.test `sg/embedded`/NestedExample().

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import "fmt"
// ^^^ reference github.com/golang/go/src go1.22 fmt/

//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/Print().
func Print[T any](s []T) {
// ^^^^^ definition 0.1.test `sg/generallyeric`/Print().
// documentation
Expand All @@ -25,4 +26,5 @@
// ^ reference local 2
}
}
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/Print().

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// ^^^^^^^ reference golang.org/x/exp 47842c84f3db `golang.org/x/exp/constraints`/Complex#
}

//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/Double().
func Double[T Number](value T) T {
// ^^^^^^ definition 0.1.test `sg/generallyeric`/Double().
// documentation
Expand All @@ -39,6 +40,7 @@
return value * 2
// ^^^^^ reference local 1
}
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/Double().

type Box[T any] struct {
// ^^^ definition 0.1.test `sg/generallyeric`/Box#
Expand Down
6 changes: 6 additions & 0 deletions internal/testdata/snapshots/output/generallyeric/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// > ```
// relationship 0.1.test `sg/generallyeric`/Person# implementation

//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/worker#Work().
func (w worker) Work() {
// ^ definition local 0
// ^^^^^^ reference 0.1.test `sg/generallyeric`/worker#
Expand All @@ -46,7 +47,9 @@
// ^^^^^^ reference github.com/golang/go/src go1.22 fmt/Printf().
// ^ reference local 0
}
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/worker#Work().

//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/DoWork().
func DoWork[T Person](things []T) {
// ^^^^^^ definition 0.1.test `sg/generallyeric`/DoWork().
// documentation
Expand All @@ -65,7 +68,9 @@
// ^^^^ reference 0.1.test `sg/generallyeric`/Person#Work.
}
}
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/DoWork().

//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/main().
func main() {
// ^^^^ definition 0.1.test `sg/generallyeric`/main().
// documentation
Expand All @@ -90,4 +95,5 @@
// ^ reference local 5
// ^ reference local 6
}
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/main().

6 changes: 6 additions & 0 deletions internal/testdata/snapshots/output/impls/impls.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
// relationship 0.1.test `sg/impls`/I1# implementation
// relationship 0.1.test `sg/impls`/I1Clone# implementation

//⌄ enclosing_range_start 0.1.test `sg/impls`/T1#F1().
func (r T1) F1() {}
// ^ definition local 0
// ^^ reference 0.1.test `sg/impls`/T1#
Expand All @@ -89,6 +90,7 @@
// > ```
// relationship 0.1.test `sg/impls`/I1#F1. implementation
// relationship 0.1.test `sg/impls`/I1Clone#F1. implementation
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T1#F1().

type T2 int
// ^^ definition 0.1.test `sg/impls`/T2#
Expand All @@ -99,6 +101,7 @@
// relationship 0.1.test `sg/impls`/I1# implementation
// relationship 0.1.test `sg/impls`/I1Clone# implementation

//⌄ enclosing_range_start 0.1.test `sg/impls`/T2#F1().
func (r T2) F1() {}
// ^ definition local 1
// ^^ reference 0.1.test `sg/impls`/T2#
Expand All @@ -109,6 +112,8 @@
// > ```
// relationship 0.1.test `sg/impls`/I1#F1. implementation
// relationship 0.1.test `sg/impls`/I1Clone#F1. implementation
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T2#F1().
//⌄ enclosing_range_start 0.1.test `sg/impls`/T2#F2().
func (r T2) F2() {}
// ^ definition local 2
// ^^ reference 0.1.test `sg/impls`/T2#
Expand All @@ -117,4 +122,5 @@
// > ```go
// > func (T2).F2()
// > ```
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T2#F2().

10 changes: 10 additions & 0 deletions internal/testdata/snapshots/output/impls/remote_impls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import "net/http"
// ^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/

//⌄ enclosing_range_start 0.1.test `sg/impls`/Something().
func Something(r http.ResponseWriter) {}
// ^^^^^^^^^ definition 0.1.test `sg/impls`/Something().
// documentation
Expand All @@ -13,6 +14,7 @@
// ^ definition local 0
// ^^^^ reference github.com/golang/go/src go1.22 `net/http`/
// ^^^^^^^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/ResponseWriter#
// ⌃ enclosing_range_end 0.1.test `sg/impls`/Something().

type MyWriter struct{}
// ^^^^^^^^ definition 0.1.test `sg/impls`/MyWriter#
Expand All @@ -29,6 +31,7 @@
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter# implementation
// relationship github.com/golang/go/src go1.22 io/Writer# implementation

//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#Header().
func (w MyWriter) Header() http.Header { panic("") }
// ^ definition local 1
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
Expand All @@ -40,6 +43,8 @@
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#Header. implementation
// ^^^^ reference github.com/golang/go/src go1.22 `net/http`/
// ^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/Header#
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#Header().
//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#Write().
func (w MyWriter) Write([]byte) (int, error) { panic("") }
// ^ definition local 2
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
Expand All @@ -52,6 +57,8 @@
// relationship github.com/golang/go/src go1.22 `internal/bisect`/Writer#Write. implementation
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#Write. implementation
// relationship github.com/golang/go/src go1.22 io/Writer#Write. implementation
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#Write().
//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#WriteHeader().
func (w MyWriter) WriteHeader(statusCode int) { panic("") }
// ^ definition local 3
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
Expand All @@ -62,7 +69,9 @@
// > ```
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#WriteHeader. implementation
// ^^^^^^^^^^ definition local 4
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#WriteHeader().

//⌄ enclosing_range_start 0.1.test `sg/impls`/Another().
func Another() {
// ^^^^^^^ definition 0.1.test `sg/impls`/Another().
// documentation
Expand All @@ -73,4 +82,5 @@
// ^^^^^^^^^ reference 0.1.test `sg/impls`/Something().
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
}
//⌃ enclosing_range_end 0.1.test `sg/impls`/Another().

2 changes: 2 additions & 0 deletions internal/testdata/snapshots/output/initial/builtin_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package initial
// ^^^^^^^ reference 0.1.test `sg/initial`/

//⌄ enclosing_range_start 0.1.test `sg/initial`/UsesBuiltin().
func UsesBuiltin() int {
// ^^^^^^^^^^^ definition 0.1.test `sg/initial`/UsesBuiltin().
// documentation
Expand All @@ -12,4 +13,5 @@
return x
// ^ reference local 0
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/UsesBuiltin().

8 changes: 8 additions & 0 deletions internal/testdata/snapshots/output/initial/child_symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
}

// StructMethod has some docs!
//⌄ enclosing_range_start 0.1.test `sg/initial`/Struct#StructMethod().
func (s *Struct) StructMethod() {}
// ^ definition local 0
// ^^^^^^ reference 0.1.test `sg/initial`/Struct#
Expand All @@ -257,7 +258,9 @@
// > ```
// documentation
// > StructMethod has some docs!
// ⌃ enclosing_range_end 0.1.test `sg/initial`/Struct#StructMethod().

//⌄ enclosing_range_start 0.1.test `sg/initial`/Struct#ImplementsInterface().
func (s *Struct) ImplementsInterface() string { return "hi!" }
// ^ definition local 1
// ^^^^^^ reference 0.1.test `sg/initial`/Struct#
Expand All @@ -267,7 +270,9 @@
// > func (*Struct).ImplementsInterface() string
// > ```
// relationship 0.1.test `sg/initial`/Interface#ImplementsInterface. implementation
// ⌃ enclosing_range_end 0.1.test `sg/initial`/Struct#ImplementsInterface().

//⌄ enclosing_range_start 0.1.test `sg/initial`/Struct#MachineLearning().
func (s *Struct) MachineLearning(
// ^ definition local 2
// ^^^^^^ reference 0.1.test `sg/initial`/Struct#
Expand Down Expand Up @@ -321,6 +326,7 @@
// ^^^^^^^^^^^ reference local 4
// ^^^^^^^^^^^ reference local 5
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/Struct#MachineLearning().

// Interface has docs too
type Interface interface {
Expand All @@ -345,13 +351,15 @@
// > ```
}

//⌄ enclosing_range_start 0.1.test `sg/initial`/NewInterface().
func NewInterface() Interface { return nil }
// ^^^^^^^^^^^^ definition 0.1.test `sg/initial`/NewInterface().
// documentation
// > ```go
// > func NewInterface() Interface
// > ```
// ^^^^^^^^^ reference 0.1.test `sg/initial`/Interface#
// ⌃ enclosing_range_end 0.1.test `sg/initial`/NewInterface().

var SortExportedFirst = 1
// ^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/initial`/SortExportedFirst.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package initial
// ^^^^^^^ reference 0.1.test `sg/initial`/

//⌄ enclosing_range_start 0.1.test `sg/initial`/UsesLater().
func UsesLater() {
// ^^^^^^^^^ definition 0.1.test `sg/initial`/UsesLater().
// documentation
Expand All @@ -10,11 +11,14 @@
DefinedLater()
// ^^^^^^^^^^^^ reference 0.1.test `sg/initial`/DefinedLater().
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/UsesLater().

//⌄ enclosing_range_start 0.1.test `sg/initial`/DefinedLater().
func DefinedLater() {}
// ^^^^^^^^^^^^ definition 0.1.test `sg/initial`/DefinedLater().
// documentation
// > ```go
// > func DefinedLater()
// > ```
// ⌃ enclosing_range_end 0.1.test `sg/initial`/DefinedLater().

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// > struct field y int
// > ```

//⌄ enclosing_range_start 0.1.test `sg/initial`/MyStruct#RecvFunction().
func (m MyStruct) RecvFunction(b int) int { return m.f + b }
// ^ definition local 0
// ^^^^^^^^ reference 0.1.test `sg/initial`/MyStruct#
Expand All @@ -40,7 +41,9 @@
// ^ reference local 0
// ^ reference 0.1.test `sg/initial`/MyStruct#f.
// ^ reference local 1
// ⌃ enclosing_range_end 0.1.test `sg/initial`/MyStruct#RecvFunction().

//⌄ enclosing_range_start 0.1.test `sg/initial`/SomethingElse().
func SomethingElse() {
// ^^^^^^^^^^^^^ definition 0.1.test `sg/initial`/SomethingElse().
// documentation
Expand All @@ -56,4 +59,5 @@
// ^^^^^^^ reference github.com/golang/go/src go1.22 fmt/Println().
// ^ reference local 2
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/SomethingElse().

2 changes: 2 additions & 0 deletions internal/testdata/snapshots/output/initial/rangefunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ^^^^^^ reference github.com/golang/go/src go1.22 slices/
)

//⌄ enclosing_range_start 0.1.test `sg/initial`/f().
func f(xs []int) int {
// ^ definition 0.1.test `sg/initial`/f().
// documentation
Expand All @@ -23,4 +24,5 @@
}
return -1
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/f().

2 changes: 2 additions & 0 deletions internal/testdata/snapshots/output/initial/toplevel_decls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// > ```
// ^^^^^^^^ reference 0.1.test `sg/initial`/MY_THING.

//⌄ enclosing_range_start 0.1.test `sg/initial`/usesMyThing().
func usesMyThing() {
// ^^^^^^^^^^^ definition 0.1.test `sg/initial`/usesMyThing().
// documentation
Expand All @@ -24,6 +25,7 @@
_ = MY_THING
// ^^^^^^^^ reference 0.1.test `sg/initial`/MY_THING.
}
//⌃ enclosing_range_end 0.1.test `sg/initial`/usesMyThing().

var initFunctions = map[string]int{}
// ^^^^^^^^^^^^^ definition 0.1.test `sg/initial`/initFunctions.
Expand Down
Loading