I'm using lsp-mode as lsp client and gopls as lsp backend in order to lookup function and variable definitions in go projects.

On a given large repository (kubernetes) that I recently wiped and cloned again, I see that, when I want to lookup a definition (lsp-find-definition), emacs will stall for a few seconds and then fail:

"Timeout while waiting for response. Method: textDocument/references" – 

Is there anything I can do to fix this?

Notice that all the definition lookups worked fine before I deleted the project folder and re-crated it...

3 Answers 3


You can lengthen the timeout using the lsp-response-timeout option: https://emacs-lsp.github.io/lsp-mode/page/settings/mode/#lsp-response-timeout

Of course, what you really want to do is make gopls faster. Probably not much you can configure in Emacs to do that.

  • 1
    AFACIT setting the lsp-response-timeout to a different value also required restarting the workspace with M-x lsp-restart-workspace.
    – anon2328
    Jun 2, 2023 at 15:03

I encountered this problem too, and it did timeout each time as I saved file. I configured the lsp-format-buffer and lsp-organize-imports as the hook of before-save-hook.

When I dived into the Emacs *lsp-log* buffer (you can also invoke lsp-describe-session), I found that Emacs used my $HOME as the root of current lsp-workspace-folder instead of the current project path, so it timeouted, and it made sense.

So what I did is to invoke lsp-workspace-folders-remove and remove the $HOME folder and re-visit my project, and select current folder as the root. It worked!

For more configuration, you can access my Emacs dot file https://github.com/yuanbohan/dot-files/blob/master/emacs/conf/conf.org#go


A workaround for this is to disable file watchers:

(setq lsp-enable-file-watchers nil)

... and then restart the workspace:


I'm not sure if this effectively disables a useful feature, but I can't get it to work otherwise.

The solution was described here: https://github.com/golang/go/issues/38032

More about file watchers here: https://emacs-lsp.github.io/lsp-mode/page/file-watchers/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.