mirror of
https://github.com/golang/go
synced 2024-10-01 05:28:33 -06:00
internal/lsp/source: always use default goimports options
No point in constructing the defaults in three places. Change-Id: I2b0776910a933a7250245bd82dc27e63c34df18a Reviewed-on: https://go-review.googlesource.com/c/tools/+/212632 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
50c778fb86
commit
0a57c09236
14
internal/lsp/cache/view.go
vendored
14
internal/lsp/cache/view.go
vendored
@ -171,7 +171,7 @@ func (v *view) Config(ctx context.Context) *packages.Config {
|
||||
}
|
||||
}
|
||||
|
||||
func (v *view) RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error, opts *imports.Options) error {
|
||||
func (v *view) RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error) error {
|
||||
v.mu.Lock()
|
||||
defer v.mu.Unlock()
|
||||
if v.processEnv == nil {
|
||||
@ -187,7 +187,17 @@ func (v *view) RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options)
|
||||
}
|
||||
|
||||
// Run the user function.
|
||||
opts.Env = v.processEnv
|
||||
opts := &imports.Options{
|
||||
// Defaults.
|
||||
AllErrors: true,
|
||||
Comments: true,
|
||||
Fragment: true,
|
||||
FormatOnly: false,
|
||||
TabIndent: true,
|
||||
TabWidth: 8,
|
||||
Env: v.processEnv,
|
||||
}
|
||||
|
||||
if err := fn(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -98,19 +98,10 @@ func AllImportsFixes(ctx context.Context, snapshot Snapshot, fh FileHandle) (all
|
||||
if hasListErrors(pkg) {
|
||||
return nil, nil, errors.Errorf("%s has list errors, not running goimports", fh.Identity().URI)
|
||||
}
|
||||
options := &imports.Options{
|
||||
// Defaults.
|
||||
AllErrors: true,
|
||||
Comments: true,
|
||||
Fragment: true,
|
||||
FormatOnly: false,
|
||||
TabIndent: true,
|
||||
TabWidth: 8,
|
||||
}
|
||||
err = snapshot.View().RunProcessEnvFunc(ctx, func(opts *imports.Options) error {
|
||||
allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot.View(), pgh, opts)
|
||||
return err
|
||||
}, options)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, errors.Errorf("computing fix edits: %v", err)
|
||||
}
|
||||
@ -317,23 +308,13 @@ func CandidateImports(ctx context.Context, prefix string, view View, filename st
|
||||
ctx, done := trace.StartSpan(ctx, "source.CandidateImports")
|
||||
defer done()
|
||||
|
||||
options := &imports.Options{
|
||||
// Defaults.
|
||||
AllErrors: true,
|
||||
Comments: true,
|
||||
Fragment: true,
|
||||
FormatOnly: false,
|
||||
TabIndent: true,
|
||||
TabWidth: 8,
|
||||
}
|
||||
|
||||
var imps []imports.ImportFix
|
||||
importFn := func(opts *imports.Options) error {
|
||||
var err error
|
||||
imps, err = imports.GetAllCandidates(ctx, prefix, filename, opts)
|
||||
return err
|
||||
}
|
||||
err := view.RunProcessEnvFunc(ctx, importFn, options)
|
||||
err := view.RunProcessEnvFunc(ctx, importFn)
|
||||
return imps, err
|
||||
}
|
||||
|
||||
@ -343,23 +324,13 @@ func PackageExports(ctx context.Context, view View, pkg, filename string) ([]imp
|
||||
ctx, done := trace.StartSpan(ctx, "source.PackageExports")
|
||||
defer done()
|
||||
|
||||
options := &imports.Options{
|
||||
// Defaults.
|
||||
AllErrors: true,
|
||||
Comments: true,
|
||||
Fragment: true,
|
||||
FormatOnly: false,
|
||||
TabIndent: true,
|
||||
TabWidth: 8,
|
||||
}
|
||||
|
||||
var pkgs []imports.PackageExport
|
||||
importFn := func(opts *imports.Options) error {
|
||||
var err error
|
||||
pkgs, err = imports.GetPackageExports(ctx, pkg, filename, opts)
|
||||
return err
|
||||
}
|
||||
err := view.RunProcessEnvFunc(ctx, importFn, options)
|
||||
err := view.RunProcessEnvFunc(ctx, importFn)
|
||||
return pkgs, err
|
||||
}
|
||||
|
||||
|
@ -110,9 +110,9 @@ type View interface {
|
||||
// Config returns the configuration for the view.
|
||||
Config(ctx context.Context) *packages.Config
|
||||
|
||||
// RunProcessEnvFunc runs fn with the process env for this view inserted into opts.
|
||||
// RunProcessEnvFunc runs fn with the process env for this view.
|
||||
// Note: the process env contains cached module and filesystem state.
|
||||
RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error, opts *imports.Options) error
|
||||
RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error) error
|
||||
|
||||
// Options returns a copy of the Options for this view.
|
||||
Options() Options
|
||||
|
Loading…
Reference in New Issue
Block a user