gopls: rm GofumptFormat from internal/settings

Since CL 612055 var GofumptFormat can never be nil, and since CL 609655
it is a very simple wrapper.

Remove it, and use mvdan.cc/gofumpt/format directly in internal/golang.

Note that this removes some documentation bits about gofumpt options, but
those are already described in internal/golang.Format inline comments.

Change-Id: Ic7d5b8412e913f2dbbc14befb978f8a4f743334a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/611844
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Kir Kolyshkin 2024-09-12 11:59:03 -07:00 коммит произвёл Gopher Robot
Родитель 198986d2dd
Коммит 91d4bdb347
2 изменённых файлов: 6 добавлений и 27 удалений

Просмотреть файл

@ -21,12 +21,12 @@ import (
"golang.org/x/tools/gopls/internal/cache/parsego"
"golang.org/x/tools/gopls/internal/file"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/diff"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/imports"
"golang.org/x/tools/internal/tokeninternal"
gofumptFormat "mvdan.cc/gofumpt/format"
)
// Format formats a file with a given range.
@ -67,7 +67,7 @@ func Format(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle) ([]pr
// Apply additional formatting, if any is supported. Currently, the only
// supported additional formatter is gofumpt.
if format := settings.GofumptFormat; snapshot.Options().Gofumpt && format != nil {
if snapshot.Options().Gofumpt {
// gofumpt can customize formatting based on language version and module
// path, if available.
//
@ -76,17 +76,17 @@ func Format(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle) ([]pr
// TODO: under which circumstances can we fail to find module information?
// Can this, for example, result in inconsistent formatting across saves,
// due to pending calls to packages.Load?
var langVersion, modulePath string
var opts gofumptFormat.Options
meta, err := NarrowestMetadataForFile(ctx, snapshot, fh.URI())
if err == nil {
if mi := meta.Module; mi != nil {
if v := mi.GoVersion; v != "" {
langVersion = "go" + v
opts.LangVersion = "go" + v
}
modulePath = mi.Path
opts.ModulePath = mi.Path
}
}
b, err := format(ctx, langVersion, modulePath, buf.Bytes())
b, err := gofumptFormat.Source(buf.Bytes(), opts)
if err != nil {
return nil, err
}

Просмотреть файл

@ -1,21 +0,0 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package settings
import (
"context"
"mvdan.cc/gofumpt/format"
)
// GofumptFormat allows the gopls module to wire in a call to
// gofumpt/format.Source. langVersion and modulePath are used for some
// Gofumpt formatting rules -- see the Gofumpt documentation for details.
var GofumptFormat = func(ctx context.Context, langVersion, modulePath string, src []byte) ([]byte, error) {
return format.Source(src, format.Options{
LangVersion: langVersion,
ModulePath: modulePath,
})
}