Skip to content

vscode golang formatter, I can't modify its config #2556

Closed as not planned
Closed as not planned
@iabdo9

Description

@iabdo9

What version of Go, VS Code & VS Code Go extension are you using?

Go version: go1.19.3
gopls: v0.10.1
vscode: 1.73.1

Share the Go related settings you have added/edited

I didn't edit any settings in Preferences: Open Settings (JSON) after install golang extension
just enable format on save

Describe the bug

when i type code like this in golang and save it (Ctrl + S)

package main
import (
    "fmt"
    "net/http"
)
func main() {
    fmt.Println("Hello World!")
}

this code will be formatted thus:

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello World!")
}
  • It has added blank lines between the function and import
  • It removed net/http from the code because I didn't use this package
    • This is really annoying, my hand is used to pressing Ctrl + S every moment, so imports that I haven't used yet are always deleted

as a nodejs (js) developer, is used vscode for long time for js development
when i type code like this:

const express = require("express");
fucntion send(text) {
console.log(text)
   }
send(         "Hello World!");

this code will be formatted thus:

const express = require("express");
fucntion send(text) {
    console.log(text)
}
send("Hello World!");

As you can see here, just formatting the spaces,

  1. it didn't remove the import even though I didn't use it
  2. It does not create blank lines between the function and the import

Screenshots or recordings

A gif showing what happens when I save a file

I want to know where can I get the config file for golang formatter, and what's the best way to solve those above problems?

I know this might be counterintuitive to some, but I'm used to a certain way of formatting

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions