mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-18 01:46:44 +00:00
Use new external-completion.el in Eglot
This refactor simplifies Eglot's source code. * lisp/progmodes/eglot.el: (Package-Requires): Require external-completion. (external-completion): Require it. (xref-backend-identifier-completion-table): Use external-completion-table. (completion-category-overrides): No longer set it. ("Backend Completion"): Delete section.
This commit is contained in:
parent
bf81df86e5
commit
fef1755736
1 changed files with 9 additions and 51 deletions
|
@ -7,7 +7,7 @@
|
|||
;; Maintainer: João Távora <joaotavora@gmail.com>
|
||||
;; URL: https://github.com/joaotavora/eglot
|
||||
;; Keywords: convenience, languages
|
||||
;; Package-Requires: ((emacs "26.3") (jsonrpc "1.0.14") (flymake "1.2.1") (project "0.3.0") (xref "1.0.1") (eldoc "1.11.0") (seq "2.23"))
|
||||
;; Package-Requires: ((emacs "26.3") (jsonrpc "1.0.14") (flymake "1.2.1") (project "0.3.0") (xref "1.0.1") (eldoc "1.11.0") (seq "2.23") (external-completion "0.1"))
|
||||
|
||||
;; This is a GNU ELPA :core package. Avoid adding functionality
|
||||
;; that is not available in the version of Emacs recorded above or any
|
||||
|
@ -110,6 +110,7 @@
|
|||
(require 'filenotify)
|
||||
(require 'ert)
|
||||
(require 'array)
|
||||
(require 'external-completion)
|
||||
|
||||
;; ElDoc is preloaded in Emacs, so `require'-ing won't guarantee we are
|
||||
;; using the latest version from GNU Elpa when we load eglot.el. Use an
|
||||
|
@ -2572,7 +2573,7 @@ If BUFFER, switch to it before."
|
|||
(let ((probe (gethash pat cache :missing)))
|
||||
(if (eq probe :missing) (puthash pat (refresh pat) cache)
|
||||
probe)))
|
||||
(lookup (pat)
|
||||
(lookup (pat _point)
|
||||
(let ((res (lookup-1 pat))
|
||||
(def (and (string= pat "") (gethash :default cache))))
|
||||
(append def res nil)))
|
||||
|
@ -2580,16 +2581,12 @@ If BUFFER, switch to it before."
|
|||
(cl-getf (get-text-property
|
||||
0 'eglot--lsp-workspaceSymbol c)
|
||||
:score 0)))
|
||||
(lambda (string _pred action)
|
||||
(pcase action
|
||||
(`metadata `(metadata
|
||||
(cycle-sort-function
|
||||
. ,(lambda (completions)
|
||||
(cl-sort completions #'> :key #'score)))
|
||||
(category . eglot-indirection-joy)))
|
||||
(`(eglot--lsp-tryc . ,point) `(eglot--lsp-tryc . (,string . ,point)))
|
||||
(`(eglot--lsp-allc . ,_point) `(eglot--lsp-allc . ,(lookup string)))
|
||||
(_ nil))))))
|
||||
(external-completion-table
|
||||
'eglot-indirection-joy
|
||||
#'lookup
|
||||
`((cycle-sort-function
|
||||
. ,(lambda (completions)
|
||||
(cl-sort completions #'> :key #'score))))))))
|
||||
|
||||
(defun eglot--recover-workspace-symbol-meta (string)
|
||||
"Search `eglot--workspace-symbols-cache' for rich entry of STRING."
|
||||
|
@ -2601,9 +2598,6 @@ If BUFFER, switch to it before."
|
|||
(setq v (cdr v))))
|
||||
eglot--workspace-symbols-cache)))
|
||||
|
||||
(add-to-list 'completion-category-overrides
|
||||
'(eglot-indirection-joy (styles . (eglot--lsp-backend-style))))
|
||||
|
||||
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot)))
|
||||
(let ((attempt
|
||||
(and (xref--prompt-p this-command)
|
||||
|
@ -3438,42 +3432,6 @@ If NOERROR, return predicate, else erroring function."
|
|||
'eglot-managed-mode-hook "1.6")
|
||||
(provide 'eglot)
|
||||
|
||||
|
||||
;;; Backend completion
|
||||
|
||||
;; Written by Stefan Monnier circa 2016. Something to move to
|
||||
;; minibuffer.el "ASAP" (with all the `eglot--lsp-' replaced by
|
||||
;; something else. The very same code already in SLY and stable for a
|
||||
;; long time.
|
||||
|
||||
;; This "completion style" delegates all the work to the "programmable
|
||||
;; completion" table which is then free to implement its own
|
||||
;; completion style. Typically this is used to take advantage of some
|
||||
;; external tool which already has its own completion system and
|
||||
;; doesn't give you efficient access to the prefix completion needed
|
||||
;; by other completion styles. The table should recognize the symbols
|
||||
;; 'eglot--lsp-tryc and 'eglot--lsp-allc as ACTION, reply with
|
||||
;; (eglot--lsp-tryc COMP...) or (eglot--lsp-allc . (STRING . POINT)),
|
||||
;; accordingly. tryc/allc names made akward/recognizable on purpose.
|
||||
|
||||
(add-to-list 'completion-styles-alist
|
||||
'(eglot--lsp-backend-style
|
||||
eglot--lsp-backend-style-try-completion
|
||||
eglot--lsp-backend-style-all-completions
|
||||
"Ad-hoc completion style provided by the completion table."))
|
||||
|
||||
(defun eglot--lsp-backend-style-call (op string table pred point)
|
||||
(when (functionp table)
|
||||
(let ((res (funcall table string pred (cons op point))))
|
||||
(when (eq op (car-safe res))
|
||||
(cdr res)))))
|
||||
|
||||
(defun eglot--lsp-backend-style-try-completion (string table pred point)
|
||||
(eglot--lsp-backend-style-call 'eglot--lsp-tryc string table pred point))
|
||||
|
||||
(defun eglot--lsp-backend-style-all-completions (string table pred point)
|
||||
(eglot--lsp-backend-style-call 'eglot--lsp-allc string table pred point))
|
||||
|
||||
|
||||
;; Local Variables:
|
||||
;; bug-reference-bug-regexp: "\\(github#\\([0-9]+\\)\\)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue