doc.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package loader defines helpers for loading packages from sources. It wraps
  14. // go/packages, allow incremental loading of source code and manual control
  15. // over which packages get type-checked. This allows for faster loading in
  16. // cases where you don't actually care about certain imports.
  17. //
  18. // Because it uses go/packages, it's modules-aware, and works in both modules-
  19. // and non-modules environments.
  20. //
  21. // # Loading
  22. //
  23. // The main entrypoint for loading is LoadRoots, which traverse the package
  24. // graph starting at the given patterns (file, package, path, or ...-wildcard,
  25. // as one might pass to go list). Packages beyond the roots can be accessed
  26. // via the Imports() method. Packages are initially loaded with export data
  27. // paths, filenames, and imports.
  28. //
  29. // Packages are suitable for comparison, as each unique package only ever has
  30. // one *Package object returned.
  31. //
  32. // # Syntax and TypeChecking
  33. //
  34. // ASTs and type-checking information can be loaded with NeedSyntax and
  35. // NeedTypesInfo, respectively. Both are idempotent -- repeated calls will
  36. // simply re-use the cached contents. Note that NeedTypesInfo will *only* type
  37. // check the current package -- if you want to type-check imports as well,
  38. // you'll need to type-check them first.
  39. //
  40. // # Reference Pruning and Recursive Checking
  41. //
  42. // In order to type-check using only the packages you care about, you can use a
  43. // TypeChecker. TypeChecker will visit each top-level type declaration,
  44. // collect (optionally filtered) references, and type-check references
  45. // packages.
  46. //
  47. // # Errors
  48. //
  49. // Errors can be added to each package. Use ErrFromNode to create an error
  50. // from an AST node. Errors can then be printed (complete with file and
  51. // position information) using PrintErrors, optionally filtered by error type.
  52. // It's generally a good idea to filter out TypeErrors when doing incomplete
  53. // type-checking with TypeChecker. You can use MaybeErrList to return multiple
  54. // errors if you need to return an error instead of adding it to a package.
  55. // AddError will later unroll it into individual errors.
  56. package loader