Skip to content
Open
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
19 changes: 13 additions & 6 deletions gop/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ type Config = packages.Config
type Package struct {
packages.Package

// GopMod is the gop packages module or nil
GopMod *gopmod.Module

// GopFiles lists the absolute file paths of the package's Go source files.
// It may include files that should not be compiled, for example because
// they contain non-matching build tags, are documentary pseudo-files such as
Expand Down Expand Up @@ -392,25 +395,30 @@ func addGopFiles(ret *Package, ld *loader, dir string, mode LoadMode, test bool)
fsetTemp := token.NewFileSet()
pkgName := ret.Name
var mod *gopmod.Module
var once sync.Once
if ld != nil {
mod = ld.Context.LoadMod(ret.Module)
} else {
mod, _ = gop.LoadMod(dir)
}
ret.GopMod = mod

for _, e := range entries {
fname := e.Name()
if strings.HasPrefix(fname, "_") {
continue
}
fext := path.Ext(fname)
if goputil.FileKind(fext) == goputil.FileUnknown {
continue
if mod == nil || !mod.IsClass(fext) {
continue
}
}
if !test {
if strings.HasSuffix(fname[:len(fname)-len(fext)], "_test") {
continue
}
// check gox class test
if strings.HasSuffix(fname, "test.gox") {
once.Do(func() {
mod, _ = gop.LoadMod(dir)
})
if mod != nil {
if _, ok := mod.ClassKind(fname); ok {
continue
Expand All @@ -428,7 +436,6 @@ func addGopFiles(ret *Package, ld *loader, dir string, mode LoadMode, test bool)
}
if ld != nil && len(ret.CompiledGopFiles) > 0 {
ctx := ld.Context
mod := ctx.LoadMod(ret.Module)
ret.GopSyntax = ld.parseFiles(ret, mod, ret.CompiledGopFiles)
if mode&(NeedTypes|NeedTypesInfo) != 0 {
ret.GopTypesInfo = &typesutil.Info{
Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/lsp/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@ func buildMetadata(updates map[PackageID]*source.Metadata, pkg *packages.Package
DepsErrors: packagesinternal.GetDepsErrors(pkg),
Standalone: standalone,
}
if len(pkg.GopFiles) > 0 {
m.LoadGopMod()
}

m.LoadGopMod(pkg.GopMod)

updates[id] = m

Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/lsp/source/view_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (pgf *ParsedGopFile) PosLocation(start, end token.Pos) (protocol.Location,
return pgf.Mapper.PosLocation(pgf.Tok, start, end)
}

func (m *Metadata) LoadGopMod() {
m.gopMod_, _ = gop.LoadMod(m.LoadDir)
func (m *Metadata) LoadGopMod(mod *gopmod.Module) {
m.gopMod_ = mod
}

func (m *Metadata) GopMod_() *gopmod.Module {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.