Skip to content
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

No support for "editor.formatOnSaveMode": "modifications" and "modificationsIfAvailable" #3174

Open
Malix-Labs opened this issue Feb 15, 2024 · 5 comments

Comments

@Malix-Labs
Copy link

Malix-Labs commented Feb 15, 2024

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.
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
  • Check your installed extensions to get the version of the VS Code Go extension
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

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.

	"gopls": {},


	"[go]": {
		"editor.defaultFormatter": "golang.go",
		"editor.formatOnSave": true,
		"editor.formatOnSaveMode":
			"file", // (default)
			// "modifications" // BUG: DOESN'T FORMAT
			// "modificationsIfAvailable" // BUG: USES "modifications" INSTEAD OF "file"
	},

https://github.com/Malix-off/vscode-issues-203463/blob/4c506f5c9fedbd12d0295455675a63c1f45f1591/.vscode/settings.json#L8-L17

Describe the bug

"editor.formatOnSaveMode": "modifications" is broken anywhere & "editor.formatOnSaveMode": "modificationsIfAvailable" relies on modification anyway

Steps to reproduce the behavior:

  1. Clone https://github.com/Malix-off/vscode-issues-203463
    I provided a dev container config
  2. Disable every extension except golang.go.
  3. Test with "editor.formatOnSaveMode": "file"
    1. Make https://github.com/Malix-off/vscode-issues-203463/blob/master/main.go unformatted (for exemple, add a tabulation before L3)
    2. Save
    3. Check results (currently works)
  4. Test with "editor.formatOnSaveMode": "modifications"
    1. Make https://github.com/Malix-off/vscode-issues-203463/blob/master/main.go unformatted (for exemple, add a tabulation before L3)
    2. Save
    3. Check results (currently doesn't work)
  5. Test with "editor.formatOnSaveMode": "modificationsIfAvailable"
    1. Make https://github.com/Malix-off/vscode-issues-203463/blob/master/main.go unformatted (for exemple, add a tabulation before L3)
    2. Save
    3. Check results (currently call "modifications", thus doesn't work)
@gopherbot gopherbot added this to the Untriaged milestone Feb 15, 2024
@findleyr findleyr changed the title "editor.formatOnSaveMode": "modifications" broken anywhere & "editor.formatOnSaveMode": "modificationsIfAvailable" relies on modification anyway No support for "editor.formatOnSaveMode": "modifications" or "modificationsIfAvailable" Feb 15, 2024
@findleyr
Copy link
Member

VS Code Go doesn't support formatOnSaveMode: "modifications". Formatting uses the same logic as gofmt, which operates on whole files at a time.

Marking this as a feature request, but it is realistically unlikely to be implemented any time soon, given that so much relies on preserving gofmt'edness for the entire file.

@Malix-Labs
Copy link
Author

Malix-Labs commented Feb 15, 2024

Understandable.

There sure would be a way to make it so modificationsIfAvailable would chose file instead of crashing on modifications (otherwise there would be no point in this option)

Moreover, there is a way in the VSCode API to make extensions enforce external settings defaults, and would be great to use it for

    [go]: {
        "editor.formatOnSaveMode": "modifications"
    }

Until modificationsIfAvailable is fixed

@findleyr
Copy link
Member

@Malix-off I'm not sure. CC @hyangah, who may know.

@Malix-Labs
Copy link
Author

Malix-Labs commented Feb 15, 2024

With Go, "editor.formatOnSaveMode": "modificationsIfAvailable" is missleading and break formatting.

It should possible to differentiate from file and modification, at least, thus making it possible to use file instead of modifications when using modificationsIfAvailable.

By the way, my initial issue was more to address a bug report about modificationsIfAvailable chosing modifications instead of file than to feature request modifications to work (which would be a feature request).

References

see microsoft/vscode#203463 (comment)

@Malix-Labs Malix-Labs changed the title No support for "editor.formatOnSaveMode": "modifications" or "modificationsIfAvailable" No support for "editor.formatOnSaveMode": "modifications" or "modificationsIfAvailable" Feb 15, 2024
@Malix-Labs Malix-Labs changed the title No support for "editor.formatOnSaveMode": "modifications" or "modificationsIfAvailable" No support for "editor.formatOnSaveMode": "modifications" and "modificationsIfAvailable" Feb 15, 2024
@Malix-Labs
Copy link
Author

Malix-Labs commented Mar 17, 2024

Poke @findleyr

This issue is not a feature request but a bug report

See #3174 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants