]> git.eshelyaron.com Git - emacs.git/commit
Eglot: improve caching in eglot-completion-at-point
authorJoão Távora <joaotavora@gmail.com>
Wed, 29 Mar 2023 18:30:04 +0000 (19:30 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sun, 2 Apr 2023 22:40:46 +0000 (23:40 +0100)
commitad1efe5e675216e1f1f342fc9d48018fac718b5e
treee9bfb4aaeb3e1e40fb58024201286d53bd6c00fa
parentd00e05daa96700860dbb9dc6527105e464ffb960
Eglot: improve caching in eglot-completion-at-point

When answering the :textDocument/completion request, LSP servers
provide a :isIncomplete flag in the response, which allows Eglot to
know if "further typing should result in recomputing [the completions]
list.

If :isIncomplete is false (i.e. the full set was returned), Eglot
caches the response in a global variable eglot--capf-cache that
persists for the duration of the "completion session", taken to be the
interval between two calls to completion-in-region-mode.

If the cache has been set, and Eglot detects that "further typing" has
happened, it is safe to use the cache instead of making a request to
the server.

Thus eglot--capf-cache-flush, added to completion-in-region-mode-hook,
is used to flush this cache.  Since the popular Company completion
package doesn't use completion-in-region-mode, eglot--capf-cache-flush
is also added to its company-after-completion-hook.

* lisp/progmodes/eglot.el (eglot--managed-mode): Set
'completion-in-region-mode-hook and company-after-completion-hook.
(eglot--capf-cache): New variable.
(eglot--capf-cache-flush): New function.
(eglot-completion-at-point): Rework.

* etc/EGLOT-NEWS: Update.
etc/EGLOT-NEWS
lisp/progmodes/eglot.el