formatter:off doesn't seem to be working Follow
First, I definitely did enable: "Enable formatter markers in comments" option in "Settings | Editor | Code Style".
I then put a line like:
I copied and pasted from the documentation so it should be correct in the code.
I ended the section with:
However whenever I press ctrl+s it still reformats the section. The tags are wrapped around a simple case statement.
Is it possible that the turning on "formatting on save" is in conflict with these marks?
Please sign in to leave a comment.
What do you mean by "formatting on save"? GoLand doesn't an option like that. But, if you invoke "Code | Reformat code" from the menu, the formatter markers are taken into account, everything works as expected in my case.
File watchers makes it possible: https://stackoverflow.com/questions/47735678/goland-how-to-use-gofmt/47737130
The File Watchers permit running tools on save, and in this case, I presume, gofmt or goimports. But neither of those tools understand that annotation as it's specific to the IntelliJ Platform based IDEs, among which Goland as well.
In this case, there's nothing we can do for this and it's unlikely that those tools will adopt the convention above, but you can ask about that in their issue trackers.
Finally, if you use GoLand 2019.2.4 or newer, the formatter is very close to be an identical match to gofmt standard, so perhaps that would be a better solution?
That sounds like the way to go, just use the IntelliJ formatter. I'm guessing the formatting on save is the one thing I'll be giving up which shouldn't be too much of compromise. Besides IDE formatters tend to be highly customizable and I'm guessing IntelliJ's is no exception?
For Go there are not that many things to customize since we try and adhere to the gofmt standard.
One last question, is your formatter by any chance in a binary that could be called with command line options to format a specific file? If so, then I can use File Watcher to call your formatter instead of Go's formatter.
If not, then I can probably look for a macro plugin (or maybe you have macros built in?) that could set off the key combination to format a file upon file save - it's a feature I'm finding good for productivity.
By default, the built-in formatter can't run on save. It's not really needed as the IDE will produce mostly formatted code by default.
During the commit phase, there is also an option in the Commit dialog to run gofmt before commit. So this removes the hassle to worry about formatting the code before it reaches the repository.
As an alternative, you can rebind the gofmt action to be on CMD+S/CTRL+S, as the IDE does autosave at different points in time.
Finally, there is a plugin, Save Actions, https://plugins.jetbrains.com/plugin/7642-save-actions/ that you can try and use to achieve something similar, but I never tried it myself.
Thank you for all that but I think I might have been a little unclear as I think I should get away from gofmt to achieve some of what I want and use your in-built formatter so binding gofmt to CMD+S/CTRL+S is the last thing I want to do.
I'm more interested in your internal formatter doing a clean up and wondering if I can get it to do so through a save action somehow hence asking if it was possible to call your formatter through the command line or have Ctrl+S both format and save somehow, perhaps through a macro if not through command line args to your formatter.
This does the trick: https://plugins.jetbrains.com/plugin/7642-save-actions
Sorry for necro this thread, but if anyone else has the same issue, you need to have a space between '//' and '@' symbol.
Does not work:
Markers with and without space work for me. Make sure you disabled `File | Settings | Editor | Code Style | Go | Other | Run gofmt on code reformat`. Gofmt doesn't know about these markers.
Oh, sorry, my issue with missing space was in Jetbrains Rider. I found this post in a search, and did not see it was the GO subforum.
@formatter:off does not work with or without a space. Using Ctrl-Alt-L to Reformat Code formats everything whether there are markers or not. And yes, it's enabled in Settings, Code Style, Formatter. It's been broken for a while and this is the latest update of IntelliJ as of today.
Todd Hill, could you please share a code snippet to reproduce the problem and what version of GoLand are you using (Help | Find Action | About)?
Ah - wrong forum. I'm talking about IntelliJ. Submitted a question there. Sorry.