From 0983143fce7e4438d2aeb2c8ba8bc405f95efb5d Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Tue, 10 Mar 2020 14:21:51 -0700 Subject: [PATCH] internal/lsp/source: avoid type checking in AllImportsFixes Change AllImportsFixes to get the ParseGoHandle directly rather than using getParsedFile. The latter also type checks the containing package, which is slow in general and can be really slow in certain circumstances. This should speed up the organizeImports code action. Change-Id: Ic505873db41d5d76c398cee42f0323e390d9e034 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222780 Run-TryBot: Muir Manders TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/source/format.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go index d8efad05de..e1c2c5ed73 100644 --- a/internal/lsp/source/format.go +++ b/internal/lsp/source/format.go @@ -80,10 +80,7 @@ func AllImportsFixes(ctx context.Context, snapshot Snapshot, fh FileHandle) (all ctx, done := trace.StartSpan(ctx, "source.AllImportsFixes") defer done() - _, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestPackageHandle) - if err != nil { - return nil, nil, errors.Errorf("getting file for AllImportsFixes: %v", err) - } + pgh := snapshot.View().Session().Cache().ParseGoHandle(fh, ParseFull) err = snapshot.View().RunProcessEnvFunc(ctx, func(opts *imports.Options) error { allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot.View(), pgh, opts) return err