Closed ITSecMedia closed 7 years ago
Was also able to reproduce this locally using v0.6.47, windows 10, Go 1.7.1
@dring1 @ITSecMedia Any reason you are using the -w
flag?
This flag is intended to write the formatted content on disk, where as internally we use the -d
option so that the formatting tool gives diff output which the extension uses to apply the edits on the document
Removing all flags, no formatting is taking place. This is my following config:
"editor.formatOnSave": true,
"go.buildOnSave": true,
"go.lintOnSave": true,
"go.vetOnSave": true,
"go.buildTags": "",
"go.buildFlags": [],
"go.lintTool": "golint",
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave":false,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.formatOnSave": true,
"go.formatTool": "goreturns",
"go.formatFlags": [],
"go.gocodeAutoBuild": false,
"go.autocompleteUnimportedPackages": true
Running go fmt .
through a terminal will result in the file being formatted correctly.
From the output panel I only see the following
Finished running tool: C:\Go\bin\golint.exe
Finished running tool: C:\tools\go\bin\go.exe tool vet c:\Go\src\github.com\dring1\test\test.go
Finished running tool: C:\tools\go\bin\go.exe build -o C:\Users\DEVON~1.RIN\AppData\Local\Temp\go-code-check -tags "" .
@dring1 Can you set go.useDiffForFormatting
to false
and try again ?
This appears to be doing the trick! Thank you!
Although auto-import does not appear to be working ( if that is expected functionality)
Finished running tool: C:\tools\go\bin\go.exe build -o C:\Users\DEVON~1.RIN\AppData\Local\Temp\go-code-check -tags "" .
c:\Go\src\github.com\dring1\test\test.go:10: undefined: log in log.Printl
On my windows machine the setting [ "go.useDiffForFormatting": false, ] shows no effect. gofmt and goreturns both don't do the -w formatting inside VSCode, But when I call gofmt -w main.go in VSCode terminal, the file gets reloaded / formatted.
My settings are
"go.useDiffForFormatting": false,
"go.buildFlags": [],
"go.buildOnSave": true,
"go.buildTags": "",
"go.coverOnSave": true,
"go.formatFlags": ["-w"],
"go.formatOnSave": true,
"go.formatTool": "goreturns",
"go.gocodeAutoBuild": true,
"go.gopath": "D:\\go",
"go.goroot": "C:\\Tools\\go",
"go.lintFlags": [],
"go.lintOnSave": true,
"go.lintTool": "golint",
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.vetFlags": [],
"go.vetOnSave": false,
@ITSecMedia As long as you use -w
in the formatflags, things will not work as expected as explained here https://github.com/Microsoft/vscode-go/issues/583#issuecomment-260718842
I will be updating the code to ignore this flag altogether later this week. Can you please remove the w
flag and try?
@dring1 The reason setting go.useDiffForFormatting
to false
worked for you is due to an upstream issue: https://github.com/sqs/goreturns/issues/28 Can you update/upvote that so that we get some traction there?
@dring1 Auto-import should work for as long as the formatting tool is not gofmt
. Can you confirm that? If that still does not work, can you open a separate issue?
Can do, thank you for your help.
@ramya-rao-a I appreciate hint #583 ! I haven't seen that one, been busy all day long ... :( It's working now. 👍 Thank you very much.
Glad I could help, Happy Coding!
Have updated the code to ignore the -w
flag with this: https://github.com/Microsoft/vscode-go/commit/727346e9a25044730e458f7de2bb86ea8882f394
I've noticed a new bug on my system Not sure if it's caused by a VSCode bug or the extension.
Using all latest versions: Windows 10 updates VSCode version VSCode Extension and go packages updates.
My settings:
When I manually trigger save, the go file gets properly formatted but it's not shown in VSCode until I close and reopen it or switch to another file and go back.
When I instantly do a text-formatting change again ( adding a tap or few spaces ) and click save I get a DIFF report, because the file has been changed
What seems to work is, if I click 2 or three times save always waiting a second or two, then the file gets refreshed...
No matter if I use gofmt or goreturns ... seems to be general refresh issue.
BUT : If I edit the file in another parallel opened Texteditor like EmEditor ... VSCode directly updates the file.
So in general instant update/refresh seems to work?!