Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

gpls import order #3059

Closed
zxwtry opened this issue Feb 20, 2020 · 4 comments
Closed

gpls import order #3059

zxwtry opened this issue Feb 20, 2020 · 4 comments

Comments

@zxwtry
Copy link

zxwtry commented Feb 20, 2020

alphabetical:'
"fmt"
"github.com/xxx"
"log"

"os / github / xxx" :
"fmt"
"log"
"github.com/xxx"

i want to order imports in alphabetical
but formatTool will change to "os / github / xxx"

how to keep alphabetical? thx

@ruinshe
Copy link

ruinshe commented Feb 20, 2020

I meet similar problem when using vscode with basic Go plugin configuration.

When I put all imports together, the plugin split the imports into multiple blocks (I used gofmt source.go it shows all imports are put together), and my go.formatTool was set to gofmt.

When I set "go.useLanguageServer": false in the settings file, it looks fine and the code is really formatted by gofmt tool.

Any idea?

@stamblerre
Copy link
Contributor

If you want your imports to be organized on save then they will be grouped this way, as the default behavior of the goimports tool is to separate standard library and third-party imports. This is the structure for the majority of Go code, and I would recommend sticking with this default. (cc @heschik)

If you only want to use the language server but only have formatting on save (@ruinshe, I believe this is your case), then you can add the following configuration to your settings.json file:

"[go]": {
	"editor.codeActionsOnSave": {
		"source.organizeImports": false,
	},
	"editor.formatOnSave": true
}

@ruinshe
Copy link

ruinshe commented Feb 20, 2020

@stamblerre Thanks for the quick reply, and Your solution works for me.

@stamblerre
Copy link
Contributor

Going to close this issue since it hasn't had much activity in the last month. @zxwtry: please reopen this issue if you're still encountering problems.

@vscodebot vscodebot bot locked and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants