Comments (16)
Did you enable File -> Auto save ?
Because formatting this way works for me (using the default goreturns).
But formatting at save does not work for me at all. See other issue.
from vscode-go.
I did enable it, but I can't remember if I enabled it before or after this. I know in this particular instance, I right-clicked, then clicked "Format Code" when it happened. (formatting on save didn't do anything)
from vscode-go.
Actually I just now realize that formatting on save is not in the feature list....
from vscode-go.
Format on save is not implemented yet - tracking that in #14.
@mholt Could you share the full file where you see this problem? And could you confirm whether you see this even when you save the file manually before invoking fmt? I wasn't able to repro this myself so far.
from vscode-go.
I am also experiencing some issues when imports are added/removed, e.g. this:
import (
"net/http"
"github.com/jinzhu/gorm"
)
gets formatted to this:
import (
"net/http"
gin-gonic/gin"jinzhu/gorm"
)
or this:
import (
"net/http"
"github.com/xxx/yyy/utils"
)
to this:
import (
"net/http
"github.com/gin-gonic/gin"
"github.com/xxx/yyy/utils"
)
from vscode-go.
Could anyone share a full code sample where they are seeing this? I can't reproduce with the snippets shared so far, but I expect that is because I don't have the rest of the file contents.
from vscode-go.
I got my error in this file: https://github.com/mholt/caddy/blob/e17d43b58a3b31f16e716791e16b69752f36a5ae/caddy/sigtrap_posix.go
by adding a fmt.Println
in one of the cases of the switch.
from vscode-go.
One snippet that goes wrong with goreturns
and also goimports
is (where | is the cursor):
package main
func main() {
fmt.Println("Hello World! :)")
}
|
This results into:
package mainimport "fmt"func main() {
fmt.Println("Hello World! :)")
}
Tried to debug the goFormat.ts
, but can't pinpoint the exact problem. If you enter another space on the last line without saving the file, the format works correctly. Copy and paste also sometimes works correctly, enter the code manually and it seems to go wrong (line end settings: LF).
from vscode-go.
I think I am seeing this issue too.
Here's a very simple reproduce case:
package main
func main() {
}
Note the 2 blank lines. Formatting this (with gofmt
as the format tool) results in correctly formatting .go code.
However, consider this version with 3 blank lines:
package main
func main() {
}
Formatting this leaves 3 blank lines, which is incorrect. Running gofmt -d main.go
shows:
diff main.go gofmt/main.go
--- /var/folders/_w/3kl_g4rn5sv1nyjblk7tf4h00000gn/T/gofmt780202922 2015-11-18 15:08:19.000000000 -0800
+++ /var/folders/_w/3kl_g4rn5sv1nyjblk7tf4h00000gn/T/gofmt316322049 2015-11-18 15:08:19.000000000 -0800
@@ -1,6 +1,4 @@
package main
-
-
func main() {
}
from vscode-go.
Thanks for the repro cases @shurcooL and @sanderhahn. As far as I can tell the Go extension is requesting the right edits here, but Code isn't applying them correctly. Following up on that in microsoft/vscode#144.
from vscode-go.
I've looked over goFormat.ts
and I agree with your assessment @lukehoban. At least I didn't spot anything obviously wrong in there.
from vscode-go.
Another repro case (vertical spaces omitted to save space here):
package main
import (
"log"
"net/http"
)
func main() {
log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}
Now add a spurious "fmt" import:
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}
When I save, it shows the red lines below "fmt", as expected. But then after Format Code, the import block becomes (note the sole double quotes)
import (
"
"log"
"net/http"
)
btw: Nice work overall, Luke and team. This is shaping up really really nicely.
from vscode-go.
@nictuku FWIW: I copy-n-pasted that code, saved it as mytest.go
, right clicked and chose "Format Code" and everything is fine.
I tested this with "goreturns" / "goimports" (when I specify gofmt I get a missing tool prompt for some reason).
from vscode-go.
when I specify gofmt I get a missing tool prompt for some reason
I think the problem is that "do you have this tool installed" check only looks in GOPATH/bin
folders (for each workspace), but not GOROOT/bin
where gofmt
is located.
from vscode-go.
vscode 0.10.2 should have fixed this issue.
from vscode-go.
All - I believe this is now fixed if you update to VS Code 0.10.2
with the fix for #70.
If anyone still sees corruption after formatting, please reopen.
from vscode-go.
Related Issues (20)
- go.formatFlags not working with gofmt -s (simplify) HOT 5
- Couldn't start client gopls HOT 5
- Unable to run Go in VS Code - command not found HOT 4
- Adding a module using `go get` from outside vscode is not recognized until go.mod is reopened HOT 5
- Can not use VS code for GO: Installing github.com/go-delve/delve/cmd/dlv FAILED HOT 5
- Disable real-time syntax error highlighting with gopls HOT 1
- Problem in mouse hover tooltip HOT 3
- Automatically Infer Path Mapping for Remote Debugging
- // .*DO NOT EDIT.?$ HOT 6
- Extension issue HOT 1
- 0.14.2 broken on macos HOT 3
- Extension Repository Migration Plan HOT 1
- Region comments not working when extension is enabled HOT 3
- Debugging uses wrong working directory HOT 4
- Background of covered and not covered code cannot be removed after running package test HOT 9
- Extension Migration Plan HOT 4
- numeric constants containing underscore are not colored correctly HOT 1
- Gopls does not support versions of go <=1.12 HOT 2
- Unable to set breakpoint when using gutter and clear Code coverage HOT 3
- Updated to 0.14.3 or the nightly and entirely stopped working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-go.