[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa ea82b4b 57/71: Close #505: ensure completion termi
From: |
João Távora |
Subject: |
[elpa] externals/elpa ea82b4b 57/71: Close #505: ensure completion terminates in correct buffer |
Date: |
Wed, 16 Dec 2020 11:42:26 -0500 (EST) |
branch: externals/elpa
commit ea82b4bb746e45d9d48c738294f8e84598aff502
Author: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
Commit: João Távora <joaotavora@gmail.com>
Close #505: ensure completion terminates in correct buffer
To design a completion-in-region-function replacement that leverages
the elements in completion-at-point-functions, we must ensure that
their :exit-function parts execute in the correct buffer. That is the
buffer where the text to be completed lives, not necessarily the
buffer being used for user interaction.
Later on, this guarantee should be provided by Emacs itself, perhaps
by putting the correct with-current-buffer call in completion--done.
Copyright-paperwork-exempt: yes
Co-authored-by: João Távora <joaotavora@gmail.com>
* eglot.el (eglot-completion-at-point): Ensure :exit-function's
buffer is where the source is.
---
eglot.el | 86 +++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 47 insertions(+), 39 deletions(-)
diff --git a/eglot.el b/eglot.el
index c0f3143..0b23337 100644
--- a/eglot.el
+++ b/eglot.el
@@ -2175,45 +2175,53 @@ is not active."
(line-beginning-position))))
:exit-function
(lambda (proxy _status)
- (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)))))))
+ ;; 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/elpa e7a43e2 40/71: Fix #480: also consider label of a CompletionItem for snippets, (continued)
- [elpa] externals/elpa e7a43e2 40/71: Fix #480: also consider label of a CompletionItem for snippets, João Távora, 2020/12/16
- [elpa] externals/elpa a807b4f 43/71: Some test-related cleanup, João Távora, 2020/12/16
- [elpa] externals/elpa 9874456 42/71: Close #482: use filter-buffer-substring to get buffer text, João Távora, 2020/12/16
- [elpa] externals/elpa b34447c 45/71: Close #473: simplify eglot-code-actions, João Távora, 2020/12/16
- [elpa] externals/elpa a044dec 47/71: Delegate "hover" and "signature" doc synchronization efforts to Eldoc, João Távora, 2020/12/16
- [elpa] externals/elpa a04b826 48/71: Update tests after update to newer Eldoc, João Távora, 2020/12/16
- [elpa] externals/elpa 2b7ec0e 51/71: Expect eglot-multiline-eldoc to fail on Travis, João Távora, 2020/12/16
- [elpa] externals/elpa 6d96601 52/71: Closes #509: fix sorting of completion items, João Távora, 2020/12/16
- [elpa] externals/elpa 4e82f53 53/71: Reload Eldoc if needed on Emacs < 28, João Távora, 2020/12/16
- [elpa] externals/elpa 8c9219d 55/71: Unbreak tests after changes to eldoc.el, João Távora, 2020/12/16
- [elpa] externals/elpa ea82b4b 57/71: Close #505: ensure completion terminates in correct buffer,
João Távora <=
- [elpa] externals/elpa fb6b17e 58/71: New 'make interactive' target for debuggable M-x ert, João Távora, 2020/12/16
- [elpa] externals/elpa 5f873d2 60/71: Fix #521: Correct paren mismatch blunder introduced by earlier commit, João Távora, 2020/12/16
- [elpa] externals/elpa 209b227 61/71: Fix #524: provide suitable default to M-x eglot-rename, João Távora, 2020/12/16
- [elpa] externals/elpa 61b71ea 62/71: Fix #528: unbreak Haskell's hie-wrapper built-in incantation, João Távora, 2020/12/16
- [elpa] externals/elpa af0e876 68/71: Close #572: use haskell-language-server in eglot-server-programs, João Távora, 2020/12/16
- [elpa] externals/elpa 476c586 69/71: Cosmetic whitespace fix (indentation, long lines, tabs->spaces), João Távora, 2020/12/16
- [elpa] externals/elpa 265b486 70/71: Fix #569: allow Eglot to stay out of Xref configuration, João Távora, 2020/12/16
- [elpa] externals/elpa 4edd478 71/71: Bump Eglot version to 1.7, João Távora, 2020/12/16