internal/lsp: use new go/packages LoadMode to get TypesSizes
This change also fixes the corresponding code in go/packages, which was actually not filling in the TypesSizes if the bit was set. Change-Id: I2d5a849045768a81c94218eb41da2faec26189a3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/170010 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
24738cbdc1
commit
73054e8977
|
@ -554,6 +554,9 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
|
||||||
if lpkg.needsrc {
|
if lpkg.needsrc {
|
||||||
srcPkgs = append(srcPkgs, lpkg)
|
srcPkgs = append(srcPkgs, lpkg)
|
||||||
}
|
}
|
||||||
|
if ld.Mode&NeedTypesSizes != 0 {
|
||||||
|
lpkg.TypesSizes = ld.sizes
|
||||||
|
}
|
||||||
stack = stack[:len(stack)-1] // pop
|
stack = stack[:len(stack)-1] // pop
|
||||||
lpkg.color = black
|
lpkg.color = black
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (v *View) cachePackage(pkg *Package) {
|
||||||
func (v *View) checkMetadata(ctx context.Context, f *File) ([]packages.Error, error) {
|
func (v *View) checkMetadata(ctx context.Context, f *File) ([]packages.Error, error) {
|
||||||
if v.reparseImports(ctx, f, f.filename) {
|
if v.reparseImports(ctx, f, f.filename) {
|
||||||
cfg := v.Config
|
cfg := v.Config
|
||||||
cfg.Mode = packages.LoadImports
|
cfg.Mode = packages.LoadImports | packages.NeedTypesSizes
|
||||||
pkgs, err := packages.Load(&cfg, fmt.Sprintf("file=%s", f.filename))
|
pkgs, err := packages.Load(&cfg, fmt.Sprintf("file=%s", f.filename))
|
||||||
if len(pkgs) == 0 {
|
if len(pkgs) == 0 {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -141,6 +141,7 @@ func (v *View) link(pkgPath string, pkg *packages.Package, parent *metadata) *me
|
||||||
m = &metadata{
|
m = &metadata{
|
||||||
pkgPath: pkgPath,
|
pkgPath: pkgPath,
|
||||||
id: pkg.ID,
|
id: pkg.ID,
|
||||||
|
typesSizes: pkg.TypesSizes,
|
||||||
parents: make(map[string]bool),
|
parents: make(map[string]bool),
|
||||||
children: make(map[string]bool),
|
children: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
@ -230,6 +231,7 @@ func (imp *importer) typeCheck(pkgPath string) (*Package, error) {
|
||||||
files: meta.files,
|
files: meta.files,
|
||||||
imports: make(map[string]*Package),
|
imports: make(map[string]*Package),
|
||||||
types: typ,
|
types: typ,
|
||||||
|
typesSizes: meta.typesSizes,
|
||||||
typesInfo: &types.Info{
|
typesInfo: &types.Info{
|
||||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
Types: make(map[ast.Expr]types.TypeAndValue),
|
||||||
Defs: make(map[*ast.Ident]types.Object),
|
Defs: make(map[*ast.Ident]types.Object),
|
||||||
|
|
|
@ -21,6 +21,7 @@ type Package struct {
|
||||||
imports map[string]*Package
|
imports map[string]*Package
|
||||||
types *types.Package
|
types *types.Package
|
||||||
typesInfo *types.Info
|
typesInfo *types.Info
|
||||||
|
typesSizes types.Sizes
|
||||||
|
|
||||||
// The analysis cache holds analysis information for all the packages in a view.
|
// The analysis cache holds analysis information for all the packages in a view.
|
||||||
// Each graph node (action) is one unit of analysis.
|
// Each graph node (action) is one unit of analysis.
|
||||||
|
@ -118,6 +119,10 @@ func (pkg *Package) GetTypesInfo() *types.Info {
|
||||||
return pkg.typesInfo
|
return pkg.typesInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pkg *Package) GetTypesSizes() types.Sizes {
|
||||||
|
return pkg.typesSizes
|
||||||
|
}
|
||||||
|
|
||||||
func (pkg *Package) IsIllTyped() bool {
|
func (pkg *Package) IsIllTyped() bool {
|
||||||
return pkg.types == nil && pkg.typesInfo == nil
|
return pkg.types == nil && pkg.typesInfo == nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package cache
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"go/types"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ type metadataCache struct {
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
id, pkgPath, name string
|
id, pkgPath, name string
|
||||||
files []string
|
files []string
|
||||||
|
typesSizes types.Sizes
|
||||||
parents, children map[string]bool
|
parents, children map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,8 +138,7 @@ func (act *Action) execOnce(fset *token.FileSet) {
|
||||||
Files: act.Pkg.GetSyntax(),
|
Files: act.Pkg.GetSyntax(),
|
||||||
Pkg: act.Pkg.GetTypes(),
|
Pkg: act.Pkg.GetTypes(),
|
||||||
TypesInfo: act.Pkg.GetTypesInfo(),
|
TypesInfo: act.Pkg.GetTypesInfo(),
|
||||||
// TODO(rstambler): Get real TypeSizes from go/packages (golang.org/issues/30139).
|
TypesSizes: act.Pkg.GetTypesSizes(),
|
||||||
TypesSizes: &types.StdSizes{},
|
|
||||||
ResultOf: inputs,
|
ResultOf: inputs,
|
||||||
Report: func(d analysis.Diagnostic) { act.diagnostics = append(act.diagnostics, d) },
|
Report: func(d analysis.Diagnostic) { act.diagnostics = append(act.diagnostics, d) },
|
||||||
ImportObjectFact: act.importObjectFact,
|
ImportObjectFact: act.importObjectFact,
|
||||||
|
|
|
@ -45,6 +45,7 @@ type Package interface {
|
||||||
GetErrors() []packages.Error
|
GetErrors() []packages.Error
|
||||||
GetTypes() *types.Package
|
GetTypes() *types.Package
|
||||||
GetTypesInfo() *types.Info
|
GetTypesInfo() *types.Info
|
||||||
|
GetTypesSizes() types.Sizes
|
||||||
IsIllTyped() bool
|
IsIllTyped() bool
|
||||||
GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error)
|
GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue