-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: unable to organize imports after go mod tidy / go get #62330
Comments
Extra infoIf I do |
Thanks for the issue, and the repro. We will take a look. |
This doesn't seem to reproduce any more, at least in vscode. Is it still an issue, or could it be closed? |
I just tried this with GNU Emacs 29.3 and eglot-1.17. Here's what I saw:
At this point, the import that was added in my case was a different one:
The flymake error I saw here actually related to the previous docker package, even though the source code no longer mentions it. (There's a metadata inconsistency somewhere.) Only after deleting the import and saving, so that organize-imports ran again, did the import and the error message become consistent about the jroimartin package.
(To be clear, I ran this on the shell, not through gopls from the go.mod file.)
No, I still see the error. Another inconsistency.
No, the package was imported again, and this time without error. Unfortunately I think there are at least two bugs here. |
@adonovan are you getting didChangeWatchedFiles notifications? If not, I think that explains the inconsistency. Gopls is not notified of the go.mod change, and therefore does not reload. Deleting and reimporting causes a reload, which is why the error goes away the second time. |
Yep, that's it: Emacs doesn't report a |
In that case, this is an unfortunate emacs issue. Perhaps something to add to #67529. |
Closing this specific issue as unactionable, though some team members who use eglot are hoping to work on improving the status quo here in #67529. |
go.mod is fairly special. what are the downsides to gopls checking it too
often?
…On Fri, May 24, 2024 at 1:07 PM findleyr ***@***.***> wrote:
In that case, this is an unfortunate emacs issue. Perhaps something to add
to #67529 <#67529>.
—
Reply to this email directly, view it on GitHub
<#62330 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJIAI6T35FTMNCLPTZE67LZD5XV7AVCNFSM6AAAAAA4BZ5YVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGAYTANRYGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@pjweinb it is not recommended for servers to do their own file watching, for the reasons listed here: We could poll the go.mod file, but that would only benefit the relatively small fraction of users on LSP clients that don't support file watching. It also would introduce a source of additional complexity in testing. Also, there are other on-disk changes we care about, such as changes in dependencies, and it seems inconsistent to watch go.mod files and not others. On the other hand, file watching is a real source of inconsistent behavior across clients. Certain clients are optimized for watching e.g. "**/*.go", and others are not... so much so that this is the only place in all of gopls where we actually switch behaviors based on the client's user agent. So, I am not in favor of adding ad-hoc watching of go.mod files. However, I would consider a larger project to give up entirely on client-side file watching, in favor of reverting to server side watching. Speaking with the Dart folks, they have server-side watching and haven't had major problems with it. Unfortunately, we're not currently in a position to make these types of large changes for marginal gain. |
I know pretty much nothing about the eglot internals, but why can't we make eglot/go-mode watch go.mod? This bug is an Emacs quirk. We can just fix it in Emacs, right? |
Exactly. The server gopls tells the client eglot which files to watch, and I think that set includes go.mod, but for some reason it does not seem to be taking effect. |
gopls version
go env
What did you do?
go mod init github.com/jroimartin/goplsissue
main.go
with the following contents:And, as expected, the following error is reported by flymake:
go mod tidy
github.com/jroimartin/proxy
What did you expect to see?
After saving the file, the package
github.com/jroimartin/proxy
should be imported again.What did you see instead?
No package is imported.
Editor and settings
Editor: GNU Emacs 28.2
LSP client: eglot 1.15
Relevant
init.el
snippet:Logs
I'm not sure if it is related, but the following error caught my attention:
The text was updated successfully, but these errors were encountered: