-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vscode golang formatter, I can't modify its config #2556
Comments
As for the imports, I found out that it is golang-based, I can't write a specific package that I haven't used in the code
It remains to solve the problem of blank lines (For me it is a problem :) |
I use the import first, and then it usually fills in the import statement
when I save the file. That is, I type
func main() {
log.SetFlags(log.Lshortfile)
flag.Parse()
and when i save the file it adds the import statements for "log" and "flag"
…On Sun, Dec 4, 2022 at 11:48 AM AbdulRahman ***@***.***> wrote:
As for the imports, I found out that it is golang-based, I can't write a
specific package that I haven't used in the code
I wonder if golang can ignore imports that are not used, in any way
It remains to solve the problem of blank lines *(For me it is a problem
:)*
—
Reply to this email directly, view it on GitHub
<#2556 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJIAI2JHQ2QMT5FOT56F7TWLTDPJANCNFSM6AAAAAASTOAX4Q>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
See discussion about this feature in https://go.dev/issue/54362. The fundamental problem with implementing this is that unused imports are a compile error, and so not cleaning them up leaves code in a broken state. The example there is compelling: if I remove the last use of "net/http" from the file and save, it is burdensome to then have to delete imports. I think the common workflow with goimports is what @pjweinb describes: never write an import statement: just let goimports manage them for you. With that said, this takes some getting used to, and may not be ideal as unimported completion lacks hover information, and goimports sometimes chooses the wrong import. There is a lot of room for improvement here. |
With respect to not putting a line between import and function: part of the gofmt philosophy is that there should be one way to format code. It may not be everyone's favorite way (or even anyone's favorite way), but the value of having one way outweighs any individual formatting decision: https://www.youtube.com/watch?v=PAAkCSZUG1c&t=523s I'm going to close this as a dupe of golang/go#54362, because that issue tracks improving the UX of managing imports. |
What version of Go, VS Code & VS Code Go extension are you using?
Share the Go related settings you have added/edited
Describe the bug
when i type code like this in golang and save it (Ctrl + S)
this code will be formatted thus:
net/http
from the code because I didn't use this packageas a nodejs (js) developer, is used vscode for long time for js development
when i type code like this:
this code will be formatted thus:
As you can see here, just formatting the spaces,
Screenshots or recordings
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
The text was updated successfully, but these errors were encountered: