Skip to content

Commit 47f46e0

Browse files
committed
gop/packages: support load gop mod for add classfile
1 parent 8d8a3aa commit 47f46e0

11 files changed

Lines changed: 84 additions & 68 deletions

File tree

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ module golang.org/x/tools
33
go 1.18 // tagx:compat 1.16
44

55
require (
6-
github.com/goplus/gop v1.2.5
7-
github.com/goplus/mod v0.13.9
6+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da
7+
github.com/goplus/mod v0.13.10
88
github.com/yuin/goldmark v1.4.13
9-
golang.org/x/mod v0.16.0
9+
golang.org/x/mod v0.17.0
1010
golang.org/x/net v0.22.0
1111
golang.org/x/sync v0.6.0
1212
golang.org/x/sys v0.18.0
1313
)
1414

1515
require (
16-
github.com/goplus/gogen v1.15.1 // indirect
17-
github.com/qiniu/x v1.13.9 // indirect
16+
github.com/goplus/gogen v1.15.2 // indirect
17+
github.com/qiniu/x v1.13.10 // indirect
1818
)

go.sum

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
github.com/goplus/gogen v1.15.1 h1:iz/fFpOeldjwmnjLzEdNsZF2mCf+sOHJavbAvV3o7sY=
2-
github.com/goplus/gogen v1.15.1/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
3-
github.com/goplus/gop v1.2.5 h1:kBCcvJ7ONt3IqTUTNGb+n9JO1nwTp5STg1UUSEfvz/k=
4-
github.com/goplus/gop v1.2.5/go.mod h1:5rLlryvlZhWLIBw1Rok8s0uvyO54vcYw/7sFLhqtNTc=
5-
github.com/goplus/mod v0.13.9 h1:B9zZoHi2AzMltTSOFqZNVjqGlSMlhhNTWwEzVqhTQzg=
6-
github.com/goplus/mod v0.13.9/go.mod h1:MibsLSftGmxaQq78YzUzNviyFwB9RtpMaoscufvEKH4=
7-
github.com/qiniu/x v1.13.9 h1:OUcQZSze1oTO5pzrhsepTUvEb9K9WtOiqZomWffFGWE=
8-
github.com/qiniu/x v1.13.9/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
1+
github.com/goplus/gogen v1.15.2 h1:Q6XaSx/Zi5tWnjfAziYsQI6Jv6MgODRpFtOYqNkiiqM=
2+
github.com/goplus/gogen v1.15.2/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
3+
github.com/goplus/gop v1.2.0-pre.1.0.20240413142707-f07725aeb257 h1:Zb62NO0mHj7kEIRD4geBbplHB8UtQNZmXyXzLtNv+bA=
4+
github.com/goplus/gop v1.2.0-pre.1.0.20240413142707-f07725aeb257/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
5+
github.com/goplus/gop v1.2.0-pre.1.0.20240415141958-7e9fba5161f5 h1:H2lFjyjo1iduWFr2hT3v4rIuZTynQpQV6DrXGGc5jiQ=
6+
github.com/goplus/gop v1.2.0-pre.1.0.20240415141958-7e9fba5161f5/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
7+
github.com/goplus/gop v1.2.0-pre.1.0.20240418023908-721378627ab2 h1:pBj7YAn04gUVo9cJReg+sjiT44i6+SeTpvdXNxPUYOY=
8+
github.com/goplus/gop v1.2.0-pre.1.0.20240418023908-721378627ab2/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
9+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da h1:CFAUqjOIYVdGm7J5IPo1AZWIu7iyEpvcux7KIscoWrY=
10+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
11+
github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE=
12+
github.com/goplus/mod v0.13.10/go.mod h1:HDuPZgpWiaTp3PUolFgsiX+Q77cbUWB/mikVHfYND3c=
13+
github.com/qiniu/x v1.13.10 h1:J4Z3XugYzAq85SlyAfqlKVrbf05glMbAOh+QncsDQpE=
14+
github.com/qiniu/x v1.13.10/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
915
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
1016
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
1117
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -14,8 +20,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
1420
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
1521
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
1622
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
17-
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
18-
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
23+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
24+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
1925
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
2026
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
2127
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=

gop/packages/packages.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ type Config = packages.Config
150150
type Package struct {
151151
packages.Package
152152

153+
// GopMod is the gop packages module or nil
154+
GopMod *gopmod.Module
155+
153156
// GopFiles lists the absolute file paths of the package's Go source files.
154157
// It may include files that should not be compiled, for example because
155158
// they contain non-matching build tags, are documentary pseudo-files such as
@@ -392,25 +395,30 @@ func addGopFiles(ret *Package, ld *loader, dir string, mode LoadMode, test bool)
392395
fsetTemp := token.NewFileSet()
393396
pkgName := ret.Name
394397
var mod *gopmod.Module
395-
var once sync.Once
398+
if ld != nil {
399+
mod = ld.Context.LoadMod(ret.Module)
400+
} else {
401+
mod, _ = gop.LoadMod(dir)
402+
}
403+
ret.GopMod = mod
404+
396405
for _, e := range entries {
397406
fname := e.Name()
398407
if strings.HasPrefix(fname, "_") {
399408
continue
400409
}
401410
fext := path.Ext(fname)
402411
if goputil.FileKind(fext) == goputil.FileUnknown {
403-
continue
412+
if mod == nil || !mod.IsClass(fext) {
413+
continue
414+
}
404415
}
405416
if !test {
406417
if strings.HasSuffix(fname[:len(fname)-len(fext)], "_test") {
407418
continue
408419
}
409420
// check gox class test
410421
if strings.HasSuffix(fname, "test.gox") {
411-
once.Do(func() {
412-
mod, _ = gop.LoadMod(dir)
413-
})
414422
if mod != nil {
415423
if _, ok := mod.ClassKind(fname); ok {
416424
continue
@@ -428,7 +436,6 @@ func addGopFiles(ret *Package, ld *loader, dir string, mode LoadMode, test bool)
428436
}
429437
if ld != nil && len(ret.CompiledGopFiles) > 0 {
430438
ctx := ld.Context
431-
mod := ctx.LoadMod(ret.Module)
432439
ret.GopSyntax = ld.parseFiles(ret, mod, ret.CompiledGopFiles)
433440
if mode&(NeedTypes|NeedTypesInfo) != 0 {
434441
ret.GopTypesInfo = &typesutil.Info{

gopls/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ go 1.18
44

55
require (
66
github.com/google/go-cmp v0.6.0
7-
github.com/goplus/gogen v1.15.1
8-
github.com/goplus/gop v1.2.5
9-
github.com/goplus/mod v0.13.9
7+
github.com/goplus/gogen v1.15.2
8+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da
9+
github.com/goplus/mod v0.13.10
1010
github.com/jba/printsrc v0.2.2
1111
github.com/jba/templatecheck v0.7.0
12-
github.com/qiniu/x v1.13.9
12+
github.com/qiniu/x v1.13.10
1313
github.com/sergi/go-diff v1.1.0
14-
golang.org/x/mod v0.16.0
14+
golang.org/x/mod v0.17.0
1515
golang.org/x/sync v0.6.0
1616
golang.org/x/sys v0.18.0
1717
golang.org/x/text v0.14.0

gopls/go.sum

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
1111
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
1212
github.com/google/safehtml v0.1.0 h1:EwLKo8qawTKfsi0orxcQAZzu07cICaBeFMegAU9eaT8=
1313
github.com/google/safehtml v0.1.0/go.mod h1:L4KWwDsUJdECRAEpZoBn3O64bQaywRscowZjJAzjHnU=
14-
github.com/goplus/c2go v0.7.25/go.mod h1:e9oe4jDVhGFMJLEGmPSrVkLuXbLZAEmAu0/uD6fSz5E=
15-
github.com/goplus/gogen v1.15.0/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
16-
github.com/goplus/gogen v1.15.1 h1:iz/fFpOeldjwmnjLzEdNsZF2mCf+sOHJavbAvV3o7sY=
17-
github.com/goplus/gogen v1.15.1/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
18-
github.com/goplus/gop v1.2.5 h1:kBCcvJ7ONt3IqTUTNGb+n9JO1nwTp5STg1UUSEfvz/k=
19-
github.com/goplus/gop v1.2.5/go.mod h1:5rLlryvlZhWLIBw1Rok8s0uvyO54vcYw/7sFLhqtNTc=
20-
github.com/goplus/mod v0.13.9 h1:B9zZoHi2AzMltTSOFqZNVjqGlSMlhhNTWwEzVqhTQzg=
21-
github.com/goplus/mod v0.13.9/go.mod h1:MibsLSftGmxaQq78YzUzNviyFwB9RtpMaoscufvEKH4=
14+
github.com/goplus/c2go v0.7.26/go.mod h1:ePAStubV/ls8mmdPGQo6VfADTVd46rKuBemE4zzBDnA=
15+
github.com/goplus/gogen v1.15.2 h1:Q6XaSx/Zi5tWnjfAziYsQI6Jv6MgODRpFtOYqNkiiqM=
16+
github.com/goplus/gogen v1.15.2/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
17+
github.com/goplus/gop v1.2.0-pre.1.0.20240413142707-f07725aeb257 h1:Zb62NO0mHj7kEIRD4geBbplHB8UtQNZmXyXzLtNv+bA=
18+
github.com/goplus/gop v1.2.0-pre.1.0.20240413142707-f07725aeb257/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
19+
github.com/goplus/gop v1.2.0-pre.1.0.20240415141958-7e9fba5161f5 h1:H2lFjyjo1iduWFr2hT3v4rIuZTynQpQV6DrXGGc5jiQ=
20+
github.com/goplus/gop v1.2.0-pre.1.0.20240415141958-7e9fba5161f5/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
21+
github.com/goplus/gop v1.2.0-pre.1.0.20240418023908-721378627ab2 h1:pBj7YAn04gUVo9cJReg+sjiT44i6+SeTpvdXNxPUYOY=
22+
github.com/goplus/gop v1.2.0-pre.1.0.20240418023908-721378627ab2/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
23+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da h1:CFAUqjOIYVdGm7J5IPo1AZWIu7iyEpvcux7KIscoWrY=
24+
github.com/goplus/gop v1.2.0-pre.1.0.20240422032454-64a3001223da/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
25+
github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE=
26+
github.com/goplus/mod v0.13.10/go.mod h1:HDuPZgpWiaTp3PUolFgsiX+Q77cbUWB/mikVHfYND3c=
2227
github.com/jba/printsrc v0.2.2 h1:9OHK51UT+/iMAEBlQIIXW04qvKyF3/vvLuwW/hL8tDU=
2328
github.com/jba/printsrc v0.2.2/go.mod h1:1xULjw59sL0dPdWpDoVU06TIEO/Wnfv6AHRpiElTwYM=
2429
github.com/jba/templatecheck v0.7.0 h1:wjTb/VhGgSFeim5zjWVePBdaMo28X74bGLSABZV+zIA=
@@ -33,8 +38,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
3338
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
3439
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3540
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
36-
github.com/qiniu/x v1.13.9 h1:OUcQZSze1oTO5pzrhsepTUvEb9K9WtOiqZomWffFGWE=
37-
github.com/qiniu/x v1.13.9/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
41+
github.com/qiniu/x v1.13.10 h1:J4Z3XugYzAq85SlyAfqlKVrbf05glMbAOh+QncsDQpE=
42+
github.com/qiniu/x v1.13.10/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
3843
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
3944
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
4045
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
@@ -50,8 +55,8 @@ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2F
5055
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
5156
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
5257
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
53-
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
54-
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
58+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
59+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
5560
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
5661
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
5762
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=

gopls/internal/goxls/parserutil/parser_util.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
package parserutil
66

77
import (
8-
"strings"
9-
8+
"github.com/goplus/gop"
109
"github.com/goplus/gop/ast"
11-
"github.com/goplus/gop/cl"
1210
"github.com/goplus/gop/parser"
1311
"github.com/goplus/gop/token"
1412
"github.com/goplus/mod/gopmod"
@@ -50,25 +48,14 @@ func ParseFileEx(mod *gopmod.Module, fset *token.FileSet, filename string, src i
5048
return
5149
}
5250

53-
const (
54-
casePrefix = "case"
55-
)
56-
57-
func testNameSuffix(testType string) string {
58-
if c := testType[0]; c >= 'A' && c <= 'Z' {
59-
return testType
60-
}
61-
return "_" + testType
62-
}
63-
64-
// GetClassType is get class type from ast.File and filename
65-
func GetClassType(file *ast.File, filename string) (classType string, ok bool) {
66-
if file.IsClass {
67-
ok = true
68-
classType, _, _ = cl.ClassNameAndExt(filename)
69-
if strings.HasSuffix(filename, "test.gox") && !file.IsProj {
70-
classType = casePrefix + testNameSuffix(classType)
51+
func GetClassType(file *ast.File, filename string, getMod func() (*gopmod.Module, error)) (classType string, isTest bool, err error) {
52+
var mod *gopmod.Module
53+
if file.IsProj {
54+
mod, err = getMod()
55+
if err != nil {
56+
return
7157
}
7258
}
59+
classType, isTest = gop.GetFileClassType(mod, file, filename)
7360
return
7461
}

gopls/internal/lsp/cache/load.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ func buildMetadata(updates map[PackageID]*source.Metadata, pkg *packages.Package
444444
DepsErrors: packagesinternal.GetDepsErrors(pkg),
445445
Standalone: standalone,
446446
}
447-
if len(pkg.GopFiles) > 0 {
448-
m.LoadGopMod()
449-
}
447+
448+
m.LoadGopMod(pkg.GopMod)
450449

451450
updates[id] = m
452451

gopls/internal/lsp/source/completion/completion_gox.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/goplus/gop/scanner"
2525
"github.com/goplus/gop/token"
2626
"github.com/goplus/gop/x/typesutil"
27+
"github.com/goplus/mod/gopmod"
2728
"golang.org/x/sync/errgroup"
2829
"golang.org/x/tools/gop/ast/astutil"
2930
"golang.org/x/tools/gopls/internal/goxls"
@@ -1431,7 +1432,12 @@ func (c *gopCompleter) lexical(ctx context.Context) error {
14311432
// position or embedded in interface declarations).
14321433
// builtinComparable = types.Universe.Lookup("comparable")
14331434
)
1434-
classType, isClass := parserutil.GetClassType(c.file, c.filename)
1435+
classType, _, err := parserutil.GetClassType(c.file, c.filename, func() (*gopmod.Module, error) {
1436+
return c.snapshot.GopModForFile(ctx, c.fh.URI())
1437+
})
1438+
if err != nil {
1439+
return fmt.Errorf("getting classType for gopCompleter: %w", err)
1440+
}
14351441
// Track seen variables to avoid showing completions for shadowed variables.
14361442
// This works since we look at scopes from innermost to outermost.
14371443
seen := make(map[string]struct{})
@@ -1446,7 +1452,7 @@ func (c *gopCompleter) lexical(ctx context.Context) error {
14461452
for _, name := range scope.Names() {
14471453
declScope, obj := scope.LookupParent(name, c.pos)
14481454
// Go+ class
1449-
if isClass && name == classType {
1455+
if c.file.IsClass && name == classType {
14501456
c.methodsAndFields(obj.Type(), true, nil, c.deepState.enqueue)
14511457
continue
14521458
}

gopls/internal/lsp/source/signature_help_gox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func GopSignatureHelp(ctx context.Context, snapshot Snapshot, fh FileHandle, pos
3737
}
3838
var offset = int(pos - start)
3939
npos := pos
40-
if len(pgf.File.Code) >= offset {
40+
if len(pgf.File.Code) > offset {
4141
if pgf.File.Code[offset] == '\n' {
4242
offset--
4343
npos--

gopls/internal/lsp/source/symbols_gox.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/goplus/gop/ast"
1212
"github.com/goplus/gop/token"
1313
"github.com/goplus/gop/x/typesutil"
14+
"github.com/goplus/mod/gopmod"
1415
"golang.org/x/tools/gopls/internal/goxls/parserutil"
1516
"golang.org/x/tools/gopls/internal/lsp/protocol"
1617
"golang.org/x/tools/internal/event"
@@ -25,7 +26,12 @@ func GopDocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) (
2526
return nil, fmt.Errorf("getting file for GopDocumentSymbols: %w", err)
2627
}
2728
file := pgf.File
28-
classType, _ := parserutil.GetClassType(file, fh.URI().Filename())
29+
classType, _, err := parserutil.GetClassType(file, fh.URI().Filename(), func() (*gopmod.Module, error) {
30+
return snapshot.GopModForFile(ctx, fh.URI())
31+
})
32+
if err != nil {
33+
return nil, fmt.Errorf("getting classType for GopDocumentSymbols: %w", err)
34+
}
2935
// Build symbols for file declarations. When encountering a declaration with
3036
// errors (typically because positions are invalid), we skip the declaration
3137
// entirely. VS Code fails to show any symbols if one of the top-level

0 commit comments

Comments
 (0)