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

Can't disable AutoFormat, at the same time, enable autoImport. #2902

Closed
zihaojin opened this issue Nov 13, 2019 · 7 comments
Closed

Can't disable AutoFormat, at the same time, enable autoImport. #2902

zihaojin opened this issue Nov 13, 2019 · 7 comments
Labels

Comments

@zihaojin
Copy link

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

  • Run go version to get version of Go
    go version go1.13 linux/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    Version: 1.40.0
    Commit: 86405ea23e3937316009fc27c9361deee66ffbf5
    Date: 2019-11-06T17:09:34.601Z
    Electron: 6.1.2
    Chrome: 76.0.3809.146
    Node.js: 12.4.0
    V8: 7.6.303.31-electron.0
    OS: Darwin x64 18.6.0
  • Check your installed extensions to get the version of the VS Code Go extension
    0.11.9
  • Run go env GOOS GOARCH to get the operating system and processor arhcitecture details
    linux
    amd64

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] prefixes.

{
    "remote.SSH.showLoginTerminal": true,
    "window.zoomLevel": 1,
    "files.autoSave": "onFocusChange",
    "editor.fontSize": 15,
    "terminal.integrated.fontSize":13,
    "go.lintOnSave": "off",
    "go.useLanguageServer": true,
    "go.languageServerExperimentalFeatures": {
            "diagnostics": true ,// for diagnostics as you type
            "autoComplete": false,
            "documentLink": true,
            "findReferences": true,
            "documentSymbols": true,
            "format": false,
            "goToDefinition": true,
            "goToTypeDefinition": true,
            "hover": true,
            "incrementalSync": true,
            "rename": true,
            "signatureHelp": true,
            "workspaceSymbols": true,
    },
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": false,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
}

Describe the bug

A clear and concise description of what the bug.
I need to disable AutoFormat, at the same time, enable autoImport.
I set

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

formatOnSave still works.

If I set

        "editor.codeActionsOnSave": {
            "source.organizeImports": false,
        },

Both formatOnSave and autoImport not working.

A clear and concise description of what you expected to happen.
Disable AutoFormat, at the same time, enable autoImport.

@ramya-rao-a
Copy link
Contributor

Thanks for reporting @jinzihao123

cc @stamblerre

@ramya-rao-a ramya-rao-a added the upstream-gopls Issue for gopls label Nov 15, 2019
@stamblerre
Copy link
Contributor

@jinzihao123: I expect you will be able to achieve this by removing this setting:

 "go.languageServerExperimentalFeatures": {
    "format": false,
},

VS Code will fall back to formatting your file with the default go.formatTool if you disable formatting through gopls. Setting editor.formatOnSave to false will tell VS Code not to format your file, but you will still get import organization through the editor.codeActionOnSave setting.

@stamblerre
Copy link
Contributor

@ramya-rao-a: This issue is closely related to the discussion on #2446, so perhaps this one can be closed as a duplicate?

@ramya-rao-a
Copy link
Contributor

@stamblerre This is the case of not wanting formatting on save (neither by gopls nor by the extension), but wanting the "organize imports" features that would add missing imports, remove unused imports and re-order imports if needed. Therefore, I see this as separate from #2446

@stamblerre
Copy link
Contributor

goimports out of the box also runs gofmt, so this is only possible if you are using the language server. We only recently added the separation between formatting and imports, previously imports would also always run the formatter as well. I believe that this will be doable with gopls/v0.3.0 and the following configuration:

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

@ramya-rao-a
Copy link
Contributor

Thanks @stamblerre

@jinzihao123 Can you try with the latest gopls and the above settings? YYou can download it by running

GO111MODULE=on 
go get golang.org/x/tools/gopls@master golang.org/x/tools@master

@vscodebot
Copy link

vscodebot bot commented Feb 14, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. Thank you for your contributions.

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

No branches or pull requests

3 participants