CodeboxIDE / codebox

Open source cloud & desktop IDE
https://www.codebox.io
Apache License 2.0
4.12k stars 590 forks source link

Improve Golang support : with gofmt (and goimports) #120

Open mkmik opened 10 years ago

mkmik commented 10 years ago

Go has a very useful automatic formatting with the builtin gofmt tool.

Either an explicit button/shortcut or an on-save hook would be good.

goimports is also very easy to use, but it would be better to make it opt-in, since it can be quite confusing (especially in the on-save hook mode, when unused imports would disappear)

AaronO commented 10 years ago

@mmikulicic We've already got some basic Go support (syntax highlighting and autorun support).

It would definitely be interesting to extend this support. However I think a hook suggestion must be in some way generic so this concept can be applied to other languages besides Go.

Maybe we could add the concept of tools to a given language and so for each file of that language it would desplay entries in the GUI for those tools.

@SamyPesse This could be a more general form of file running. Where running a specific file is just one of the tools available.

The kind of things that could fit in the tools category in my opinion could be :

@SamyPesse @mmikulicic This requires some extra thought so we can extract it to something generic. Please share your thoughts.

PS: @mmikulicic It's nice to see a fellow Irish citizen contributing to codebox ;)

SamyPesse commented 10 years ago

I think a good solution could be to do a "Gofmt" addon that will add a command on the IDE to run gofmt on a selected file.

I started writing a documentation for add-on development at https://github.com/FriendCode/codebox/blob/master/docs/addons/getstarted.md

mkmik commented 10 years ago

@AaronO I agree with you that it would be better to solve it in a generic way, after all, there is also http://clang.llvm.org/docs/ClangFormat.html (I'm not really Irish, yet :-) this is just my first year here)

All tools should be configured in one place. So we need a tool registry, preloaded with common language specific tools, but allow the user to just override the command lines. We have to figure out how to map a toolset to a specific subset of files (just by language? by custom profiles?)

Let's divide the tools in two rough categories:

My feature request was focusing on the latter. It has a smaller scope and less impact on the gui. Probably it can be implemented with an addon, as suggested by @SamyPesse .

@SamyPesse: can the addon execute code on the user's box? Because that would be required to use goimports which has to have access to the actual dependencies installed.

kalbasit commented 9 years ago

Does Codebox offer a before-save and after-save hooks? If such hooks exists, we can simply add Addons per language, project (whatever the addon author want) that will bind to such hook and will mutilate the text however it wants. In this instance, the Gofmt (or Goimports) will bind to the before-save hook, and once the user saves, it passes the text to the actual command (Gofmt, Goimports) and replaces it with the output.