-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathellsp-completion.el
76 lines (63 loc) · 2.78 KB
/
ellsp-completion.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; ellsp-completion.el --- Completion Handler -*- lexical-binding: t; -*-
;; Copyright (C) 2023-2025 Shen, Jen-Chieh
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Completion Handler.
;;
;;; Code:
(require 'company)
(require 'company-capf)
(require 'lsp-completion)
(declare-function ellsp-2str "ellsp.el")
(defun ellsp--convert-kind (kind)
"Convert company's KIND to lsp-mode's kind."
(setq kind (ellsp-2str kind))
(or (cl-position (capitalize kind) lsp-completion--item-kind :test #'equal)
lsp/completion-item-kind-text))
(defun ellsp--capf-completions ()
"Fallback completions engine is the `elisp-completion-at-point'."
(let* ((prefix (company-capf 'prefix))
(candidates (company-capf 'candidates prefix)))
(mapcar (lambda (candidate)
(lsp-make-completion-item
:label candidate
;; XXX: The documentation take so much performance, so it's
;; currently disabled! Hopefully, I am able to figure this out
;; in the future!
;;:documentation? (or (ignore-errors (documentation (intern candidate)))
;; "No documentation")
:deprecated? (if (null (company-capf 'deprecated candidate))
json-false
t)
:kind? (ellsp--convert-kind (company-capf 'kind candidate))))
candidates)))
(defun ellsp--handle-textDocument/completion (id params)
"Handle method `textDocument/completion'."
(-let* (((&CompletionParams :text-document (&TextDocumentIdentifier :uri)
:position (&Position :line :character))
params)
(file (lsp--uri-to-path uri))
(buffer (ellsp-get-buffer ellsp-workspace file)))
(when buffer
(with-current-buffer buffer
(goto-char (point-min))
(forward-line line)
(forward-char character)
(lsp--make-response
id
(lsp-make-completion-list
:is-incomplete json-false
:items (apply #'vector (ellsp--capf-completions))))))))
(provide 'ellsp-completion)
;;; ellsp-completion.el ends here