| 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package imports implements a Go pretty-printer (like package "go/format") |
| 6 | // that also adds or removes import statements as necessary. |
| 7 | package importsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/ // import "golang.org/x/tools/imports" |
| 8 | |
| 9 | import ( |
| 10 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 11 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 12 | |
| 13 | "golang.org/x/tools/internal/gocommandscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/gocommand`/" |
| 14 | intimpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ "golang.org/x/tools/internal/importsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/" |
| 15 | ) |
| 16 | |
| 17 | // Options specifies options for processing files. |
| 18 | type Optionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options# struct { |
| 19 | Fragmentscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#Fragment. bool // Accept fragment of a source file (no package statement) |
| 20 | AllErrorsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#AllErrors. bool // Report all errors (not just the first 10 on different lines) |
| 21 | |
| 22 | Commentsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#Comments. bool // Print comments (true if nil *Options provided) |
| 23 | TabIndentscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabIndent. bool // Use tabs for indent (true if nil *Options provided) |
| 24 | TabWidthscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabWidth. int // Tab width (8 if nil *Options provided) |
| 25 | |
| 26 | FormatOnlyscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#FormatOnly. bool // Disable the insertion and deletion of imports |
| 27 | } |
| 28 | |
| 29 | // Debug controls verbose logging. |
| 30 | var Debugscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Debug. = false |
| 31 | |
| 32 | // LocalPrefix is a comma-separated string of import path prefixes, which, if |
| 33 | // set, instructs Process to sort the import paths with the given prefixes |
| 34 | // into another group after 3rd-party packages. |
| 35 | var LocalPrefixscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/LocalPrefix. string |
| 36 | |
| 37 | // Process formats and adjusts imports for the provided file. |
| 38 | // If opt is nil the defaults are used, and if src is nil the source |
| 39 | // is read from the filesystem. |
| 40 | // |
| 41 | // Note that filename's directory influences which imports can be chosen, |
| 42 | // so it is important that filename be accurate. |
| 43 | // To process data “as if” it were in filename, pass the data as a non-nil src. |
| 44 | func Processscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Process().(filename string, src []byte, opt *Optionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#) ([]byte, error) { |
| 45 | var err error |
| 46 | if src == nil { |
| 47 | src, err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(filename) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | } |
| 52 | if opt == nil { |
| 53 | opt = &Optionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#{Commentsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#Comments.: true, TabIndentscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabIndent.: true, TabWidthscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabWidth.: 8} |
| 54 | } |
| 55 | intopt := &intimpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/.Optionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#{ |
| 56 | Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#Env.: &intimpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/.ProcessEnvscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ProcessEnv#{ |
| 57 | GocmdRunnerscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ProcessEnv#GocmdRunner.: &gocommandscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/gocommand`/.Runnerscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/gocommand`/Runner#{}, |
| 58 | }, |
| 59 | LocalPrefixscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#LocalPrefix.: LocalPrefixscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/LocalPrefix., |
| 60 | AllErrorsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#AllErrors.: opt.AllErrorsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#AllErrors., |
| 61 | Commentsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#Comments.: opt.Commentsscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#Comments., |
| 62 | FormatOnlyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#FormatOnly.: opt.FormatOnlyscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#FormatOnly., |
| 63 | Fragmentscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#Fragment.: opt.Fragmentscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#Fragment., |
| 64 | TabIndentscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#TabIndent.: opt.TabIndentscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabIndent., |
| 65 | TabWidthscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#TabWidth.: opt.TabWidthscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Options#TabWidth., |
| 66 | } |
| 67 | if Debugscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/Debug. { |
| 68 | intopt.Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Options#Env..Logfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ProcessEnv#Logf. = logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf(). |
| 69 | } |
| 70 | return intimpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/.Processscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Process().(filename, src, intopt) |
| 71 | } |
| 72 | |
| 73 | // VendorlessPath returns the devendorized version of the import path ipath. |
| 74 | // For example, VendorlessPath("foo/barbendor/a/b") return "a/b". |
| 75 | func VendorlessPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/imports`/VendorlessPath().(ipath string) string { |
| 76 | return intimpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/.VendorlessPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/VendorlessPath().(ipath) |
| 77 | } |