1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:18:33 -06:00

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 <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Muir Manders 2020-03-10 14:21:51 -07:00 committed by Heschi Kreinick
parent 3e041465cc
commit 0983143fce

View File

@ -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