Skip to content

Commit 7d206e1

Browse files
committed
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 #35458. Change-Id: Ic77c93344c71435ef8e5624c2f2defb619139a15 Reviewed-on: https://go-review.googlesource.com/c/tools/+/206145 Run-TryBot: Heschi Kreinick <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 46f5a7f commit 7d206e1

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

internal/lsp/source/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func trimToFirstNonImport(fset *token.FileSet, f *ast.File, src []byte) []byte {
277277
if firstDecl != nil {
278278
end = fset.File(f.Pos()).LineStart(fset.Position(firstDecl.Pos()).Line - 1)
279279
}
280-
return src[fset.Position(f.Pos()).Offset:fset.Position(end).Offset]
280+
return src[0:fset.Position(end).Offset]
281281
}
282282

283283
// CandidateImports returns every import that could be added to filename.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- goimports --
2+
package imports //@import("package")
3+
4+
func _() {
5+
println("Hello, world!")
6+
}
7+
8+
9+
10+
11+
12+
13+
14+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
4+
5+
6+
package imports //@import("package")
7+
8+
9+
10+
11+
12+
13+
func _() {
14+
println("Hello, world!")
15+
}
16+
17+
18+
19+
20+
21+
22+

internal/lsp/testdata/summary.txt.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CaseSensitiveCompletionsCount = 4
99
DiagnosticsCount = 22
1010
FoldingRangesCount = 2
1111
FormatCount = 6
12-
ImportCount = 6
12+
ImportCount = 7
1313
SuggestedFixCount = 1
1414
DefinitionsCount = 38
1515
TypeDefinitionsCount = 2

0 commit comments

Comments
 (0)