From ad1efe5e675216e1f1f342fc9d48018fac718b5e Mon Sep 17 00:00:00 2001 From: João Távora Date: Wed, 29 Mar 2023 19:30:04 +0100 Subject: 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'etc') diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index dd04e677285..09772a1e71a 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS @@ -17,6 +17,28 @@ This refers to https://github.com/joaotavora/eglot/issues/. That is, to look up issue github#1234, go to https://github.com/joaotavora/eglot/issues/1234. + +* Changes in upcoming Eglot 1.14 + +** Faster, more responsive completion + +Eglot takes advantage of LSP's "isIncomplete" flag in responses to +completion requests to drive new completion-caching mechanism for the +duration of each completion session. Once a full set of completions +is obtained for a given position, the server needn't be contacted in +many scenarios, resulting in significantly less communication +overhead. This works with the popular Company package and stock +completion-at-point interfaces. + +A variable 'eglot-cache-session-completions', t by default, controls +this. The mechanism was tested with ccls, jdtls, pylsp, golsp and +clangd. Notably, the C/C++ language server Clangd version 15 has a +bug in its "isIcomplete" flag (it is fixed in later versions). If you +run into problems, disable this mechanism like so: + +(add-hook 'c-common-mode-hook + (lambda () (setq-local eglot-cache-session-completions nil))) + * Changes in Eglot 1.13 (15/03/2023) -- cgit v1.2.3