liteide icon indicating copy to clipboard operation
liteide copied to clipboard

goimports no longer runs

Open jdoklovic opened this issue 7 years ago • 3 comments

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 ??

jdoklovic avatar Mar 05 '18 17:03 jdoklovic

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

visualfc avatar Mar 06 '18 01:03 visualfc

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:

  • set GOFMT in gosrc.xml to $(LITEIDE_TOOL_PATH)/gotools
  • set GoFmt action in gosrc.xml to cmd="$(GOFMT)" args="gofmt -fiximports -w $(EDITOR_FILE_NAME)"

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!

jdoklovic avatar Mar 14 '18 18:03 jdoklovic

CTRL+ALT+I Works for me.

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

zelenko avatar Sep 10 '24 14:09 zelenko