[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot f5151be 67/69: Don't immediately request completi
From: |
João Távora |
Subject: |
[elpa] externals/eglot f5151be 67/69: Don't immediately request completions in eglot-completion-at-point |
Date: |
Sun, 20 Oct 2019 08:21:55 -0400 (EDT) |
branch: externals/eglot
commit f5151be46d9bcfcd3a524cfc3fc6c6a34587264f
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Don't immediately request completions in eglot-completion-at-point
Yet another adjustment to this function. According to the
documentation of completion-at-point-functions, we should strive to
make functions like eglot-completion-at-point "cheap to run".
Requesting completion from the server immediately after calling the
function goes against that. The reason we were doing it is that it
might have helped compute more accurate "bounds" for the return value
(START and END) from possible TextEdit completion items. But I've
decided it's not worth the effort, at least for now.
* eglot.el (eglot-completion-at-point): Request completions
asynchronously.
---
eglot.el | 70 ++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 35 insertions(+), 35 deletions(-)
diff --git a/eglot.el b/eglot.el
index cba8c34..09c1461 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1889,47 +1889,46 @@ is not active."
(or (get-text-property 0 :sortText a)
"")
(or (get-text-property 0 :sortText b)
""))))))
(metadata `(metadata . ((display-sort-function .
,sort-completions))))
- (response (jsonrpc-request server
- :textDocument/completion
- (eglot--CompletionParams)
- :deferred :textDocument/completion
- :cancel-on-input t))
- (items (append ; coerce to list
- (if (vectorp response) response (plist-get response :items))
- nil))
+ resp items (cached-proxies :none)
(proxies
- (mapcar (jsonrpc-lambda
- (&rest item &key label insertText insertTextFormat
- &allow-other-keys)
- (let ((proxy
- (cond ((and (eql insertTextFormat 2)
- (eglot--snippet-expansion-fn))
- (string-trim-left label))
- (t
- (or insertText (string-trim-left
label))))))
- (unless (zerop (length proxy))
- (put-text-property 0 1 'eglot--lsp-item item proxy))
- proxy))
- items))
- (bounds
- (cl-loop with probe =
- (plist-get (plist-get (car items) :textEdit) :range)
- for item in (cdr items)
- for range = (plist-get (plist-get item :textEdit) :range)
- unless (and range (equal range probe))
- return (bounds-of-thing-at-point 'symbol)
- finally (cl-return (or (and probe
- (eglot--range-region probe))
- (bounds-of-thing-at-point
'symbol))))))
+ (lambda ()
+ (if (listp cached-proxies) cached-proxies
+ (setq resp
+ (jsonrpc-request server
+ :textDocument/completion
+ (eglot--CompletionParams)
+ :deferred :textDocument/completion
+ :cancel-on-input t))
+ (setq items (append
+ (if (vectorp resp) resp (plist-get resp :items))
+ nil))
+ (setq cached-proxies
+ (mapcar
+ (jsonrpc-lambda
+ (&rest item &key label insertText insertTextFormat
+ &allow-other-keys)
+ (let ((proxy
+ (cond ((and (eql insertTextFormat 2)
+ (eglot--snippet-expansion-fn))
+ (string-trim-left label))
+ (t
+ (or insertText (string-trim-left
label))))))
+ (unless (zerop (length item))
+ (put-text-property 0 1 'eglot--lsp-item item
proxy))
+ proxy))
+ items)))))
+ (bounds (bounds-of-thing-at-point 'symbol)))
(list
(or (car bounds) (point))
(or (cdr bounds) (point))
(lambda (probe pred action)
(cond
((eq action 'metadata) metadata) ; metadata
- ((eq action 'lambda) (member probe proxies)) ; test-completion
+ ((eq action 'lambda) ; test-completion
+ (member probe (funcall proxies)))
((eq (car-safe action) 'boundaries) nil) ; boundaries
- ((and (null action) (member probe proxies) t)) ; try-completion
+ ((and (null action) ; try-completion
+ (member probe (funcall proxies)) t))
((eq action t) ; all-completions
(cl-remove-if-not
(lambda (proxy)
@@ -1938,7 +1937,7 @@ is not active."
(and (or (null pred) (funcall pred proxy))
(string-prefix-p
probe (or filterText proxy) completion-ignore-case))))
- proxies))))
+ (funcall proxies)))))
:annotation-function
(lambda (proxy)
(eglot--dbind ((CompletionItem) detail kind insertTextFormat)
@@ -1993,7 +1992,8 @@ is not active."
;; buffer, `proxy' won't have any properties. A
;; lookup should fix that (github#148)
(get-text-property
- 0 'eglot--lsp-item (cl-find proxy proxies :test #'string=)))
+ 0 'eglot--lsp-item
+ (cl-find proxy (funcall proxies) :test #'string=)))
(let ((snippet-fn (and (eql insertTextFormat 2)
(eglot--snippet-expansion-fn))))
(cond (textEdit
- [elpa] externals/eglot 124a833 56/69: Add a test for #311 and #279, (continued)
- [elpa] externals/eglot 124a833 56/69: Add a test for #311 and #279, João Távora, 2019/10/20
- [elpa] externals/eglot d774754 37/69: Merge pull request #298 from jorams/nil-capabilities-as-false, João Távora, 2019/10/20
- [elpa] externals/eglot 20195e5 42/69: On buffer kill, first send didClose then teardown local structures, João Távora, 2019/10/20
- [elpa] externals/eglot 5a98c5a 55/69: Fix eglot-completion-at-point to work with bare completion-at-point, João Távora, 2019/10/20
- [elpa] externals/eglot 6a7ce66 32/69: Expand directory watcher globs containing ** (#293), João Távora, 2019/10/20
- [elpa] externals/eglot f45fdc6 31/69: Fix invalid guess for php language Server (#288), João Távora, 2019/10/20
- [elpa] externals/eglot 05c68c2 45/69: Don't send dummy JSON object in "initialized" notification (#312), João Távora, 2019/10/20
- [elpa] externals/eglot bff921e 60/69: Per #319: always filter completions client-side by prefix, João Távora, 2019/10/20
- [elpa] externals/eglot 260f152 65/69: Fix #321: don't choke on single-location reply to tD/definition, João Távora, 2019/10/20
- [elpa] externals/eglot 8a17c29 61/69: Close #235: play along with LSP's filterText hacks, João Távora, 2019/10/20
- [elpa] externals/eglot f5151be 67/69: Don't immediately request completions in eglot-completion-at-point,
João Távora <=
- [elpa] externals/eglot 74240c7 66/69: Protect against zero-length completions, João Távora, 2019/10/20