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:
parent
46f5a7f28b
commit
7d206e10da
@ -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.
|
||||
|
14
internal/lsp/testdata/imports/issue35458.go.golden
vendored
Normal file
14
internal/lsp/testdata/imports/issue35458.go.golden
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
-- goimports --
|
||||
package imports //@import("package")
|
||||
|
||||
func _() {
|
||||
println("Hello, world!")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
22
internal/lsp/testdata/imports/issue35458.go.in
vendored
Normal file
22
internal/lsp/testdata/imports/issue35458.go.in
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
package imports //@import("package")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func _() {
|
||||
println("Hello, world!")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
internal/lsp/testdata/summary.txt.golden
vendored
2
internal/lsp/testdata/summary.txt.golden
vendored
@ -9,7 +9,7 @@ CaseSensitiveCompletionsCount = 4
|
||||
DiagnosticsCount = 22
|
||||
FoldingRangesCount = 2
|
||||
FormatCount = 6
|
||||
ImportCount = 6
|
||||
ImportCount = 7
|
||||
SuggestedFixCount = 1
|
||||
DefinitionsCount = 38
|
||||
TypeDefinitionsCount = 2
|
||||
|
Loading…
Reference in New Issue
Block a user