Skip to content

x/tools/gopls: don't run gofmt on generated files #49555

Closed
@gudvinr

Description

@gudvinr

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

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.17.3 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.7.3
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.61.0 (x64)
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.29.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • gopkgs: /home/gudvin/tools/go/path/bin/gopkgs: go1.17.1
      go-outline: /home/gudvin/tools/go/path/bin/go-outline: go1.17.1
      gotests: /home/gudvin/tools/go/path/bin/gotests: go1.17.1
      gomodifytags: /home/gudvin/tools/go/path/bin/gomodifytags: go1.17.1
      impl: /home/gudvin/tools/go/path/bin/impl: go1.17.1
      goplay: not installed
      dlv: /home/gudvin/tools/go/path/bin/dlv: go1.17.1
      dlv-dap: /home/gudvin/tools/go/path/bin/dlv-dap: go1.17.1
      gopls: /home/gudvin/tools/go/path/bin/gopls: go1.17.1

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"] or gopls prefixes.

{
    "editor.formatOnPaste": false,
    "editor.formatOnSave": false,
    "go.toolsManagement.autoUpdate": true,
    "go.vetOnSave": "workspace",
    "go.lintOnSave": "workspace",
    "go.toolsGopath": "~/path/to/go/",
    "gopls": {
        "build.experimentalWorkspaceModule": false,
        "ui.documentation.linksInHover": false,
        "usePlaceholders": false,
        "analyses": {
            "composites": false,
            "shadow": true,
            "ST1000": false,
            "ST1003": false
        },
        "ui.diagnostic.staticcheck": true
    }
}

Describe the bug

When save action is called with generated file open in editor it then become formatted.

Generated code has comment matched by this regex:
^// Code generated .* DO NOT EDIT\.$

In fact, extension warns that file should not be edited. But then proceeds to edit it by itself.

Steps to reproduce the behavior:

  1. Open generated file
  2. Press Ctr+S

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions