Emacs problem with tide-mode, eslint, and eldoc

Posted by on 6 August 2022

I created a YouTube of this if you would rather consume this information in video format: https://youtu.be/nS92d9J13XY.

I edit almost everything in Emacs. I primarily edit JavaScript or TypeScript so I use the Tide Mode package for it's many features that make editing JavaScript much easier. Two of those features clashed on me, flymake and eldoc. I use flymake instead of flycheck because it's built-in to Emacs so it's not another package I have to install and configure. Flymake performs syntax checking using a backend, for JavaScript that would be eslint. So if an error is found, the text is highlighted and you can navigate all the errors in a buffer and deal with each one as you go. Eldoc shows you documentation about function calls, variables and such.

The problem I ran into is that if flymake found errors on a symbol that also had documentation, the error would display for a second or two in the minibuffer then be overwritten by the eldoc documentation.

I came up with a work-around, not really a fix. In my emacs configuration I set the following:

  (setq eldoc-documentation-strategy #'eldoc-documentation-compose))

This doesn't do what I thought it would. The documentation says the following:

eldoc-documentation-compose: calls all functions in the special hook and displays all of the resulting doc strings together. Wait for all strings to be ready, and preserve their relative order as specified by the order of functions in the hook;

I thought this would take the call from flymake and combine it the the subsequent call from tide-mode which both use eldoc and just combine the messages, but this is not the case. Instead it essential disables eldoc under the point altogether. So I wanted another way to trigger the documentation, but only when I wanted it, so it would no longer conflict with errors under the point. So I made a hotkey ~~ that would trigger the documentation and it works very well. This is probably the way it should have been all along really. Here is how I created the keybind.

(use-package tide
  :if config-enable-web-mode
  :bind (("C-c C-." . tide-documentation-at-point))
  :after (typescript-mode flymake))

The bind property above is what creates the hotkey. I would love to hear from you if you have alternative ways of handling this kind of thing.

Tags: #emacs

Categories: #technology