1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:58:34 -06:00

internal/lsp: do not format the file on import organization

Updates golang/go#30843
Updates golang/go#35114

Change-Id: Id3f66d20b1ada9e53298b2370214b23b87bb0680
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204557
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-10-31 14:29:49 -04:00
parent d229a6140f
commit 075a17623f
3 changed files with 10 additions and 9 deletions

View File

@ -18,7 +18,6 @@ import (
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/lsp/telemetry"
"golang.org/x/tools/internal/span"
"golang.org/x/tools/internal/telemetry/log"
"golang.org/x/tools/internal/telemetry/trace"
"golang.org/x/tools/internal/xcontext"
errors "golang.org/x/xerrors"
@ -320,13 +319,11 @@ func (s *session) openOverlay(ctx context.Context, uri span.URI, kind source.Fil
hash: hashContents(data),
unchanged: true,
}
_, hash, err := s.cache.GetFile(uri, kind).Read(ctx)
if err != nil {
log.Error(ctx, "failed to read", err, telemetry.File)
return
}
if hash == s.overlays[uri].hash {
s.overlays[uri].sameContentOnDisk = true
// If the file is on disk, check if its content is the same as the overlay.
if _, hash, err := s.cache.GetFile(uri, kind).Read(ctx); err == nil {
if hash == s.overlays[uri].hash {
s.overlays[uri].sameContentOnDisk = true
}
}
}

View File

@ -197,6 +197,10 @@ func AllImportsFixes(ctx context.Context, view View, f File) (edits []protocol.T
if err != nil {
return err
}
// Do not change the file if there are no import fixes.
if len(fixes) == 0 {
return nil
}
// Apply all of the import fixes to the file.
formatted, err := imports.ApplyFixes(fixes, f.URI().Filename(), data, options)
if err != nil {

View File

@ -4,4 +4,4 @@ import "fmt"
func _() {
fmt.Println("")
}
}