]> Cypherpunks repositories - gostls13.git/commit
go/doc: group play example imports
authorJonathan Amsterdam <jba@google.com>
Thu, 10 Feb 2022 15:32:58 +0000 (10:32 -0500)
committerJonathan Amsterdam <jba@google.com>
Tue, 10 May 2022 14:22:16 +0000 (14:22 +0000)
commit59ef3a966b38cb2ac537d1be43f0b8fd2468ea70
tree95b4a5f1dd02363de0bc3bbab7a7bcf553eaf588
parent1ce7fcf139417d618c2730010ede2afb41664211
go/doc: group play example imports

When synthesizing a program from a playable example, preserve
the grouping of imports. That is, maintain blank lines between
imports while removing unused ones.

People are used to having those groups because that is what goimports
does.  It's disconcerting to see the all imports placed together, as
the existing code does, especially when the user has already grouped
them.

For an example, see golang/go#43658.

This is an improvement to a fix in pkgsite's fork of go/doc
(https://go.googlesource.com/pkgsite/+/7b10ef3861af4a863bf215f63b6de94c681d5af0/internal/godoc/internal/doc/example_pkgsite.go#405).
Here I've managed to avoid using a token.FileSet.

Change-Id: I65605e6dd53d742a3fe1210c3f982b54e3706198
Reviewed-on: https://go-review.googlesource.com/c/go/+/384837
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
src/go/doc/example.go
src/go/doc/example_internal_test.go [new file with mode: 0644]
src/go/doc/example_test.go