-
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: make eglot+gopls awesome #67529
Comments
From #62330: one thing to look at would be watched file support (didChangeWatchedFiles). |
Re didChangeWatchedFiles, at least for macOS there's the possibly related emacs-lsp/lsp-mode#3296 (comment) for lsp-mode. Looks like eglot does use |
I'm so glad to see this area getting some investment 😁. lsp-mode is nice, but the eglot experience works much better with TRAMP (especially in concert with https://github.com/patrickt/codespaces.el) and GitHub Codespaces. |
Regarding the Specifically, I can reproduce issue #62330 on macOS, but not on Linux. On Linux, the (inotify-based) file content watching works and if I update go.mod’s contents (e.g. with On macOS, indeed I get no event at all. AFAIK, Emacs does its own file watching (falling back to polling, even) for opened files, which is why having a file open papers over the problem. I linked Emacs bug#51146, which I’ll summarize as: This is an inherent limitation of kqueue-based watching. Adding fsevents support (a macOS-specific file watching API) to Emacs would probably be the best way to fix this bug. With that said, there is another problem regarding To better understand what’s happening, I instrumented Emacs like so: (defun my-file-notify-add-watch-logger (file event &rest args)
"log a message whenever file-notify-add-watch is called"
(message "file-notify-add-watch called with file: %s, event: %s" file event))
(advice-add 'file-notify-add-watch :before #'my-file-notify-add-watch-logger) When opening
Creating a new directory does not result in a new expansion of the glob pattern, so the new directory is unwatched. I have filed a bug report about this with Eglot, but given the rather dire state of client-side watching, are we sure that we don’t want to reconsider server-side watching? :) |
Two years ago I would have responded with a philosophical argument that clients should be responsible for all state changes, etc etc, including the arguments here. However, after years of struggling with client-side watching, I am at the point where the only barrier to switching to server-side watching is momentum; we have other high priorities, and file watching sort of works in most clients. Perhaps I'm being overly pessimistic, though. In theory, it shouldn't be that hard to link a cross platform file watching library, and provide a gopls option to use server-side file watching. It may be worth an experiment. |
:) I had a quick look and it seems like https://github.com/fsnotify/fsnotify is the most popular Go package for file watching. It does support recursive watching since last month (see fsnotify/fsnotify@a618f07), but not on macOS (it also does not support the fsevents API on macOS). So I suppose by using the fsnotify package as of today, we would fix file watching on macOS in general, and recursive file watching on Linux, but not on macOS. |
You inspired me to file #67995, dumping my thoughts on this issue. If you are interested, feel free to give that a try. I think the three bullets listed there are the basic code pointers necessary, though I'm happy to provide more guidance. This is a relatively self-contained experiment, and doesn't require deep gopls knowledge. |
@stapelberg and I plan to work together to make Emacs+eglot smoother, faster, and better documented.
Some specific items (feel free to add or suggest more):
didChangeWatchedFiles
for unopened files on macOS (see x/tools/gopls: unable to organize imports after go mod tidy / go get #62330)didChangeWatchedFiles
to work recursively? The underlying Emacsfilenotify
package does not watch directories recursively, but gopls’s glob pattern requests recursive matching.go-*
helper commands for features otherwise accessible though more cumbersome eglot commands (e.g. go-doc, go-test, go-freesymbols, etc); see add go-* shortcuts for various hard-to-find eglot operations dominikh/go-mode.el#436(global-set-key (kbd "s-<mouse-1>") #'xref-find-definitions-at-mouse)
.The text was updated successfully, but these errors were encountered: