[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot d00dfe3 08/49: Fix #592: run exit-function only f
From: |
Stefan Monnier |
Subject: |
[elpa] externals/eglot d00dfe3 08/49: Fix #592: run exit-function only for finished completion |
Date: |
Wed, 17 Mar 2021 18:41:43 -0400 (EDT) |
branch: externals/eglot
commit d00dfe3de9f484233840ca17501a347ad653b6e3
Author: Andrii Kolomoiets <andreyk.mad@gmail.com>
Commit: GitHub <noreply@github.com>
Fix #592: run exit-function only for finished completion
Per #594.
* eglot.el (eglot-completion-at-point): Respect 'status' argument in
completion's exit function.
---
eglot.el | 100 +++++++++++++++++++++++++++++++++------------------------------
1 file changed, 52 insertions(+), 48 deletions(-)
diff --git a/eglot.el b/eglot.el
index b8db7f9..0447bc8 100644
--- a/eglot.el
+++ b/eglot.el
@@ -2203,54 +2203,58 @@ is not active."
(cl-coerce (cl-getf completion-capability :triggerCharacters)
'list))
(line-beginning-position))))
:exit-function
- (lambda (proxy _status)
- ;; To assist in using this whole `completion-at-point'
- ;; function inside `completion-in-region', ensure the exit
- ;; function runs in the buffer where the completion was
- ;; triggered from. This should probably be in Emacs itself.
- ;; (github#505)
- (with-current-buffer (if (minibufferp)
- (window-buffer (minibuffer-selected-window))
- (current-buffer))
- (eglot--dbind ((CompletionItem) insertTextFormat
- insertText textEdit additionalTextEdits label)
- (funcall
- resolve-maybe
- (or (get-text-property 0 'eglot--lsp-item proxy)
- ;; When selecting from the *Completions*
- ;; buffer, `proxy' won't have any properties.
- ;; A lookup should fix that (github#148)
- (get-text-property
- 0 'eglot--lsp-item
- (cl-find proxy (funcall proxies) :test #'string=))))
- (let ((snippet-fn (and (eql insertTextFormat 2)
- (eglot--snippet-expansion-fn))))
- (cond (textEdit
- ;; Undo (yes, undo) the newly inserted completion.
- ;; If before completion the buffer was "foo.b" and
- ;; now is "foo.bar", `proxy' will be "bar". We
- ;; want to delete only "ar" (`proxy' minus the
- ;; symbol whose bounds we've calculated before)
- ;; (github#160).
- (delete-region (+ (- (point) (length proxy))
- (if bounds (- (cdr bounds) (car
bounds)) 0))
- (point))
- (eglot--dbind ((TextEdit) range newText) textEdit
- (pcase-let ((`(,beg . ,end) (eglot--range-region
range)))
- (delete-region beg end)
- (goto-char beg)
- (funcall (or snippet-fn #'insert) newText)))
- (when (cl-plusp (length additionalTextEdits))
- (eglot--apply-text-edits additionalTextEdits)))
- (snippet-fn
- ;; A snippet should be inserted, but using plain
- ;; `insertText'. This requires us to delete the
- ;; whole completion, since `insertText' is the full
- ;; completion's text.
- (delete-region (- (point) (length proxy)) (point))
- (funcall snippet-fn (or insertText label)))))
- (eglot--signal-textDocument/didChange)
- (eldoc))))))))
+ (lambda (proxy status)
+ (when (eq status 'finished)
+ ;; To assist in using this whole `completion-at-point'
+ ;; function inside `completion-in-region', ensure the exit
+ ;; function runs in the buffer where the completion was
+ ;; triggered from. This should probably be in Emacs itself.
+ ;; (github#505)
+ (with-current-buffer (if (minibufferp)
+ (window-buffer
(minibuffer-selected-window))
+ (current-buffer))
+ (eglot--dbind ((CompletionItem) insertTextFormat
+ insertText textEdit additionalTextEdits label)
+ (funcall
+ resolve-maybe
+ (or (get-text-property 0 'eglot--lsp-item proxy)
+ ;; When selecting from the *Completions*
+ ;; buffer, `proxy' won't have any properties.
+ ;; A lookup should fix that (github#148)
+ (get-text-property
+ 0 'eglot--lsp-item
+ (cl-find proxy (funcall proxies) :test #'string=))))
+ (let ((snippet-fn (and (eql insertTextFormat 2)
+ (eglot--snippet-expansion-fn))))
+ (cond (textEdit
+ ;; Undo (yes, undo) the newly inserted completion.
+ ;; If before completion the buffer was "foo.b" and
+ ;; now is "foo.bar", `proxy' will be "bar". We
+ ;; want to delete only "ar" (`proxy' minus the
+ ;; symbol whose bounds we've calculated before)
+ ;; (github#160).
+ (delete-region (+ (- (point) (length proxy))
+ (if bounds
+ (- (cdr bounds) (car bounds))
+ 0))
+ (point))
+ (eglot--dbind ((TextEdit) range newText) textEdit
+ (pcase-let ((`(,beg . ,end)
+ (eglot--range-region range)))
+ (delete-region beg end)
+ (goto-char beg)
+ (funcall (or snippet-fn #'insert) newText)))
+ (when (cl-plusp (length additionalTextEdits))
+ (eglot--apply-text-edits additionalTextEdits)))
+ (snippet-fn
+ ;; A snippet should be inserted, but using plain
+ ;; `insertText'. This requires us to delete the
+ ;; whole completion, since `insertText' is the full
+ ;; completion's text.
+ (delete-region (- (point) (length proxy)) (point))
+ (funcall snippet-fn (or insertText label)))))
+ (eglot--signal-textDocument/didChange)
+ (eldoc)))))))))
(defun eglot--hover-info (contents &optional range)
(let ((heading (and range (pcase-let ((`(,beg . ,end) (eglot--range-region
range)))
- [elpa] externals/eglot 51f1320 09/49: Skip downloading GNU ELPA deps on make check by default, (continued)
- [elpa] externals/eglot 51f1320 09/49: Skip downloading GNU ELPA deps on make check by default, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 6370a1c 10/49: Fix some of eglot-tests.el for new Eldoc library, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 8761f86 11/49: Unbreak eglot-dcase test, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 0c4daa4 13/49: Fix #531: mention M-x eldoc as preferred documentation command, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot e5a9648 07/49: Fix #513: use `path-separator', not ":", in Eclipse/JDT custom code, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot e6ca70c 14/49: Close #599: add rnix-lsp server for nix-mode, community suggestion, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 1f2b024 23/49: Close #605: Support activeParameter property for SignatureInformation, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 2fc0db8 33/49: Fix #467: make eglot-ignored-server-capabilites defcustom a set, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 1a54fc0 40/49: Per #627: URIfy better, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 7f2e680 38/49: Fix #627: handle empty actions array in window/showMessageRequest, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot d00dfe3 08/49: Fix #592: run exit-function only for finished completion,
Stefan Monnier <=
- [elpa] externals/eglot 8305eed 18/49: * eglot.el (eglot): Tweak docstring grammar., Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 50b0e84 22/49: Fix #602: fully handle LSP glob syntax, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 550ffc2 34/49: Per #602: tweak glob-parsing grammar, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 133c25e 24/49: Close #613: explicitly require seq.el, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot a43289e 25/49: Fix #616: also override global flymake-diagnostic-functions, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot fc4c324 29/49: Fix #567: update elixir-ls link in README.md, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 7918fac 43/49: Close #637: Add TRAMP support, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 33e83ba 44/49: Fix #638: convert colon to hex in URI, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot bf4a7aa 31/49: Fix #406: mention eglot-stay-out-of in README.md, Stefan Monnier, 2021/03/17
- [elpa] externals/eglot 65aadca 46/49: Fix #620: simplify eglot--apply-workspace-edit, Stefan Monnier, 2021/03/17