![]() ![]() Does it make sense to continue supporting it, or can it be replaced with ‘go fmt’ entirely? There are at least two reasons to keep it. There are a few problems that appear when using an external tool to reformat code.įirst of all, GoLand already has an embedded code formatter. And though the IDE can’t support all of their workflows, we should still try to make them feel as comfortable as possible in the new environment. Recently, more and more developers have been switching to GoLand from conventional editors. Also, I’m afraid that even if we find a satisfying answer for this question, there would still be yet another hurdle that is extremely hard to overcome – habit. But that is a large topic that probably deserves a separate post. At this point, we should probably step back and think about why one might want to reformat code automatically and regularly. Even if ‘go fmt’ is enabled by default in GoLand, the resulting experience will be different from what users expect. The conclusion I’d like to emphasize from the above description of the IDE’s behavior is that the meaning of “on-save” in GoLand is not quite the same as it is for other editors. File | Local History is available to help you restore a previous file snapshot if necessary. Building/running, performing VCS operations, and closing a file are among such reasons. You can control some of these reasons, such as the option to save your file upon IDE frame deactivation, via Settings ( Preferences) | Appearance & Behavior | System Settings | Autosave. They can save a file for a lot of different reasons. IntelliJ-based IDEs, such as GoLand, work differently. You open a file and modify it, and then you either explicitly save it or close the editor, losing your changes. Indeed, conventional text editors typically have a straightforward workflow. If you’ve never used GoLand before, you may be surprised that there is more than one internal reason to modify file content. While it might seem like a good idea to just go ahead and commit them, that’s probably not what you opened the IDE to do. Thus you now have modified files even though your only intention was to update the project. If they were committed with non-canonical formatting, they are updated. Some files are changed on disk, so the IDE runs ‘go fmt’ on them. Then you update the project using, say, ‘git pull’. The main concern here is the user experience. A file watcher can be configured to run ‘go fmt’ on external changes, but this option is disabled by default. It could be Git pulling updates, another editor modifying a file, and so on. There are many reasons why file contents can be changed, but we can roughly divide them into two groups: external (with respect to the IDE) and internal.īy an external reason, I mean a tool modifies file content on disk. I’ll describe this problem in more detail in the next session. The key word in this case is “whenever,” as users don’t have full control over the precise moment a file gets modified. Whenever a Go file is changed, the command is executed on it. It’s easy to add a new watcher by using the predefined ‘go fmt’ template. Under Settings ( Preferences), you can find Tools | File Watchers. The third way is to configure a file watcher. There you can find Go fmt, which is enabled by default. They can be configured via Settings ( Preferences on macOS) | Version Control | Commit | Before Commit. There are several hooks that can be run before a commit. The sole purpose of these actions is to run ‘go fmt’, providing it with either file paths or a path to the project directory, and they only work when you invoke them manually. ![]() Each has a shortcut assigned to it: Alt + Shift + Control + F ( Alt + Shift + Cmd + F on macOS) and Alt + Shift + Control + P ( Alt + Shift + Cmd + P), respectively. Under the Tools | Go Tools menu, you can find two actions related to code formatting: Go Fmt File and Go Fmt Project. The current stateĬurrently, GoLand offers three ways to interact with ‘go fmt’: dedicated actions, before commit tools, and file watchers. ![]() If you’re new to the language, you might want to familiarize yourself with the topic before continuing reading. Note: For the sake of brevity, I’m assuming you know what ‘go fmt’ is. If you believe that what GoLand provides now is not enough or could work better, please read the post and share your thoughts with us. This blog post’s primary purpose is to collect as much user feedback as possible before implementing anything. In this article, I’d like to describe some of the obstacles that make doing this difficult, analyze some solutions to the same problem from other IDEs, and reflect on the paths that GoLand can take to address this request. Even though GoLand supports running ‘go fmt’ on save, users regularly request making this option more discoverable or even enabling it by default. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |