internal/lsp/source: fix crash on conflict markers in imports
Generally speaking, if the imports package can operate on a file, we can
assume that it's in good enough shape for the rest of our work. That
means it's important we run imports first. On one code path, we weren't.
Fixes golang/go#36162.
Change-Id: I750aff31e0c3706aeb798ceb60c35ea17ba95943
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211580
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index 35b7981..3a846bf 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -132,13 +132,13 @@
if err != nil {
return nil, nil, err
}
- origImports, origImportOffset := trimToImports(view.Session().Cache().FileSet(), origAST, origData)
allFixes, err := imports.FixImports(filename, origData, options)
if err != nil {
return nil, nil, err
}
+ origImports, origImportOffset := trimToImports(view.Session().Cache().FileSet(), origAST, origData)
allFixEdits, err = computeFixEdits(view, ph, options, origData, origAST, origMapper, origImports, origImportOffset, allFixes)
if err != nil {
return nil, nil, err