Skip to content

Commit

Permalink
Add support for TextEdits in completion
Browse files Browse the repository at this point in the history
* eglot.el (eglot-completion-at-point): Apply the CompletionItem's
  :textEdit and :additionalTextEdits when they're present.
  • Loading branch information
mkcms committed Nov 13, 2018
1 parent 1b582c1 commit 7307481
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lisp/progmodes/eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1584,12 +1584,23 @@ is not active."
(cl-find comp strings :test #'string=))))
(cl-destructuring-bind (&key insertTextFormat
insertText
textEdit
additionalTextEdits
&allow-other-keys)
(text-properties-at 0 comp)
(when-let ((fn (and (eql insertTextFormat 2)
(eglot--snippet-expansion-fn))))
(delete-region (- (point) (length comp)) (point))
(funcall fn insertText))
(let ((fn (and (eql insertTextFormat 2)
(eglot--snippet-expansion-fn))))
(when (or fn textEdit)
;; Undo the completion
(delete-region (- (point) (length comp)) (point)))
(cond (textEdit
(cl-destructuring-bind (&key range newText) textEdit
(pcase-let ((`(,beg . ,end) (eglot--range-region range)))
(delete-region beg end)
(goto-char beg)
(funcall (or fn #'insert) newText)))
(eglot--apply-text-edits additionalTextEdits))
(fn (funcall fn insertText))))
(eglot--signal-textDocument/didChange)
(eglot-eldoc-function))))))))

Expand Down

0 comments on commit 7307481

Please sign in to comment.