Skip to content

Commit 94e8caa

Browse files
Support enclosing ranges for function definitions
1 parent ae3fc19 commit 94e8caa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+218
-20
lines changed

internal/index/scip.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func Index(writer func(proto.Message), opts config.IndexOpts) error {
131131
continue
132132
}
133133

134+
enclosingNodeMap := map[*ast.Ident]ast.Node{}
135+
visitors.EnclosingNodeMap(f, enclosingNodeMap)
136+
134137
// If possible, any state required for created a scip document
135138
// should be contained in the visitor. This makes sure that we can
136139
// garbage collect everything that's there after each loop,
@@ -142,6 +145,7 @@ func Index(writer func(proto.Message), opts config.IndexOpts) error {
142145
allPackages,
143146
pkgSymbols,
144147
globalSymbols,
148+
enclosingNodeMap,
145149
)
146150

147151
// Traverse the file

internal/testdata/snapshots/output/alias/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
// > ```
7373
)
7474

75+
//⌄ enclosing_range_start github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().
7576
func f(u U) {}
7677
// ^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().
7778
// documentation
@@ -80,4 +81,5 @@
8081
// > ```
8182
// ^ definition local 0
8283
// ^ reference github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/U#
84+
// ⌃ enclosing_range_end github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/f().
8385

internal/testdata/snapshots/output/embedded/embedded.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// ^^^ reference github.com/golang/go/src go1.22 `os/exec`/Cmd#
3434
}
3535

36+
//⌄ enclosing_range_start 0.1.test `sg/embedded`/wrapExecCommand().
3637
func wrapExecCommand(c *exec.Cmd) {
3738
// ^^^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/wrapExecCommand().
3839
// documentation
@@ -47,6 +48,7 @@
4748
// ^^^ reference 0.1.test `sg/embedded`/osExecCommand#Cmd.
4849
// ^ reference local 0
4950
}
51+
//⌃ enclosing_range_end 0.1.test `sg/embedded`/wrapExecCommand().
5052

5153
type Inner struct {
5254
// ^^^^^ definition 0.1.test `sg/embedded`/Inner#
@@ -110,6 +112,7 @@
110112
// > ```
111113
}
112114

115+
//⌄ enclosing_range_start 0.1.test `sg/embedded`/useOfCompositeStructs().
113116
func useOfCompositeStructs() {
114117
// ^^^^^^^^^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/useOfCompositeStructs().
115118
// documentation
@@ -145,4 +148,5 @@
145148
// ^^^^^ reference 0.1.test `sg/embedded`/Outer#Inner.
146149
// ^ reference 0.1.test `sg/embedded`/Inner#Y.
147150
}
151+
//⌃ enclosing_range_end 0.1.test `sg/embedded`/useOfCompositeStructs().
148152

internal/testdata/snapshots/output/embedded/internal/nested.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// ^^^^^^^^^^^ reference 0.1.test `sg/embedded`/
1111
)
1212

13+
//⌄ enclosing_range_start 0.1.test `sg/embedded/internal`/Something().
1314
func Something(recent embedded.RecentCommittersResults) {
1415
// ^^^^^^^^^ definition 0.1.test `sg/embedded/internal`/Something().
1516
// documentation
@@ -36,4 +37,5 @@
3637
}
3738
}
3839
}
40+
//⌃ enclosing_range_end 0.1.test `sg/embedded/internal`/Something().
3941

internal/testdata/snapshots/output/embedded/nested.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// > ```
3939
}
4040

41+
//⌄ enclosing_range_start 0.1.test `sg/embedded`/NestedExample().
4142
func NestedExample(n NestedHandler) {
4243
// ^^^^^^^^^^^^^ definition 0.1.test `sg/embedded`/NestedExample().
4344
// documentation
@@ -57,4 +58,5 @@
5758
// ^ reference local 0
5859
// ^^^^^ reference 0.1.test `sg/embedded`/NestedHandler#Other.
5960
}
61+
//⌃ enclosing_range_end 0.1.test `sg/embedded`/NestedExample().
6062

internal/testdata/snapshots/output/generallyeric/generallyeric.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import "fmt"
88
// ^^^ reference github.com/golang/go/src go1.22 fmt/
99

10+
//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/Print().
1011
func Print[T any](s []T) {
1112
// ^^^^^ definition 0.1.test `sg/generallyeric`/Print().
1213
// documentation
@@ -25,4 +26,5 @@
2526
// ^ reference local 2
2627
}
2728
}
29+
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/Print().
2830

internal/testdata/snapshots/output/generallyeric/new_operators.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// ^^^^^^^ reference golang.org/x/exp 47842c84f3db `golang.org/x/exp/constraints`/Complex#
2626
}
2727

28+
//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/Double().
2829
func Double[T Number](value T) T {
2930
// ^^^^^^ definition 0.1.test `sg/generallyeric`/Double().
3031
// documentation
@@ -39,6 +40,7 @@
3940
return value * 2
4041
// ^^^^^ reference local 1
4142
}
43+
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/Double().
4244

4345
type Box[T any] struct {
4446
// ^^^ definition 0.1.test `sg/generallyeric`/Box#

internal/testdata/snapshots/output/generallyeric/person.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// > ```
3333
// relationship 0.1.test `sg/generallyeric`/Person# implementation
3434

35+
//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/worker#Work().
3536
func (w worker) Work() {
3637
// ^ definition local 0
3738
// ^^^^^^ reference 0.1.test `sg/generallyeric`/worker#
@@ -46,7 +47,9 @@
4647
// ^^^^^^ reference github.com/golang/go/src go1.22 fmt/Printf().
4748
// ^ reference local 0
4849
}
50+
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/worker#Work().
4951

52+
//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/DoWork().
5053
func DoWork[T Person](things []T) {
5154
// ^^^^^^ definition 0.1.test `sg/generallyeric`/DoWork().
5255
// documentation
@@ -65,7 +68,9 @@
6568
// ^^^^ reference 0.1.test `sg/generallyeric`/Person#Work.
6669
}
6770
}
71+
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/DoWork().
6872

73+
//⌄ enclosing_range_start 0.1.test `sg/generallyeric`/main().
6974
func main() {
7075
// ^^^^ definition 0.1.test `sg/generallyeric`/main().
7176
// documentation
@@ -90,4 +95,5 @@
9095
// ^ reference local 5
9196
// ^ reference local 6
9297
}
98+
//⌃ enclosing_range_end 0.1.test `sg/generallyeric`/main().
9399

internal/testdata/snapshots/output/impls/impls.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
// relationship 0.1.test `sg/impls`/I1# implementation
8080
// relationship 0.1.test `sg/impls`/I1Clone# implementation
8181

82+
//⌄ enclosing_range_start 0.1.test `sg/impls`/T1#F1().
8283
func (r T1) F1() {}
8384
// ^ definition local 0
8485
// ^^ reference 0.1.test `sg/impls`/T1#
@@ -89,6 +90,7 @@
8990
// > ```
9091
// relationship 0.1.test `sg/impls`/I1#F1. implementation
9192
// relationship 0.1.test `sg/impls`/I1Clone#F1. implementation
93+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T1#F1().
9294

9395
type T2 int
9496
// ^^ definition 0.1.test `sg/impls`/T2#
@@ -99,6 +101,7 @@
99101
// relationship 0.1.test `sg/impls`/I1# implementation
100102
// relationship 0.1.test `sg/impls`/I1Clone# implementation
101103

104+
//⌄ enclosing_range_start 0.1.test `sg/impls`/T2#F1().
102105
func (r T2) F1() {}
103106
// ^ definition local 1
104107
// ^^ reference 0.1.test `sg/impls`/T2#
@@ -109,6 +112,8 @@
109112
// > ```
110113
// relationship 0.1.test `sg/impls`/I1#F1. implementation
111114
// relationship 0.1.test `sg/impls`/I1Clone#F1. implementation
115+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T2#F1().
116+
//⌄ enclosing_range_start 0.1.test `sg/impls`/T2#F2().
112117
func (r T2) F2() {}
113118
// ^ definition local 2
114119
// ^^ reference 0.1.test `sg/impls`/T2#
@@ -117,4 +122,5 @@
117122
// > ```go
118123
// > func (T2).F2()
119124
// > ```
125+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/T2#F2().
120126

internal/testdata/snapshots/output/impls/remote_impls.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import "net/http"
55
// ^^^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/
66

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

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

34+
//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#Header().
3235
func (w MyWriter) Header() http.Header { panic("") }
3336
// ^ definition local 1
3437
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
@@ -40,6 +43,8 @@
4043
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#Header. implementation
4144
// ^^^^ reference github.com/golang/go/src go1.22 `net/http`/
4245
// ^^^^^^ reference github.com/golang/go/src go1.22 `net/http`/Header#
46+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#Header().
47+
//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#Write().
4348
func (w MyWriter) Write([]byte) (int, error) { panic("") }
4449
// ^ definition local 2
4550
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
@@ -52,6 +57,8 @@
5257
// relationship github.com/golang/go/src go1.22 `internal/bisect`/Writer#Write. implementation
5358
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#Write. implementation
5459
// relationship github.com/golang/go/src go1.22 io/Writer#Write. implementation
60+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#Write().
61+
//⌄ enclosing_range_start 0.1.test `sg/impls`/MyWriter#WriteHeader().
5562
func (w MyWriter) WriteHeader(statusCode int) { panic("") }
5663
// ^ definition local 3
5764
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
@@ -62,7 +69,9 @@
6269
// > ```
6370
// relationship github.com/golang/go/src go1.22 `net/http`/ResponseWriter#WriteHeader. implementation
6471
// ^^^^^^^^^^ definition local 4
72+
// ⌃ enclosing_range_end 0.1.test `sg/impls`/MyWriter#WriteHeader().
6573

74+
//⌄ enclosing_range_start 0.1.test `sg/impls`/Another().
6675
func Another() {
6776
// ^^^^^^^ definition 0.1.test `sg/impls`/Another().
6877
// documentation
@@ -73,4 +82,5 @@
7382
// ^^^^^^^^^ reference 0.1.test `sg/impls`/Something().
7483
// ^^^^^^^^ reference 0.1.test `sg/impls`/MyWriter#
7584
}
85+
//⌃ enclosing_range_end 0.1.test `sg/impls`/Another().
7686

0 commit comments

Comments
 (0)