Skip to content

Fix lsp-ui-doc-mode non-idempotency#798

Open
radon-at-beeper wants to merge 1 commit intoemacs-lsp:masterfrom
radon-at-beeper:rr-idempotent-mode
Open

Fix lsp-ui-doc-mode non-idempotency#798
radon-at-beeper wants to merge 1 commit intoemacs-lsp:masterfrom
radon-at-beeper:rr-idempotent-mode

Conversation

@radon-at-beeper
Copy link

Per https://www.gnu.org/software/emacs/manual/html_node/elisp/Minor-Mode-Conventions.html:

Enabling or disabling a minor mode twice in direct succession should not fail and should do the same thing as enabling or disabling it only once. In other words, the minor mode command should be idempotent.

The existing implementation of lsp-ui-doc-mode was not idempotent. The first time it was enabled, it ran lsp-ui-doc--setup-mouse, which invoked:

(setq lsp-ui-doc--mouse-tracked-by-us (not track-mouse))
(setq-local track-mouse t)

The second time it was enabled, it did the same thing, but now track-mouse was already non-nil, making lsp-ui-doc--mouse-tracked-by-us nil, even though lsp-ui-doc was in fact tracking the mouse. As a consequence, lsp-ui-doc--disable-mouse-on-prefix stopped functioning, causing a bug similar to #795, where if you typed a prefix key such as C-x and then moved the mouse (in a buffer where lsp-ui-doc-mode was enabled) it would abort the key sequence.

You might not expect this sequence of events to come up commonly, but the default configuration of lsp-mode (or at least the one running in my config) apparently invokes (lsp-ui-doc-mode 1) three separate times when setting up a new buffer. I don't know why. But this caused the prefix bug to trigger universally for me.

I resolved the issue by adding a second mode variable for tracking whether or not lsp-ui-doc--setup-mouse needs to be run again. There may be additional idempotency issues, but this resolves one of them, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant