Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

goreturns not unstable in module mode #2309

Closed
FAQinghere opened this issue Feb 8, 2019 · 12 comments
Closed

goreturns not unstable in module mode #2309

FAQinghere opened this issue Feb 8, 2019 · 12 comments

Comments

@FAQinghere
Copy link

For about a year the auto-formatting using goreturns or goimports has continuously alternated between working and not working (with more time spent in the not working state). gofmt, of course, always works fine.

From one of several (closed) issues about this same problem:

  • Does goreturns work when you manually format the file in VS Code i.e right-click -> Format Document?
  • no (but I have experienced this problem with this plugin in the past)
  • Are there any errors in the console? Help -> Toggle Developer Tools -> Console
  • no
  • Can you try updating the tool? Run Go: Install/Update Tools, select goreturns to update
  • yes, I did

Again, I expect this to suddenly start working again randomly at some point. But then it will stop working again randomly at some point.

I do use go modules and for some reason have the vague impression that it's related.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Feb 12, 2019

Please let me know if that works for you.

@ramya-rao-a ramya-rao-a added the go-modules Related to Go modules label Feb 12, 2019
@ramya-rao-a ramya-rao-a changed the title goreturns and goimports, etc. still unstable goreturns and goimports, etc. still unstable in module mode Feb 12, 2019
@nezorflame
Copy link
Contributor

I can confirm goimports works without any issues in module mode.

@ramya-rao-a
Copy link
Contributor

Thanks for confirming that @nezorflame

What we can do to improve this experience is to use goimports instead of goreturns when using modules.

PRs are welcome for this

Code Pointers:

  • See Build and Debug Extension to set up local dev environment
  • goFormat.ts is the file to be updated to use goimports if user's choice is goreturns in module mode
  • isModSupported is the helper function to use to determine if current file is using modules

@ramya-rao-a ramya-rao-a changed the title goreturns and goimports, etc. still unstable in module mode goreturns not unstable in module mode Feb 14, 2019
@open-source-explorer
Copy link

open-source-explorer commented Feb 14, 2019

@ramya-rao-a I can't find any isModSupported method within the goFormat.ts file.

@ramya-rao-a
Copy link
Contributor

@open-source-explorer You need to import isModSupported from the goModules.ts file

@jamesgeorge007
Copy link
Contributor

@ramya-rao-a I made an attempt to refactor the code based on my assumptions.
Kindly have a look at #2338 and let me know your thoughts 👍

@stevvooe
Copy link

This still isn't working. I've tried a whole bunch of different configurations, including the suggestion above. It seems to work on simple imports but when there are few different possibilities, it just does nothing. Running the goimports tool in the CLI works find and inserts the correct import.

My configuration is as follows:

{
    "go.installDependenciesWhenBuilding": false,
    "go.formatTool": "goimports",
    "go.inferGopath": true,
    "editor.formatOnSave": true,
}

I'm using a regular GOPATH setup, without modules. I'm using vscode 1.31.1 on Mac OS X. The extension is version 0.9.2

@ramya-rao-a
Copy link
Contributor

@stevvooe When you see that goimports works fine when run in CLI but not in VS Code, can you share from which folder are you running the goimports tool? Try running it from the same folder which has the file being formatted.

@stevvooe
Copy link

I run it from the directory root, but it works fine either way. I suspect something is wrong with how the tool is being called. Is there a way to print the command that is being run, like some debug mode?

@stevvooe
Copy link

It also seems to happen when there are multiple imports to add. I'll see if I can get a minimal example, but it would be easier if I could just see what command is being run, as I suspect its not formed correctly.

@ramya-rao-a
Copy link
Contributor

Regarding the original issue here about goreturns vs goimports for modules:

In the latest beta version (0.9.3-beta.2) of this extension, if you are using modules, your workspace settings will be updated to use goimports instead of goreturns for formatting (and you will be notified of the same). If you don't have goimports installed, you will be prompted to install the same

@stevvooe If the formatting failed, then there will be logs with the exact call being made.

From the View menu, select Output. Select Log (Extension Host) from the drop down on the top right corner of the panel. This will have logs from the extension host and errors from extensions.
Clear it (there should be a button on the top right corner), try formatting again and see if anything is printed to the logs

Please log a new issue with your findings. I am closing this issue as we now use goimports instead of goreturns when using Go modules

@ramya-rao-a
Copy link
Contributor

The fix for this issue is out in the latest release(0.10.0) of the Go extension

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants