1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:04:41 -07:00

internal/lsp/source: start import diffs at byte 0

I assumed that f.Pos() would be the first byte of the file, but it's the
position of the package declaration. This kills the file. Just use 0.

Fixes golang/go#35458.

Change-Id: Ic77c93344c71435ef8e5624c2f2defb619139a15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206145
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Heschi Kreinick 2019-11-08 13:43:54 -05:00
parent 46f5a7f28b
commit 7d206e10da
4 changed files with 38 additions and 2 deletions

View File

@ -277,7 +277,7 @@ func trimToFirstNonImport(fset *token.FileSet, f *ast.File, src []byte) []byte {
if firstDecl != nil {
end = fset.File(f.Pos()).LineStart(fset.Position(firstDecl.Pos()).Line - 1)
}
return src[fset.Position(f.Pos()).Offset:fset.Position(end).Offset]
return src[0:fset.Position(end).Offset]
}
// CandidateImports returns every import that could be added to filename.

View File

@ -0,0 +1,14 @@
-- goimports --
package imports //@import("package")
func _() {
println("Hello, world!")
}

View File

@ -0,0 +1,22 @@
package imports //@import("package")
func _() {
println("Hello, world!")
}

View File

@ -9,7 +9,7 @@ CaseSensitiveCompletionsCount = 4
DiagnosticsCount = 22
FoldingRangesCount = 2
FormatCount = 6
ImportCount = 6
ImportCount = 7
SuggestedFixCount = 1
DefinitionsCount = 38
TypeDefinitionsCount = 2