forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from xushiwei/q
golang.org/x/tools/go/packages => goxls/packages
- Loading branch information
Showing
18 changed files
with
282 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
// Copyright 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package packages | ||
|
||
import ( | ||
"sort" | ||
|
||
"golang.org/x/tools/go/packages" | ||
internal "golang.org/x/tools/internal/packagesinternal" | ||
|
||
"golang.org/x/tools/gopls/internal/goxls/packagesinternal" | ||
) | ||
|
||
// An Error describes a problem with a package's metadata, syntax, or types. | ||
type Error = packages.Error | ||
|
||
// ErrorKind describes the source of the error, allowing the user to | ||
// differentiate between errors generated by the driver, the parser, or the | ||
// type-checker. | ||
type ErrorKind = packages.ErrorKind | ||
|
||
const ( | ||
UnknownError = packages.UnknownError | ||
ListError = packages.ListError | ||
ParseError = packages.ParseError | ||
TypeError = packages.TypeError | ||
) | ||
|
||
// A LoadMode controls the amount of detail to return when loading. | ||
// The bits below can be combined to specify which fields should be | ||
// filled in the result packages. | ||
// The zero value is a special case, equivalent to combining | ||
// the NeedName, NeedFiles, and NeedCompiledGoFiles bits. | ||
// ID and Errors (if present) will always be filled. | ||
// Load may return more information than requested. | ||
type LoadMode = packages.LoadMode | ||
|
||
const ( | ||
// NeedName adds Name and PkgPath. | ||
NeedName = packages.NeedName | ||
|
||
// NeedFiles adds GoFiles, GopFiles and OtherFiles. | ||
NeedFiles = packages.NeedFiles | ||
|
||
// NeedCompiledGoFiles adds CompiledGoFiles/CompiledGopFiles. | ||
NeedCompiledGoFiles = packages.NeedCompiledGoFiles | ||
|
||
// NeedCompiledGopFiles adds CompiledGoFiles/CompiledGopFiles. | ||
NeedCompiledGopFiles = packages.NeedCompiledGoFiles | ||
|
||
// NeedImports adds Imports. If NeedDeps is not set, the Imports field will contain | ||
// "placeholder" Packages with only the ID set. | ||
NeedImports = packages.NeedImports | ||
|
||
// NeedDeps adds the fields requested by the LoadMode in the packages in Imports. | ||
NeedDeps = packages.NeedDeps | ||
|
||
// NeedExportFile adds ExportFile. | ||
NeedExportFile = packages.NeedExportFile | ||
|
||
// NeedTypes adds Types, Fset, and IllTyped. | ||
NeedTypes = packages.NeedTypes | ||
|
||
// NeedSyntax adds Syntax. | ||
NeedSyntax = packages.NeedSyntax | ||
|
||
// NeedTypesInfo adds TypesInfo. | ||
NeedTypesInfo = packages.NeedTypesInfo | ||
|
||
// NeedTypesSizes adds TypesSizes. | ||
NeedTypesSizes = packages.NeedTypesSizes | ||
|
||
// NeedModule adds Module. | ||
NeedModule = packages.NeedModule | ||
|
||
// NeedEmbedFiles adds EmbedFiles. | ||
NeedEmbedFiles = packages.NeedEmbedFiles | ||
|
||
// NeedEmbedPatterns adds EmbedPatterns. | ||
NeedEmbedPatterns = packages.NeedEmbedPatterns | ||
) | ||
|
||
// A Config specifies details about how packages should be loaded. | ||
// The zero value is a valid configuration. | ||
// Calls to Load do not modify this struct. | ||
type Config = packages.Config | ||
|
||
type Package = packages.Package | ||
|
||
/* | ||
// A Package describes a loaded Go+ package. | ||
type Package struct { | ||
*packages.Package | ||
// 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 | ||
// unsafe/unsafe.go or builtin/builtin.go, or are subject to cgo preprocessing. | ||
GopFiles []string | ||
// CompiledGopFiles lists the absolute file paths of the package's source | ||
// files that are suitable for type checking. | ||
// This may differ from GoFiles if files are processed before compilation. | ||
CompiledGopFiles []string | ||
// Imports maps import paths appearing in the package's Go source files | ||
// to corresponding loaded Packages. | ||
Imports map[string]*Package | ||
// TypesInfo provides type information about the package's syntax trees. | ||
// It is set only when Syntax is set. | ||
GopTypesInfo *typesutil.Info | ||
} | ||
*/ | ||
|
||
// Module provides module information for a package. | ||
type Module = packages.Module | ||
|
||
// Load loads and returns the Go packages named by the given patterns. | ||
// | ||
// Config specifies loading options; | ||
// nil behaves the same as an empty Config. | ||
// | ||
// Load returns an error if any of the patterns was invalid | ||
// as defined by the underlying build system. | ||
// It may return an empty list of packages without an error, | ||
// for instance for an empty expansion of a valid wildcard. | ||
// Errors associated with a particular package are recorded in the | ||
// corresponding Package's Errors list, and do not cause Load to | ||
// return an error. Clients may need to handle such errors before | ||
// proceeding with further analysis. The PrintErrors function is | ||
// provided for convenient display of all errors. | ||
func Load(cfg *Config, patterns ...string) ([]*Package, error) { | ||
return packages.Load(cfg, patterns...) | ||
} | ||
|
||
/* | ||
pkgs, err := packages.Load(cfg, patterns...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ret := make([]*Package, len(pkgs)) | ||
for i, pkg := range pkgs { | ||
ret[i] = &Package{Package: pkg, Imports: importPkgs(pkg.Imports)} | ||
} | ||
return ret, nil | ||
} | ||
func importPkgs(pkgs map[string]*packages.Package) map[string]*Package { | ||
if len(pkgs) == 0 { | ||
return nil | ||
} | ||
ret := make(map[string]*Package, len(pkgs)) | ||
for path, pkg := range pkgs { | ||
ret[path] = &Package{Package: pkg} | ||
} | ||
return ret | ||
} | ||
*/ | ||
|
||
// Visit visits all the packages in the import graph whose roots are | ||
// pkgs, calling the optional pre function the first time each package | ||
// is encountered (preorder), and the optional post function after a | ||
// package's dependencies have been visited (postorder). | ||
// The boolean result of pre(pkg) determines whether | ||
// the imports of package pkg are visited. | ||
func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package)) { | ||
seen := make(map[*Package]bool) | ||
var visit func(*Package) | ||
visit = func(pkg *Package) { | ||
if !seen[pkg] { | ||
seen[pkg] = true | ||
|
||
if pre == nil || pre(pkg) { | ||
paths := make([]string, 0, len(pkg.Imports)) | ||
for path := range pkg.Imports { | ||
paths = append(paths, path) | ||
} | ||
sort.Strings(paths) // Imports is a map, this makes visit stable | ||
for _, path := range paths { | ||
visit(pkg.Imports[path]) | ||
} | ||
} | ||
|
||
if post != nil { | ||
post(pkg) | ||
} | ||
} | ||
} | ||
for _, pkg := range pkgs { | ||
visit(pkg) | ||
} | ||
} | ||
|
||
func init() { | ||
packagesinternal.GetForTest = func(p interface{}) string { | ||
return internal.GetForTest(p.(*Package)) | ||
// return internal.GetForTest(p.(*Package).Package) | ||
} | ||
packagesinternal.GetDepsErrors = func(p interface{}) []*packagesinternal.PackageError { | ||
return internal.GetDepsErrors(p.(*Package)) | ||
// return internal.GetDepsErrors(p.(*Package).Package) | ||
} | ||
packagesinternal.GetGoCmdRunner = internal.GetGoCmdRunner | ||
packagesinternal.SetGoCmdRunner = internal.SetGoCmdRunner | ||
packagesinternal.SetModFile = internal.SetModFile | ||
packagesinternal.SetModFlag = internal.SetModFlag | ||
packagesinternal.TypecheckCgo = internal.TypecheckCgo | ||
packagesinternal.DepsErrors = internal.DepsErrors | ||
packagesinternal.ForTest = internal.ForTest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package packagesinternal exposes internal-only fields from goxls/packages. | ||
package packagesinternal | ||
|
||
import ( | ||
"golang.org/x/tools/internal/gocommand" | ||
"golang.org/x/tools/internal/packagesinternal" | ||
) | ||
|
||
var GetForTest = func(p interface{}) string { return "" } | ||
var GetDepsErrors = func(p interface{}) []*PackageError { return nil } | ||
|
||
type PackageError = packagesinternal.PackageError | ||
|
||
var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil } | ||
|
||
var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {} | ||
|
||
var TypecheckCgo int | ||
var DepsErrors int // must be set as a LoadMode to call GetDepsErrors | ||
var ForTest int // must be set as a LoadMode to call GetForTest | ||
|
||
var SetModFlag = func(config interface{}, value string) {} | ||
var SetModFile = func(config interface{}, value string) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.