visualfc / liteide

LiteIDE is a simple, open source, cross-platform Go IDE.
GNU Lesser General Public License v2.1
7.56k stars 968 forks source link

goimports no longer runs #920

Open jdoklovic opened 6 years ago

jdoklovic commented 6 years ago

LiteIDE Version: X33.1 Go Version: 1.9 OS: Linux amd64

There used to be an option unfer the GolangFmt options to "use goimports" instead of go fmt. That option is no longer there and now just has "enable update imports..." which I have checked.

When I use CTRL+ALT+I to reformat code and update imports, it no longer adds/removes imports that I expect.

I expect that all missing imports are added which they are not.

As a test, I changed to gofmt command in gosrc.xml to be:

<config id="GoFmt" name="GOFMT" value="goimports"/>
...

<action id="GoFmt" menu="Utils" img="fmt.png" cmd="$(GOFMT)" args="-w $(EDITOR_FILE_NAME)" save="all" output="true" regex="$(ERRREGEX)" navigate="true" work="$(EDITOR_DIR_PATH)"/>

With that in place, when I use the GoFmt build menu action, it runs goimports and I get the expected result.

Question is, why doesn't LiteIDE do this when using CTRL+ALT+I ??

visualfc commented 6 years ago

liteide gotools internal gofmt include goimports function. please download liteide latest version x33.2 and test. https://github.com/visualfc/liteide/releases if use archlinux download https://github.com/visualfc/liteide/releases/download/x33.2/liteidex33.2.archlinux-pkgbuild.zip

jdoklovic commented 6 years ago

I upgraded to x33.2 and the same issue exists, however, I think I know the problem...

in gosrc.xml on master the GOFMT variable is set to golang's gofmt command, NOT gotools gofmt:

https://github.com/visualfc/liteide/blob/c0b698a036f0b05ebd7921dcc7d43ac797a785e9/liteidex/deploy/litebuild/gosrc.xml#L5

But that's not the only issue... later in the file, the GoFmt action in the utils menus is set as go fmt not even gofmt.

https://github.com/visualfc/liteide/blob/c0b698a036f0b05ebd7921dcc7d43ac797a785e9/liteidex/deploy/litebuild/gosrc.xml#L51

I think the internal command mapping and gosrc.xml are getting in each other's way. Also, I noticed that keyboard mapping Ctrl+Alt+I is supposed to map to "GoImports" but that doesn't work either.

To fix, this is what I had to do:

With that in place, I could use the build menu to properly format and adjust imports, however, the key command Ctrl+Alt+I didn't work.

At this point, I removed the key mapping from GoImports and put it on Build|GoFmt. This worked as expected until I restarted liteIDE and then it didn't work anymore.

To get it working between restarts, I had to add key = "Ctrl+Alt+i" to the GoFmt action in gosrc.xml

Hope this helps!

zelenko commented 4 days ago

CTRL+ALT+I Works for me.

LiteIDE Version: X38.3 Go Version: 1.22.5 OS: Linux amd64