From 94e8caa43f3447665c64ecba543e133484f69487 Mon Sep 17 00:00:00 2001 From: Michael Podtserkovskii Date: Tue, 7 Oct 2025 22:21:46 +0100 Subject: [PATCH] Support enclosing ranges for function definitions --- internal/index/scip.go | 4 ++ .../testdata/snapshots/output/alias/main.go | 2 + .../snapshots/output/embedded/embedded.go | 4 ++ .../output/embedded/internal/nested.go | 2 + .../snapshots/output/embedded/nested.go | 2 + .../output/generallyeric/generallyeric.go | 2 + .../output/generallyeric/new_operators.go | 2 + .../snapshots/output/generallyeric/person.go | 6 ++ .../testdata/snapshots/output/impls/impls.go | 6 ++ .../snapshots/output/impls/remote_impls.go | 10 +++ .../snapshots/output/initial/builtin_types.go | 2 + .../snapshots/output/initial/child_symbols.go | 8 +++ .../output/initial/func_declarations.go | 4 ++ .../output/initial/methods_and_receivers.go | 4 ++ .../snapshots/output/initial/rangefunc.go | 2 + .../output/initial/toplevel_decls.go | 2 + .../output/inlinestruct/inlinestruct.go | 2 + .../inlinestruct/inlinestruct_genericindex.go | 4 ++ .../inlinestruct/inlinestruct_interface.go | 4 ++ .../output/package-documentation/primary.go | 2 + .../output/package-documentation/secondary.go | 2 + .../replace-directives/replace_directives.go | 2 + .../cmd/gitserver/server/cleanup.go | 2 + .../cmd/gitserver/server/cleanup_test.go | 2 + .../cmd/gitserver/server/server.go | 2 + .../cmd/gitserver/server/server_test.go | 4 ++ .../snapshots/output/switches/switches.go | 4 ++ .../output/testdata/anonymous_structs.go | 2 + .../testdata/cmd/minimal_main/minimal_main.go | 2 + .../sandbox_unsupported_test.go | 4 ++ .../snapshots/output/testdata/data.go | 2 + .../output/testdata/duplicate_path_id/main.go | 8 +++ .../output/testdata/duplicate_path_id/two.go | 2 + .../output/testdata/implementations.go | 20 ++++++ .../testdata/implementations_methods.go | 8 +++ .../output/testdata/implementations_remote.go | 8 +++ .../snapshots/output/testdata/named_import.go | 2 + .../snapshots/output/testdata/parallel.go | 2 + .../snapshots/output/testdata/typeswitch.go | 2 + .../snapshots/output/testspecial/foo.go | 2 + .../output/testspecial/foo_other_test.go | 2 + .../snapshots/output/testspecial/foo_test.go | 2 + internal/visitors/visitor_file.go | 63 ++++++++++++++----- internal/visitors/visitors.go | 15 +++-- 44 files changed, 218 insertions(+), 20 deletions(-) diff --git a/internal/index/scip.go b/internal/index/scip.go index 856e257..0677566 100644 --- a/internal/index/scip.go +++ b/internal/index/scip.go @@ -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, @@ -142,6 +145,7 @@ func Index(writer func(proto.Message), opts config.IndexOpts) error { allPackages, pkgSymbols, globalSymbols, + enclosingNodeMap, ) // Traverse the file diff --git a/internal/testdata/snapshots/output/alias/main.go b/internal/testdata/snapshots/output/alias/main.go index dbf2548..7f3971d 100755 --- a/internal/testdata/snapshots/output/alias/main.go +++ b/internal/testdata/snapshots/output/alias/main.go @@ -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 @@ -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(). diff --git a/internal/testdata/snapshots/output/embedded/embedded.go b/internal/testdata/snapshots/output/embedded/embedded.go index a549184..b8a9766 100755 --- a/internal/testdata/snapshots/output/embedded/embedded.go +++ b/internal/testdata/snapshots/output/embedded/embedded.go @@ -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 @@ -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# @@ -110,6 +112,7 @@ // > ``` } +//⌄ enclosing_range_start 0.1.test `sg/embedded`/useOfCompositeStructs(). func useOfCompositeStructs() { // ^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/useOfCompositeStructs(). // documentation @@ -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(). diff --git a/internal/testdata/snapshots/output/embedded/internal/nested.go b/internal/testdata/snapshots/output/embedded/internal/nested.go index dc150eb..db50f6d 100755 --- a/internal/testdata/snapshots/output/embedded/internal/nested.go +++ b/internal/testdata/snapshots/output/embedded/internal/nested.go @@ -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 @@ -36,4 +37,5 @@ } } } +//⌃ enclosing_range_end 0.1.test `sg/embedded/internal`/Something(). diff --git a/internal/testdata/snapshots/output/embedded/nested.go b/internal/testdata/snapshots/output/embedded/nested.go index e61cdbe..00e809f 100755 --- a/internal/testdata/snapshots/output/embedded/nested.go +++ b/internal/testdata/snapshots/output/embedded/nested.go @@ -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 @@ -57,4 +58,5 @@ // ^ reference local 0 // ^^^^^ reference 0.1.test `sg/embedded`/NestedHandler#Other. } +//⌃ enclosing_range_end 0.1.test `sg/embedded`/NestedExample(). diff --git a/internal/testdata/snapshots/output/generallyeric/generallyeric.go b/internal/testdata/snapshots/output/generallyeric/generallyeric.go index edc76f2..9e402b4 100755 --- a/internal/testdata/snapshots/output/generallyeric/generallyeric.go +++ b/internal/testdata/snapshots/output/generallyeric/generallyeric.go @@ -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 @@ -25,4 +26,5 @@ // ^ reference local 2 } } +//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/Print(). diff --git a/internal/testdata/snapshots/output/generallyeric/new_operators.go b/internal/testdata/snapshots/output/generallyeric/new_operators.go index 29b70ca..0263860 100755 --- a/internal/testdata/snapshots/output/generallyeric/new_operators.go +++ b/internal/testdata/snapshots/output/generallyeric/new_operators.go @@ -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 @@ -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# diff --git a/internal/testdata/snapshots/output/generallyeric/person.go b/internal/testdata/snapshots/output/generallyeric/person.go index 0e0f156..9330b9e 100755 --- a/internal/testdata/snapshots/output/generallyeric/person.go +++ b/internal/testdata/snapshots/output/generallyeric/person.go @@ -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# @@ -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 @@ -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 @@ -90,4 +95,5 @@ // ^ reference local 5 // ^ reference local 6 } +//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/main(). diff --git a/internal/testdata/snapshots/output/impls/impls.go b/internal/testdata/snapshots/output/impls/impls.go index 144c2ce..01532d5 100755 --- a/internal/testdata/snapshots/output/impls/impls.go +++ b/internal/testdata/snapshots/output/impls/impls.go @@ -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# @@ -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# @@ -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# @@ -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# @@ -117,4 +122,5 @@ // > ```go // > func (T2).F2() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/impls`/T2#F2(). diff --git a/internal/testdata/snapshots/output/impls/remote_impls.go b/internal/testdata/snapshots/output/impls/remote_impls.go index beb69cb..cd3eebd 100755 --- a/internal/testdata/snapshots/output/impls/remote_impls.go +++ b/internal/testdata/snapshots/output/impls/remote_impls.go @@ -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 @@ -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# @@ -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# @@ -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# @@ -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# @@ -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 @@ -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(). diff --git a/internal/testdata/snapshots/output/initial/builtin_types.go b/internal/testdata/snapshots/output/initial/builtin_types.go index ee5f42a..7ab7e27 100755 --- a/internal/testdata/snapshots/output/initial/builtin_types.go +++ b/internal/testdata/snapshots/output/initial/builtin_types.go @@ -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 @@ -12,4 +13,5 @@ return x // ^ reference local 0 } +//⌃ enclosing_range_end 0.1.test `sg/initial`/UsesBuiltin(). diff --git a/internal/testdata/snapshots/output/initial/child_symbols.go b/internal/testdata/snapshots/output/initial/child_symbols.go index ebe1df6..77f2ece 100755 --- a/internal/testdata/snapshots/output/initial/child_symbols.go +++ b/internal/testdata/snapshots/output/initial/child_symbols.go @@ -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# @@ -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# @@ -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# @@ -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 { @@ -345,6 +351,7 @@ // > ``` } +//⌄ enclosing_range_start 0.1.test `sg/initial`/NewInterface(). func NewInterface() Interface { return nil } // ^^^^^^^^^^^^ definition 0.1.test `sg/initial`/NewInterface(). // documentation @@ -352,6 +359,7 @@ // > 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. diff --git a/internal/testdata/snapshots/output/initial/func_declarations.go b/internal/testdata/snapshots/output/initial/func_declarations.go index ecdfa5e..441f3ad 100755 --- a/internal/testdata/snapshots/output/initial/func_declarations.go +++ b/internal/testdata/snapshots/output/initial/func_declarations.go @@ -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 @@ -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(). diff --git a/internal/testdata/snapshots/output/initial/methods_and_receivers.go b/internal/testdata/snapshots/output/initial/methods_and_receivers.go index d5ae9af..ac8264a 100755 --- a/internal/testdata/snapshots/output/initial/methods_and_receivers.go +++ b/internal/testdata/snapshots/output/initial/methods_and_receivers.go @@ -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# @@ -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 @@ -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(). diff --git a/internal/testdata/snapshots/output/initial/rangefunc.go b/internal/testdata/snapshots/output/initial/rangefunc.go index f2c06ff..6a9836f 100755 --- a/internal/testdata/snapshots/output/initial/rangefunc.go +++ b/internal/testdata/snapshots/output/initial/rangefunc.go @@ -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 @@ -23,4 +24,5 @@ } return -1 } +//⌃ enclosing_range_end 0.1.test `sg/initial`/f(). diff --git a/internal/testdata/snapshots/output/initial/toplevel_decls.go b/internal/testdata/snapshots/output/initial/toplevel_decls.go index 00f1f66..255ca4f 100755 --- a/internal/testdata/snapshots/output/initial/toplevel_decls.go +++ b/internal/testdata/snapshots/output/initial/toplevel_decls.go @@ -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 @@ -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. diff --git a/internal/testdata/snapshots/output/inlinestruct/inlinestruct.go b/internal/testdata/snapshots/output/inlinestruct/inlinestruct.go index 334f2b2..70f5909 100755 --- a/internal/testdata/snapshots/output/inlinestruct/inlinestruct.go +++ b/internal/testdata/snapshots/output/inlinestruct/inlinestruct.go @@ -45,6 +45,7 @@ // ^^^^^^^^^^^^^^ reference 0.1.test `sg/inlinestruct`/FieldInterface# }{} +//⌄ enclosing_range_start 0.1.test `sg/inlinestruct`/MyFunc(). func MyFunc() { // ^^^^^^ definition 0.1.test `sg/inlinestruct`/MyFunc(). // documentation @@ -58,4 +59,5 @@ // ^^^^^^^^ reference 0.1.test `sg/inlinestruct`/MyInline. // ^^^^^^^^^^^ reference 0.1.test `sg/inlinestruct`/MyInline:PublicField. } +//⌃ enclosing_range_end 0.1.test `sg/inlinestruct`/MyFunc(). diff --git a/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go b/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go index f5da0ee..5d76b16 100755 --- a/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go +++ b/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go @@ -49,6 +49,7 @@ // > struct{} // > ``` +//⌄ enclosing_range_start 0.1.test `sg/inlinestruct`/ProcessImpl#Process(). func (p *ProcessImpl) Process(payload Limit) { panic("not implemented") } // ^ definition local 2 // ^^^^^^^^^^^ reference 0.1.test `sg/inlinestruct`/ProcessImpl# @@ -59,6 +60,8 @@ // > ``` // ^^^^^^^ definition local 3 // ^^^^^ reference 0.1.test `sg/inlinestruct`/Limit# +// ⌃ enclosing_range_end 0.1.test `sg/inlinestruct`/ProcessImpl#Process(). +//⌄ enclosing_range_start 0.1.test `sg/inlinestruct`/ProcessImpl#ProcessorType(). func (p *ProcessImpl) ProcessorType() string { panic("not implemented") } // ^ definition local 4 // ^^^^^^^^^^^ reference 0.1.test `sg/inlinestruct`/ProcessImpl# @@ -67,6 +70,7 @@ // > ```go // > func (*ProcessImpl).ProcessorType() string // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/inlinestruct`/ProcessImpl#ProcessorType(). var _ Processor[Limit] = &ProcessImpl{} // ^^^^^^^^^ reference 0.1.test `sg/inlinestruct`/Processor# diff --git a/internal/testdata/snapshots/output/inlinestruct/inlinestruct_interface.go b/internal/testdata/snapshots/output/inlinestruct/inlinestruct_interface.go index bc5e703..0eb2c63 100755 --- a/internal/testdata/snapshots/output/inlinestruct/inlinestruct_interface.go +++ b/internal/testdata/snapshots/output/inlinestruct/inlinestruct_interface.go @@ -4,6 +4,7 @@ import "context" // ^^^^^^^ reference github.com/golang/go/src go1.22 context/ +//⌄ enclosing_range_start 0.1.test `sg/inlinestruct`/Target(). func Target() interface { // ^^^^^^ definition 0.1.test `sg/inlinestruct`/Target(). // documentation @@ -45,7 +46,9 @@ } { panic("not implemented") } +//⌃ enclosing_range_end 0.1.test `sg/inlinestruct`/Target(). +//⌄ enclosing_range_start 0.1.test `sg/inlinestruct`/something(). func something() { // ^^^^^^^^^ definition 0.1.test `sg/inlinestruct`/something(). // documentation @@ -61,4 +64,5 @@ // ^^^^^^^ reference github.com/golang/go/src go1.22 context/ // ^^^^^^^^^^ reference github.com/golang/go/src go1.22 context/Background(). } +//⌃ enclosing_range_end 0.1.test `sg/inlinestruct`/something(). diff --git a/internal/testdata/snapshots/output/package-documentation/primary.go b/internal/testdata/snapshots/output/package-documentation/primary.go index aec3ce5..e3ccebf 100755 --- a/internal/testdata/snapshots/output/package-documentation/primary.go +++ b/internal/testdata/snapshots/output/package-documentation/primary.go @@ -4,10 +4,12 @@ // documentation // > This is documentation for this package. +//⌄ enclosing_range_start github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/Exported(). func Exported() {} // ^^^^^^^^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/Exported(). // documentation // > ```go // > func Exported() // > ``` +// ⌃ enclosing_range_end github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/Exported(). diff --git a/internal/testdata/snapshots/output/package-documentation/secondary.go b/internal/testdata/snapshots/output/package-documentation/secondary.go index 5698163..dda5e1f 100755 --- a/internal/testdata/snapshots/output/package-documentation/secondary.go +++ b/internal/testdata/snapshots/output/package-documentation/secondary.go @@ -1,10 +1,12 @@ package packagedocumentation // ^^^^^^^^^^^^^^^^^^^^ reference github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/ +//⌄ enclosing_range_start github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/AlsoExporter(). func AlsoExporter() {} // ^^^^^^^^^^^^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/AlsoExporter(). // documentation // > ```go // > func AlsoExporter() // > ``` +// ⌃ enclosing_range_end github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/package-documentation`/AlsoExporter(). diff --git a/internal/testdata/snapshots/output/replace-directives/replace_directives.go b/internal/testdata/snapshots/output/replace-directives/replace_directives.go index dda4338..4b564b6 100755 --- a/internal/testdata/snapshots/output/replace-directives/replace_directives.go +++ b/internal/testdata/snapshots/output/replace-directives/replace_directives.go @@ -11,6 +11,7 @@ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference github.com/sourcegraph/gologin c6f1b62954d8 `github.com/dghubble/gologin`/ ) +//⌄ enclosing_range_start 0.1.test `sg/replace-directives`/Something(). func Something() { // ^^^^^^^^^ definition 0.1.test `sg/replace-directives`/Something(). // documentation @@ -23,4 +24,5 @@ // ^^^^^^^ reference github.com/sourcegraph/gologin c6f1b62954d8 `github.com/dghubble/gologin`/ // ^^^^^^^^^^^^^^^^^^^ reference github.com/sourcegraph/gologin c6f1b62954d8 `github.com/dghubble/gologin`/DefaultCookieConfig. } +//⌃ enclosing_range_end 0.1.test `sg/replace-directives`/Something(). diff --git a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup.go b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup.go index 6df94d4..cac051d 100755 --- a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup.go +++ b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup.go @@ -1,10 +1,12 @@ package server // ^^^^^^ reference 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/ +//⌄ enclosing_range_start 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/LiterallyAnything(). func LiterallyAnything() {} // ^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/LiterallyAnything(). // documentation // > ```go // > func LiterallyAnything() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/LiterallyAnything(). diff --git a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup_test.go b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup_test.go index 98ed031..8a413ff 100755 --- a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup_test.go +++ b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/cleanup_test.go @@ -4,6 +4,7 @@ import "testing" // ^^^^^^^ reference github.com/golang/go/src go1.22 testing/ +//⌄ enclosing_range_start 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestStuff(). func TestStuff(t *testing.T) { // ^^^^^^^^^ definition 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestStuff(). // documentation @@ -24,4 +25,5 @@ // ^^ reference local 1 // ^^^^ reference local 2 } +//⌃ enclosing_range_end 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestStuff(). diff --git a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server.go b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server.go index bdcbb71..e72bff5 100755 --- a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server.go +++ b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server.go @@ -3,10 +3,12 @@ // documentation // > package server +//⌄ enclosing_range_start 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/AnythingAtAll(). func AnythingAtAll() {} // ^^^^^^^^^^^^^ definition 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/AnythingAtAll(). // documentation // > ```go // > func AnythingAtAll() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/AnythingAtAll(). diff --git a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server_test.go b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server_test.go index 8ee6dda..9270cd0 100755 --- a/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server_test.go +++ b/internal/testdata/snapshots/output/sharedtestmodule/cmd/gitserver/server/server_test.go @@ -4,6 +4,7 @@ import "testing" // ^^^^^^^ reference github.com/golang/go/src go1.22 testing/ +//⌄ enclosing_range_start 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestExecRequest(). func TestExecRequest(t *testing.T) { // ^^^^^^^^^^^^^^^ definition 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestExecRequest(). // documentation @@ -17,7 +18,9 @@ // ^ reference local 0 // ^^^ reference github.com/golang/go/src go1.22 testing/common#Log(). } +//⌃ enclosing_range_end 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/TestExecRequest(). +//⌄ enclosing_range_start 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/runCmd(). func runCmd(t *testing.T, dir string, cmd string, arg ...string) {} // ^^^^^^ definition 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/runCmd(). // documentation @@ -30,4 +33,5 @@ // ^^^ definition local 2 // ^^^ definition local 3 // ^^^ definition local 4 +// ⌃ enclosing_range_end 0.1.test `sg/sharedtestmodule/cmd/gitserver/server`/runCmd(). diff --git a/internal/testdata/snapshots/output/switches/switches.go b/internal/testdata/snapshots/output/switches/switches.go index 290e35e..afd3338 100755 --- a/internal/testdata/snapshots/output/switches/switches.go +++ b/internal/testdata/snapshots/output/switches/switches.go @@ -18,6 +18,7 @@ // > ``` // Something does some things... and stuff +//⌄ enclosing_range_start 0.1.test `sg/switches`/CustomSwitch#Something(). func (c *CustomSwitch) Something() bool { return false } // ^ definition local 0 // ^^^^^^^^^^^^ reference 0.1.test `sg/switches`/CustomSwitch# @@ -28,7 +29,9 @@ // > ``` // documentation // > Something does some things... and stuff +// ⌃ enclosing_range_end 0.1.test `sg/switches`/CustomSwitch#Something(). +//⌄ enclosing_range_start 0.1.test `sg/switches`/Switch(). func Switch(interfaceValue interface{}) bool { // ^^^^^^ definition 0.1.test `sg/switches`/Switch(). // documentation @@ -66,4 +69,5 @@ return false } } +//⌃ enclosing_range_end 0.1.test `sg/switches`/Switch(). diff --git a/internal/testdata/snapshots/output/testdata/anonymous_structs.go b/internal/testdata/snapshots/output/testdata/anonymous_structs.go index 2f126ef..d944bc4 100755 --- a/internal/testdata/snapshots/output/testdata/anonymous_structs.go +++ b/internal/testdata/snapshots/output/testdata/anonymous_structs.go @@ -72,6 +72,7 @@ } } +//⌄ enclosing_range_start 0.1.test `sg/testdata`/funcContainingAnonymousStructs(). func funcContainingAnonymousStructs() { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/funcContainingAnonymousStructs(). // documentation @@ -177,4 +178,5 @@ // ^ reference 0.1.test `sg/testdata`/TypeContainingAnonymousStructs#c. // ^ reference 0.1.test `sg/testdata`/TypeContainingAnonymousStructs#c.Y. } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/funcContainingAnonymousStructs(). diff --git a/internal/testdata/snapshots/output/testdata/cmd/minimal_main/minimal_main.go b/internal/testdata/snapshots/output/testdata/cmd/minimal_main/minimal_main.go index 0cac7be..9f1c327 100755 --- a/internal/testdata/snapshots/output/testdata/cmd/minimal_main/minimal_main.go +++ b/internal/testdata/snapshots/output/testdata/cmd/minimal_main/minimal_main.go @@ -40,10 +40,12 @@ // > struct{} // > ``` +//⌄ enclosing_range_start 0.1.test `sg/testdata/cmd/minimal_main`/main(). func main() {} // ^^^^ definition 0.1.test `sg/testdata/cmd/minimal_main`/main(). // documentation // > ```go // > func main() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata/cmd/minimal_main`/main(). diff --git a/internal/testdata/snapshots/output/testdata/conflicting_test_symbols/sandbox_unsupported_test.go b/internal/testdata/snapshots/output/testdata/conflicting_test_symbols/sandbox_unsupported_test.go index 6c1faa8..128caac 100755 --- a/internal/testdata/snapshots/output/testdata/conflicting_test_symbols/sandbox_unsupported_test.go +++ b/internal/testdata/snapshots/output/testdata/conflicting_test_symbols/sandbox_unsupported_test.go @@ -22,6 +22,7 @@ // ^^^^^^ reference github.com/golang/go/src go1.22 errors/ // ^^^ reference github.com/golang/go/src go1.22 errors/New(). +//⌄ enclosing_range_start 0.1.test `sg/testdata/conflicting_test_symbols`/newKey(). func newKey(t *testing.T) (string, error) { // ^^^^^^ definition 0.1.test `sg/testdata/conflicting_test_symbols`/newKey(). // documentation @@ -34,7 +35,9 @@ return "", ErrNotImplemented // ^^^^^^^^^^^^^^^^^ reference 0.1.test `sg/testdata/conflicting_test_symbols`/ErrNotImplemented. } +//⌃ enclosing_range_end 0.1.test `sg/testdata/conflicting_test_symbols`/newKey(). +//⌄ enclosing_range_start 0.1.test `sg/testdata/conflicting_test_symbols`/verifySandbox(). func verifySandbox(t *testing.T, s string) { // ^^^^^^^^^^^^^ definition 0.1.test `sg/testdata/conflicting_test_symbols`/verifySandbox(). // documentation @@ -47,4 +50,5 @@ // ^ definition local 2 return } +//⌃ enclosing_range_end 0.1.test `sg/testdata/conflicting_test_symbols`/verifySandbox(). diff --git a/internal/testdata/snapshots/output/testdata/data.go b/internal/testdata/snapshots/output/testdata/data.go index 3e82e8e..a4fb5b4 100755 --- a/internal/testdata/snapshots/output/testdata/data.go +++ b/internal/testdata/snapshots/output/testdata/data.go @@ -191,6 +191,7 @@ // ^^^^^^^^^^^ reference 0.1.test `sg/testdata`/StringAlias# // Doer is similar to the test interface (but not the same). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/TestStruct#Doer(). func (ts *TestStruct) Doer(ctx context.Context, data string) (score int, err error) { // ^^ definition local 3 // ^^^^^^^^^^ reference 0.1.test `sg/testdata`/TestStruct# @@ -210,6 +211,7 @@ return Score, nil // ^^^^^ reference 0.1.test `sg/testdata`/Score. } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/TestStruct#Doer(). // StructTagRegression is a struct that caused panic in the wild. Added here to // support a regression test. diff --git a/internal/testdata/snapshots/output/testdata/duplicate_path_id/main.go b/internal/testdata/snapshots/output/testdata/duplicate_path_id/main.go index 7dc6a91..b647f4a 100755 --- a/internal/testdata/snapshots/output/testdata/duplicate_path_id/main.go +++ b/internal/testdata/snapshots/output/testdata/duplicate_path_id/main.go @@ -23,6 +23,7 @@ // > struct{} // > ``` +//⌄ enclosing_range_start 0.1.test `sg/testdata/duplicate_path_id`/fetchMeta(). func fetchMeta() (string, *importMeta, *sourceMeta) { // ^^^^^^^^^ definition 0.1.test `sg/testdata/duplicate_path_id`/fetchMeta(). // documentation @@ -33,23 +34,30 @@ // ^^^^^^^^^^ reference 0.1.test `sg/testdata/duplicate_path_id`/sourceMeta# panic("hmm") } +//⌃ enclosing_range_end 0.1.test `sg/testdata/duplicate_path_id`/fetchMeta(). +//⌄ enclosing_range_start 0.1.test `sg/testdata/duplicate_path_id`/init(). func init() {} // ^^^^ definition 0.1.test `sg/testdata/duplicate_path_id`/init(). // documentation // > ```go // > func init() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata/duplicate_path_id`/init(). +//⌄ enclosing_range_start 0.1.test `sg/testdata/duplicate_path_id`/init(). func init() {} // ^^^^ definition 0.1.test `sg/testdata/duplicate_path_id`/init(). // documentation // > ```go // > func init() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata/duplicate_path_id`/init(). +//⌄ enclosing_range_start 0.1.test `sg/testdata/duplicate_path_id`/init(). func init() {} // ^^^^ definition 0.1.test `sg/testdata/duplicate_path_id`/init(). // documentation // > ```go // > func init() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata/duplicate_path_id`/init(). diff --git a/internal/testdata/snapshots/output/testdata/duplicate_path_id/two.go b/internal/testdata/snapshots/output/testdata/duplicate_path_id/two.go index 4792ca6..f85af41 100755 --- a/internal/testdata/snapshots/output/testdata/duplicate_path_id/two.go +++ b/internal/testdata/snapshots/output/testdata/duplicate_path_id/two.go @@ -3,10 +3,12 @@ // documentation // > package gosrc +//⌄ enclosing_range_start 0.1.test `sg/testdata/duplicate_path_id`/init(). func init() {} // ^^^^ definition 0.1.test `sg/testdata/duplicate_path_id`/init(). // documentation // > ```go // > func init() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata/duplicate_path_id`/init(). diff --git a/internal/testdata/snapshots/output/testdata/implementations.go b/internal/testdata/snapshots/output/testdata/implementations.go index c5d41bb..b67c12c 100755 --- a/internal/testdata/snapshots/output/testdata/implementations.go +++ b/internal/testdata/snapshots/output/testdata/implementations.go @@ -60,6 +60,7 @@ // > ``` // relationship 0.1.test `sg/testdata`/I1# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/T1#F1(). func (r T1) F1() {} // ^ definition local 0 // ^^ reference 0.1.test `sg/testdata`/T1# @@ -69,6 +70,7 @@ // > func (T1).F1() // > ``` // relationship 0.1.test `sg/testdata`/I1#F1. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/T1#F1(). type T2 int // ^^ definition 0.1.test `sg/testdata`/T2# @@ -79,6 +81,7 @@ // relationship 0.1.test `sg/testdata`/I1# implementation // relationship 0.1.test `sg/testdata`/I2# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/T2#F1(). func (r T2) F1() {} // ^ definition local 1 // ^^ reference 0.1.test `sg/testdata`/T2# @@ -88,6 +91,8 @@ // > func (T2).F1() // > ``` // relationship 0.1.test `sg/testdata`/I1#F1. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/T2#F1(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/T2#F2(). func (r T2) F2() {} // ^ definition local 2 // ^^ reference 0.1.test `sg/testdata`/T2# @@ -97,6 +102,7 @@ // > func (T2).F2() // > ``` // relationship 0.1.test `sg/testdata`/I2#F2. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/T2#F2(). type A1 = T1 // ^^ definition 0.1.test `sg/testdata`/A1# @@ -164,6 +170,7 @@ // relationship 0.1.test `sg/testdata`/InterfaceWithExportedMethod# implementation // relationship 0.1.test `sg/testdata`/InterfaceWithNonExportedMethod# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Foo#nonExportedMethod(). func (r Foo) nonExportedMethod() {} // ^ definition local 3 // ^^^ reference 0.1.test `sg/testdata`/Foo# @@ -173,6 +180,8 @@ // > func (Foo).nonExportedMethod() // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithNonExportedMethod#nonExportedMethod. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Foo#nonExportedMethod(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Foo#ExportedMethod(). func (r Foo) ExportedMethod() {} // ^ definition local 4 // ^^^ reference 0.1.test `sg/testdata`/Foo# @@ -182,6 +191,8 @@ // > func (Foo).ExportedMethod() // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithExportedMethod#ExportedMethod. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Foo#ExportedMethod(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Foo#Close(). func (r Foo) Close() error { return nil } // ^ definition local 5 // ^^^ reference 0.1.test `sg/testdata`/Foo# @@ -192,6 +203,7 @@ // > ``` // relationship github.com/golang/go/src go1.22 io/Closer#Close. implementation // relationship 0.1.test `sg/testdata`/I3#Close. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Foo#Close(). type SharedOne interface { // ^^^^^^^^^ definition 0.1.test `sg/testdata`/SharedOne# @@ -260,6 +272,7 @@ // relationship 0.1.test `sg/testdata`/SharedOne# implementation // relationship 0.1.test `sg/testdata`/SharedTwo# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Between#Shared(). func (Between) Shared() {} // ^^^^^^^ reference 0.1.test `sg/testdata`/Between# // ^^^^^^ definition 0.1.test `sg/testdata`/Between#Shared(). @@ -269,6 +282,8 @@ // > ``` // relationship 0.1.test `sg/testdata`/SharedOne#Shared. implementation // relationship 0.1.test `sg/testdata`/SharedTwo#Shared. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Between#Shared(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Between#Distinct(). func (Between) Distinct() {} // ^^^^^^^ reference 0.1.test `sg/testdata`/Between# // ^^^^^^^^ definition 0.1.test `sg/testdata`/Between#Distinct(). @@ -277,6 +292,8 @@ // > func (Between).Distinct() // > ``` // relationship 0.1.test `sg/testdata`/SharedOne#Distinct. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Between#Distinct(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Between#Unique(). func (Between) Unique() {} // ^^^^^^^ reference 0.1.test `sg/testdata`/Between# // ^^^^^^ definition 0.1.test `sg/testdata`/Between#Unique(). @@ -285,7 +302,9 @@ // > func (Between).Unique() // > ``` // relationship 0.1.test `sg/testdata`/SharedTwo#Unique. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/Between#Unique(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/shouldShow(). func shouldShow(shared SharedOne) { // ^^^^^^^^^^ definition 0.1.test `sg/testdata`/shouldShow(). // documentation @@ -298,4 +317,5 @@ // ^^^^^^ reference local 6 // ^^^^^^ reference 0.1.test `sg/testdata`/SharedOne#Shared. } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/shouldShow(). diff --git a/internal/testdata/snapshots/output/testdata/implementations_methods.go b/internal/testdata/snapshots/output/testdata/implementations_methods.go index 8efe336..2cbe659 100755 --- a/internal/testdata/snapshots/output/testdata/implementations_methods.go +++ b/internal/testdata/snapshots/output/testdata/implementations_methods.go @@ -33,6 +33,7 @@ // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethod# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/StructWithMethods#SingleMethod(). func (StructWithMethods) SingleMethod() float64 { return 5.0 } // ^^^^^^^^^^^^^^^^^ reference 0.1.test `sg/testdata`/StructWithMethods# // ^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/StructWithMethods#SingleMethod(). @@ -41,6 +42,7 @@ // > func (StructWithMethods).SingleMethod() float64 // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethod#SingleMethod. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/StructWithMethods#SingleMethod(). type InterfaceWithSingleMethodTwoImplementers interface { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/InterfaceWithSingleMethodTwoImplementers# @@ -74,6 +76,7 @@ // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethodTwoImplementers# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/TwoImplOne#SingleMethodTwoImpl(). func (TwoImplOne) SingleMethodTwoImpl() float64 { return 5.0 } // ^^^^^^^^^^ reference 0.1.test `sg/testdata`/TwoImplOne# // ^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/TwoImplOne#SingleMethodTwoImpl(). @@ -82,6 +85,7 @@ // > func (TwoImplOne).SingleMethodTwoImpl() float64 // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethodTwoImplementers#SingleMethodTwoImpl. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/TwoImplOne#SingleMethodTwoImpl(). type TwoImplTwo struct{} // ^^^^^^^^^^ definition 0.1.test `sg/testdata`/TwoImplTwo# @@ -95,6 +99,7 @@ // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethodTwoImplementers# implementation +//⌄ enclosing_range_start 0.1.test `sg/testdata`/TwoImplTwo#SingleMethodTwoImpl(). func (TwoImplTwo) SingleMethodTwoImpl() float64 { return 5.0 } // ^^^^^^^^^^ reference 0.1.test `sg/testdata`/TwoImplTwo# // ^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/TwoImplTwo#SingleMethodTwoImpl(). @@ -103,6 +108,8 @@ // > func (TwoImplTwo).SingleMethodTwoImpl() float64 // > ``` // relationship 0.1.test `sg/testdata`/InterfaceWithSingleMethodTwoImplementers#SingleMethodTwoImpl. implementation +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/TwoImplTwo#SingleMethodTwoImpl(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/TwoImplTwo#RandomThingThatDoesntMatter(). func (TwoImplTwo) RandomThingThatDoesntMatter() float64 { return 5.0 } // ^^^^^^^^^^ reference 0.1.test `sg/testdata`/TwoImplTwo# // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/TwoImplTwo#RandomThingThatDoesntMatter(). @@ -110,4 +117,5 @@ // > ```go // > func (TwoImplTwo).RandomThingThatDoesntMatter() float64 // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/TwoImplTwo#RandomThingThatDoesntMatter(). diff --git a/internal/testdata/snapshots/output/testdata/implementations_remote.go b/internal/testdata/snapshots/output/testdata/implementations_remote.go index 9ce7f29..f431920 100755 --- a/internal/testdata/snapshots/output/testdata/implementations_remote.go +++ b/internal/testdata/snapshots/output/testdata/implementations_remote.go @@ -19,6 +19,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/testdata`/implementsWriter#Header(). func (implementsWriter) Header() http.Header { panic("Just for how") } // ^^^^^^^^^^^^^^^^ reference 0.1.test `sg/testdata`/implementsWriter# // ^^^^^^ definition 0.1.test `sg/testdata`/implementsWriter#Header(). @@ -29,6 +30,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/testdata`/implementsWriter#Header(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/implementsWriter#Write(). func (implementsWriter) Write([]byte) (int, error) { panic("Just for show") } // ^^^^^^^^^^^^^^^^ reference 0.1.test `sg/testdata`/implementsWriter# // ^^^^^ definition 0.1.test `sg/testdata`/implementsWriter#Write(). @@ -40,6 +43,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/testdata`/implementsWriter#Write(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/implementsWriter#WriteHeader(). func (implementsWriter) WriteHeader(statusCode int) {} // ^^^^^^^^^^^^^^^^ reference 0.1.test `sg/testdata`/implementsWriter# // ^^^^^^^^^^^ definition 0.1.test `sg/testdata`/implementsWriter#WriteHeader(). @@ -49,7 +54,9 @@ // > ``` // relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#WriteHeader. implementation // ^^^^^^^^^^ definition local 0 +// ⌃ enclosing_range_end 0.1.test `sg/testdata`/implementsWriter#WriteHeader(). +//⌄ enclosing_range_start 0.1.test `sg/testdata`/ShowsInSignature(). func ShowsInSignature(respWriter http.ResponseWriter) { // ^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/ShowsInSignature(). // documentation @@ -63,4 +70,5 @@ // ^^^^^^^^^^ reference local 1 // ^^^^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/ResponseWriter#WriteHeader. } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/ShowsInSignature(). diff --git a/internal/testdata/snapshots/output/testdata/named_import.go b/internal/testdata/snapshots/output/testdata/named_import.go index c0b8ded..1a02fb1 100755 --- a/internal/testdata/snapshots/output/testdata/named_import.go +++ b/internal/testdata/snapshots/output/testdata/named_import.go @@ -9,6 +9,7 @@ // ^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/ ) +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Example(). func Example() { // ^^^^^^^ definition 0.1.test `sg/testdata`/Example(). // documentation @@ -20,4 +21,5 @@ // ^ reference local 0 // ^^^^^^^^^^^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/CanonicalHeaderKey(). } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/Example(). diff --git a/internal/testdata/snapshots/output/testdata/parallel.go b/internal/testdata/snapshots/output/testdata/parallel.go index f4f25a0..b0575a0 100755 --- a/internal/testdata/snapshots/output/testdata/parallel.go +++ b/internal/testdata/snapshots/output/testdata/parallel.go @@ -25,6 +25,7 @@ // Parallel invokes each of the given parallelizable functions in their own goroutines and // returns the first error to occur. This method will block until all goroutines have returned. +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Parallel(). func Parallel(ctx context.Context, fns ...ParallelizableFunc) error { // ^^^^^^^^ definition 0.1.test `sg/testdata`/Parallel(). // documentation @@ -84,4 +85,5 @@ return nil } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/Parallel(). diff --git a/internal/testdata/snapshots/output/testdata/typeswitch.go b/internal/testdata/snapshots/output/testdata/typeswitch.go index f70cf6c..743227a 100755 --- a/internal/testdata/snapshots/output/testdata/typeswitch.go +++ b/internal/testdata/snapshots/output/testdata/typeswitch.go @@ -1,6 +1,7 @@ package testdata // ^^^^^^^^ reference 0.1.test `sg/testdata`/ +//⌄ enclosing_range_start 0.1.test `sg/testdata`/Switch(). func Switch(interfaceValue interface{}) bool { // ^^^^^^ definition 0.1.test `sg/testdata`/Switch(). // documentation @@ -29,4 +30,5 @@ return false } } +//⌃ enclosing_range_end 0.1.test `sg/testdata`/Switch(). diff --git a/internal/testdata/snapshots/output/testspecial/foo.go b/internal/testdata/snapshots/output/testspecial/foo.go index e1aae65..0ba160c 100755 --- a/internal/testdata/snapshots/output/testspecial/foo.go +++ b/internal/testdata/snapshots/output/testspecial/foo.go @@ -3,10 +3,12 @@ // documentation // > package testspecial +//⌄ enclosing_range_start 0.1.test `sg/testspecial`/Foo(). func Foo() {} // ^^^ definition 0.1.test `sg/testspecial`/Foo(). // documentation // > ```go // > func Foo() // > ``` +// ⌃ enclosing_range_end 0.1.test `sg/testspecial`/Foo(). diff --git a/internal/testdata/snapshots/output/testspecial/foo_other_test.go b/internal/testdata/snapshots/output/testspecial/foo_other_test.go index 39ba768..6045f77 100755 --- a/internal/testdata/snapshots/output/testspecial/foo_other_test.go +++ b/internal/testdata/snapshots/output/testspecial/foo_other_test.go @@ -11,6 +11,7 @@ // ^^^^^^^^^^^^^^ reference 0.1.test `sg/testspecial`/ ) +//⌄ enclosing_range_start 0.1.test `sg/testspecial_test`/TestFoo_Blackbox(). func TestFoo_Blackbox(*testing.T) { testspecial.Foo() } // ^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testspecial_test`/TestFoo_Blackbox(). // documentation @@ -21,4 +22,5 @@ // ^ reference github.com/golang/go/src go1.22 testing/T# // ^^^^^^^^^^^ reference 0.1.test `sg/testspecial`/ // ^^^ reference 0.1.test `sg/testspecial`/Foo(). +// ⌃ enclosing_range_end 0.1.test `sg/testspecial_test`/TestFoo_Blackbox(). diff --git a/internal/testdata/snapshots/output/testspecial/foo_test.go b/internal/testdata/snapshots/output/testspecial/foo_test.go index 98f6eda..a29ecb6 100755 --- a/internal/testdata/snapshots/output/testspecial/foo_test.go +++ b/internal/testdata/snapshots/output/testspecial/foo_test.go @@ -1,6 +1,7 @@ package testspecial // ^^^^^^^^^^^ reference 0.1.test `sg/testspecial`/ +//⌄ enclosing_range_start 0.1.test `sg/testspecial`/TestFoo_Whitebox(). func TestFoo_Whitebox() { Foo() } // ^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testspecial`/TestFoo_Whitebox(). // documentation @@ -8,4 +9,5 @@ // > func TestFoo_Whitebox() // > ``` // ^^^ reference 0.1.test `sg/testspecial`/Foo(). +// ⌃ enclosing_range_end 0.1.test `sg/testspecial`/TestFoo_Whitebox(). diff --git a/internal/visitors/visitor_file.go b/internal/visitors/visitor_file.go index 930df9e..7ecf939 100644 --- a/internal/visitors/visitor_file.go +++ b/internal/visitors/visitor_file.go @@ -30,6 +30,7 @@ func NewFileVisitor( pkgLookup loader.PackageLookup, pkgSymbols *lookup.Package, globalSymbols *lookup.Global, + enclosingNodeMap map[*ast.Ident]ast.Node, ) *fileVisitor { caseClauses := map[token.Pos]types.Object{} for implicit, obj := range pkg.TypesInfo.Implicits { @@ -59,6 +60,7 @@ func NewFileVisitor( caseClauses: caseClauses, pkgNameOverride: map[newtypes.PackageID]string{}, }, + enclosingNodeMap: enclosingNodeMap, } } @@ -98,6 +100,10 @@ type fileVisitor struct { // if ImportSpec.Name is not nil. Otherwise, just use package directly pkgNameOverride map[newtypes.PackageID]string } + + // enclosingNodeMap maps certain nodes to their enclosing nodes for + // enclosing range computation. + enclosingNodeMap map[*ast.Ident]ast.Node } // Implements ast.Visitor @@ -137,7 +143,7 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { symName := v.createNewLocalSymbol(node.Name.Pos(), pkgAlias) rangeFromName := symbols.RangeFromName( v.pkg.Fset.Position(node.Name.Pos()), node.Name.Name, false) - v.NewDefinition(symName, rangeFromName) + v.NewDefinition(symName, rangeFromName, nil) // Save package name override, so that we use the new local symbol // within this file @@ -157,8 +163,8 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { // compared to almost every other construct in the language. switch sel := use.(type) { case *types.PkgName: - pos := ident.NamePos - position := v.pkg.Fset.Position(pos) + startPosition := v.pkg.Fset.Position(ident.Pos()) + endPosition := v.pkg.Fset.Position(ident.End()) pkgID := newtypes.GetFromTypesPackage(sel.Imported()) var symbolName string @@ -174,7 +180,7 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { symbolName = symbol.Symbol } - v.AppendSymbolReference(symbolName, scipRange(position, sel), nil) + v.AppendSymbolReference(symbolName, scipRange(startPosition, endPosition, sel), nil) // Then walk the selection ast.Walk(v, node.Sel) @@ -201,13 +207,13 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { return nil } - pos := node.NamePos - position := v.pkg.Fset.Position(pos) + startPosition := v.pkg.Fset.Position(node.Pos()) + endPosition := v.pkg.Fset.Position(node.End()) // Short circuit on case clauses if obj, ok := v.overrides.caseClauses[node.Pos()]; ok { symName := v.createNewLocalSymbol(obj.Pos(), obj) - v.NewDefinition(symName, scipRange(position, obj)) + v.NewDefinition(symName, scipRange(startPosition, endPosition, obj), nil) return nil } @@ -224,8 +230,8 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { } else { symName = v.createNewLocalSymbol(def.Pos(), def) } - - v.NewDefinition(symName, scipRange(position, def)) + fmt.Printf("Definition: %s | %s | %s\n", node.Name, def, v.enclosingRange(node)) + v.NewDefinition(symName, scipRange(startPosition, endPosition, def), v.enclosingRange(node)) } // Emit Reference @@ -276,7 +282,7 @@ func (v *fileVisitor) Visit(n ast.Node) ast.Visitor { symbol = symInfo.Symbol } - v.AppendSymbolReference(symbol, scipRange(position, ref), overrideType) + v.AppendSymbolReference(symbol, scipRange(startPosition, endPosition, ref), overrideType) } if def == nil && ref == nil { @@ -314,11 +320,12 @@ func (v *fileVisitor) emitImportReference( // NewDefinition emits a scip.Occurence ONLY. This will not emit a // new symbol. You must do that using DeclareNewSymbol[ForPos] -func (v *fileVisitor) NewDefinition(symbol string, rng []int32) { +func (v *fileVisitor) NewDefinition(symbol string, rng []int32, enclRng []int32) { v.occurrences = append(v.occurrences, &scip.Occurrence{ - Range: rng, - Symbol: symbol, - SymbolRoles: symbolDefinition, + Range: rng, + Symbol: symbol, + SymbolRoles: symbolDefinition, + EnclosingRange: enclRng, }) } @@ -371,3 +378,31 @@ func (v *fileVisitor) ToScipDocument() *scip.Document { Symbols: documentSymbols, } } + +func (v *fileVisitor) enclosingRange(n *ast.Ident) []int32 { + if n == nil { + return nil + } + + enclosingNode, ok := v.enclosingNodeMap[n] + if !ok { + return nil + } + + startPosition := v.pkg.Fset.Position(enclosingNode.Pos()) + endPosition := v.pkg.Fset.Position(enclosingNode.End()) + return scipRange(startPosition, endPosition, v.pkg.TypesInfo.Defs[n]) +} + +// EnclosingNodeMap builds a map from [ast.Ident] to its enclosing node for enclosing range computation. +// Currently only supports mapping [ast.Ident] to its enclosing [ast.FuncDecl]. +func EnclosingNodeMap(root ast.Node, enclNodes map[*ast.Ident]ast.Node) { + ast.PreorderStack(root, nil, func(n ast.Node, stack []ast.Node) bool { + if ident, ok := n.(*ast.Ident); ok && len(stack) > 1 { + if funcDecl, ok := stack[len(stack)-1].(*ast.FuncDecl); ok { + enclNodes[ident] = funcDecl + } + } + return true + }) +} diff --git a/internal/visitors/visitors.go b/internal/visitors/visitors.go index b48e58e..2fd0df6 100644 --- a/internal/visitors/visitors.go +++ b/internal/visitors/visitors.go @@ -94,17 +94,20 @@ func descriptorTerm(name string) *scip.Descriptor { } } -func scipRange(position token.Position, obj types.Object) []int32 { +func scipRange(start, end token.Position, obj types.Object) []int32 { var adjustment int32 = 0 if pkgName, ok := obj.(*types.PkgName); ok && strings.HasPrefix(pkgName.Name(), `"`) { adjustment = 1 } - line := int32(position.Line - 1) - column := int32(position.Column - 1) - n := int32(len(obj.Name())) - - return []int32{line, column + adjustment, column + n - adjustment} + startLine := int32(start.Line - 1) + startColumn := int32(start.Column - 1) + endLine := int32(end.Line - 1) + endColumn := int32(end.Column - 1) + if startLine != endLine { + return []int32{startLine, startColumn + adjustment, endLine, endColumn - adjustment} + } + return []int32{startLine, startColumn + adjustment, endColumn - adjustment} } func getIdentOfTypeExpr(pkg *packages.Package, ty ast.Expr) []*ast.Ident {