go/parser: deprecate parser.ParseDir

Fixes #71122

Change-Id: Icaf27842f4a42e11eea4bd2203eba5d56610c196
Reviewed-on: https://go-review.googlesource.com/c/go/+/649275
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
qiulaidongfeng 2025-02-14 01:07:54 +08:00 committed by Gopher Robot
parent 3f46587fe0
commit abd0239113
3 changed files with 7 additions and 0 deletions

1
api/next/71122.txt Normal file
View File

@ -0,0 +1 @@
pkg go/parser, func ParseDir //deprecated #71122

View File

@ -0,0 +1 @@
The [ParseDir] function is deprecated.

View File

@ -145,6 +145,11 @@ func ParseFile(fset *token.FileSet, filename string, src any, mode Mode) (f *ast
// If the directory couldn't be read, a nil map and the respective error are
// returned. If a parse error occurred, a non-nil but incomplete map and the
// first error encountered are returned.
//
// Deprecated: ParseDir does not consider build tags when associating
// files with packages. For precise information about the relationship
// between packages and files, use golang.org/x/tools/go/packages,
// which can also optionally parse and type-check the files too.
func ParseDir(fset *token.FileSet, path string, filter func(fs.FileInfo) bool, mode Mode) (pkgs map[string]*ast.Package, first error) {
list, err := os.ReadDir(path)
if err != nil {