diff options
| -rw-r--r-- | lisp/progmodes/eglot.el | 60 |
1 files changed, 9 insertions, 51 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index c266f6e18a3..97a4f261c61 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | ;; Maintainer: João Távora <joaotavora@gmail.com> | 7 | ;; Maintainer: João Távora <joaotavora@gmail.com> |
| 8 | ;; URL: https://github.com/joaotavora/eglot | 8 | ;; URL: https://github.com/joaotavora/eglot |
| 9 | ;; Keywords: convenience, languages | 9 | ;; Keywords: convenience, languages |
| 10 | ;; 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")) | 10 | ;; 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")) |
| 11 | 11 | ||
| 12 | ;; This is a GNU ELPA :core package. Avoid adding functionality | 12 | ;; This is a GNU ELPA :core package. Avoid adding functionality |
| 13 | ;; that is not available in the version of Emacs recorded above or any | 13 | ;; that is not available in the version of Emacs recorded above or any |
| @@ -110,6 +110,7 @@ | |||
| 110 | (require 'filenotify) | 110 | (require 'filenotify) |
| 111 | (require 'ert) | 111 | (require 'ert) |
| 112 | (require 'array) | 112 | (require 'array) |
| 113 | (require 'external-completion) | ||
| 113 | 114 | ||
| 114 | ;; ElDoc is preloaded in Emacs, so `require'-ing won't guarantee we are | 115 | ;; ElDoc is preloaded in Emacs, so `require'-ing won't guarantee we are |
| 115 | ;; using the latest version from GNU Elpa when we load eglot.el. Use an | 116 | ;; using the latest version from GNU Elpa when we load eglot.el. Use an |
| @@ -2571,7 +2572,7 @@ If BUFFER, switch to it before." | |||
| 2571 | (let ((probe (gethash pat cache :missing))) | 2572 | (let ((probe (gethash pat cache :missing))) |
| 2572 | (if (eq probe :missing) (puthash pat (refresh pat) cache) | 2573 | (if (eq probe :missing) (puthash pat (refresh pat) cache) |
| 2573 | probe))) | 2574 | probe))) |
| 2574 | (lookup (pat) | 2575 | (lookup (pat _point) |
| 2575 | (let ((res (lookup-1 pat)) | 2576 | (let ((res (lookup-1 pat)) |
| 2576 | (def (and (string= pat "") (gethash :default cache)))) | 2577 | (def (and (string= pat "") (gethash :default cache)))) |
| 2577 | (append def res nil))) | 2578 | (append def res nil))) |
| @@ -2579,16 +2580,12 @@ If BUFFER, switch to it before." | |||
| 2579 | (cl-getf (get-text-property | 2580 | (cl-getf (get-text-property |
| 2580 | 0 'eglot--lsp-workspaceSymbol c) | 2581 | 0 'eglot--lsp-workspaceSymbol c) |
| 2581 | :score 0))) | 2582 | :score 0))) |
| 2582 | (lambda (string _pred action) | 2583 | (external-completion-table |
| 2583 | (pcase action | 2584 | 'eglot-indirection-joy |
| 2584 | (`metadata `(metadata | 2585 | #'lookup |
| 2585 | (cycle-sort-function | 2586 | `((cycle-sort-function |
| 2586 | . ,(lambda (completions) | 2587 | . ,(lambda (completions) |
| 2587 | (cl-sort completions #'> :key #'score))) | 2588 | (cl-sort completions #'> :key #'score)))))))) |
| 2588 | (category . eglot-indirection-joy))) | ||
| 2589 | (`(eglot--lsp-tryc . ,point) `(eglot--lsp-tryc . (,string . ,point))) | ||
| 2590 | (`(eglot--lsp-allc . ,_point) `(eglot--lsp-allc . ,(lookup string))) | ||
| 2591 | (_ nil)))))) | ||
| 2592 | 2589 | ||
| 2593 | (defun eglot--recover-workspace-symbol-meta (string) | 2590 | (defun eglot--recover-workspace-symbol-meta (string) |
| 2594 | "Search `eglot--workspace-symbols-cache' for rich entry of STRING." | 2591 | "Search `eglot--workspace-symbols-cache' for rich entry of STRING." |
| @@ -2600,9 +2597,6 @@ If BUFFER, switch to it before." | |||
| 2600 | (setq v (cdr v)))) | 2597 | (setq v (cdr v)))) |
| 2601 | eglot--workspace-symbols-cache))) | 2598 | eglot--workspace-symbols-cache))) |
| 2602 | 2599 | ||
| 2603 | (add-to-list 'completion-category-overrides | ||
| 2604 | '(eglot-indirection-joy (styles . (eglot--lsp-backend-style)))) | ||
| 2605 | |||
| 2606 | (cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot))) | 2600 | (cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot))) |
| 2607 | (let ((attempt | 2601 | (let ((attempt |
| 2608 | (and (xref--prompt-p this-command) | 2602 | (and (xref--prompt-p this-command) |
| @@ -3437,42 +3431,6 @@ If NOERROR, return predicate, else erroring function." | |||
| 3437 | 'eglot-managed-mode-hook "1.6") | 3431 | 'eglot-managed-mode-hook "1.6") |
| 3438 | (provide 'eglot) | 3432 | (provide 'eglot) |
| 3439 | 3433 | ||
| 3440 | |||
| 3441 | ;;; Backend completion | ||
| 3442 | |||
| 3443 | ;; Written by Stefan Monnier circa 2016. Something to move to | ||
| 3444 | ;; minibuffer.el "ASAP" (with all the `eglot--lsp-' replaced by | ||
| 3445 | ;; something else. The very same code already in SLY and stable for a | ||
| 3446 | ;; long time. | ||
| 3447 | |||
| 3448 | ;; This "completion style" delegates all the work to the "programmable | ||
| 3449 | ;; completion" table which is then free to implement its own | ||
| 3450 | ;; completion style. Typically this is used to take advantage of some | ||
| 3451 | ;; external tool which already has its own completion system and | ||
| 3452 | ;; doesn't give you efficient access to the prefix completion needed | ||
| 3453 | ;; by other completion styles. The table should recognize the symbols | ||
| 3454 | ;; 'eglot--lsp-tryc and 'eglot--lsp-allc as ACTION, reply with | ||
| 3455 | ;; (eglot--lsp-tryc COMP...) or (eglot--lsp-allc . (STRING . POINT)), | ||
| 3456 | ;; accordingly. tryc/allc names made akward/recognizable on purpose. | ||
| 3457 | |||
| 3458 | (add-to-list 'completion-styles-alist | ||
| 3459 | '(eglot--lsp-backend-style | ||
| 3460 | eglot--lsp-backend-style-try-completion | ||
| 3461 | eglot--lsp-backend-style-all-completions | ||
| 3462 | "Ad-hoc completion style provided by the completion table.")) | ||
| 3463 | |||
| 3464 | (defun eglot--lsp-backend-style-call (op string table pred point) | ||
| 3465 | (when (functionp table) | ||
| 3466 | (let ((res (funcall table string pred (cons op point)))) | ||
| 3467 | (when (eq op (car-safe res)) | ||
| 3468 | (cdr res))))) | ||
| 3469 | |||
| 3470 | (defun eglot--lsp-backend-style-try-completion (string table pred point) | ||
| 3471 | (eglot--lsp-backend-style-call 'eglot--lsp-tryc string table pred point)) | ||
| 3472 | |||
| 3473 | (defun eglot--lsp-backend-style-all-completions (string table pred point) | ||
| 3474 | (eglot--lsp-backend-style-call 'eglot--lsp-allc string table pred point)) | ||
| 3475 | |||
| 3476 | 3434 | ||
| 3477 | ;; Local Variables: | 3435 | ;; Local Variables: |
| 3478 | ;; bug-reference-bug-regexp: "\\(github#\\([0-9]+\\)\\)" | 3436 | ;; bug-reference-bug-regexp: "\\(github#\\([0-9]+\\)\\)" |