-
Notifications
You must be signed in to change notification settings - Fork 646
Use goimports fork for modules support #2098
Comments
@ramya-rao-a: need anything else from me? |
@heschik I have pushed the necessary changes, and this will be part of the next update |
I'm not 100% sure, but this could be breaking things right now. However, I'm not sure this code change has actually been deployed to the extension store yet, so another possibility is that EDIT: the on save behavior is still strangely unreliable. I can run |
Yes, this code change has not been released yet. You can use our beta version which does have the changes
Am not sure how this would work as the changes to use
That is true
How about when you manually run the formatter? Right click -> Format Document? |
Under
So, this explains why it was being finicky. I increased the Format On Save timeout and the issue went away. |
@ramya-rao-a if this still hasn't been released it might make sense to roll it back. The fork is affected by golang/go#28645, and after some internal discussions it looks like we're going to try to get tip working with modules. (Similar to godef.) If it has been released, no problem. |
This has not been released @heschik
That's great news. In that case, I'll just revert the changes done as part of this issue. |
@ramya-rao-a Until this is fixed, how do I make the I installed the fork, and via I don't understand why the tool would behave differently in the shell, vs. inside VSCode. My environment should be identical. |
...Looks like it's because VScode runs Edit: I wrote a little wrapper script that sets the right |
@atombender I dont sent any specific cwd when spawning the process for goimports. See https://github.com/Microsoft/vscode-go/blob/0.7.0/src/goFormat.ts#L64. That can be easily fixed.
I can either set the cwd to the folder that was opened in VS Code, or the parent directory of the file that is being formatted. Would the latter work? |
Yes, the parent directory of the file is the most appropriate. I've confirmed that it works correctly for subdirectories under a module. This comment is relevant to the above. Not sure if |
@atombender Can you remove the wrapper and try the latest beta version of this extension? I have updated it to use the parent directory of the file as cwd. |
Fix confirmed. 🎉 Thank you! |
Thanks! Since you already have the beta version now, you can also check out the upcoming features in the next update. Take a look at #2164 |
With regards to setting the CWD, it has to be set to a folder in which For instance, if you jump to definition in one of the projects source files, it may take you to a file in the module cache. If you set the CWD to the parent of that file when invoking any other tool, the tool is going to fail because the file is not on your GOPATH or part of a true module. And even if it does work, it may produce inconsistent results because it has different module version results to that of your project. |
I understand the problem, but is that relevant to
Are there other use cases? |
It is less of a problem for goimports than almost any other tool, but we want one clear rule that works for all tools in all editors, and most other tools will care. Extra cases to consider:
Also, if you ran it in the module cache it might not do it relative to that module, because on disk it might not be a valid module, |
So, in this case, are we saying that the editor should use the workspace as cwd or that goimports should figure out the right directory based on the file being imported? |
The workspace will be the wrong directory if the file being formatted is in a sub-module. E.g. you have In my opinion, from what I understood of @ianthehat's explanation, the directory of the current file will always work for us when formatting with |
I've pushed a beta version of goimports that uses go/packages for module support. As usual, it's slower than we'd like it to be but should be functional. I think it's ready for use in the same circumstances as the godef and gocode forks.
It does have one slight difference in behavior vs. standard goimports, described in golang/go#28428, but that change should be merged soon.
The text was updated successfully, but these errors were encountered: