The answer was simple: var fset token.FileSet – wrong
fset := token.NewFileSet() – right вторник, 22 октября 2019 г., 11:20:38 UTC+3 пользователь Michel Levieux написал: > > Hi Denis, > > In a project of my own I encountered the same issue. This program moves a > go project to another location, then it remembers imports (that are > necessary), exported types, functions and package-scope values (var / > const) and maps them in the original go project to the newly created one. > The original goal of this program is to move packages from other packages, > while leaving everything compatible as is. Everything almost works now but > in practice, all my code has a strange look, like function/type definitions > are all stuck with one another, with no lines in between. > > If anyone has suggestions or ideas, please let us know! > > Thanks to all of you for your time. > > Le ven. 18 oct. 2019 à 00:11, Denis Cheremisov <denis.c...@gmail.com > <javascript:>> a écrit : > >> Hi! >> >> I have a utility that parses Go files into AST , makes some changes on >> the tree (import paths) and format it back into the Go source code, in the >> original file. >> >> The problem is I am using format.Node function from this >> <https://golang.org/pkg/go/format/> package. The formatting this >> function applies to the AST is very similar to what gofmt does but it is >> not identical. >> >> Example. >> >> The original file may look like this >> >> // +build !windows >> >> package main >> >> import ( >> "<import-path>" >> ) >> >> func main() {} >> >> And the result will look like >> >> // +build !windows >> package main >> >> import ( >> "<new-import-path>" >> ) >> >> func main() {} >> >> See the 2nd line of the original: it is blank. And it disappears in the >> result. And I don't touch neither the Package token of the AST, neither the >> leading comment. >> >> What AST into source printer can I use instead to preserve that blank >> line? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/50b2e8fe-e017-403e-a2d8-f44cfd86f20a%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/50b2e8fe-e017-403e-a2d8-f44cfd86f20a%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f1461f3b-c872-47f5-b67f-5cb5838b8d70%40googlegroups.com.