Skip to content

Commit 0350909

Browse files
authored
Prepare lsp-mode for :company-candidate-kind (#1995)
- company-mode is about to introduce :candidate-kind, see discussion at: company-mode/company-mode#996
1 parent 01bbdd9 commit 0350909

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

lsp-completion.el

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,38 @@ Also, additional data to attached to each candidate can be passed via PLIST."
240240
lsp-items)
241241
(-map (lambda (item) (apply #'lsp-completion--make-item item plist))))))
242242

243+
(defconst lsp-completion--kind->symbol
244+
'((1 . text)
245+
(2 . method)
246+
(3 . function)
247+
(4 . constructor)
248+
(5 . field)
249+
(6 . variable)
250+
(7 . class)
251+
(8 . interface)
252+
(9 . module)
253+
(10 . property)
254+
(11 . unit)
255+
(12 . value)
256+
(13 . enum)
257+
(14 . keyword)
258+
(15 . snippet)
259+
(16 . color)
260+
(17 . file)
261+
(18 . reference)
262+
(19 . folder)
263+
(20 . enum-member)
264+
(21 . constant)
265+
(22 . struct)
266+
(23 . event)
267+
(24 . operator)
268+
(25 . type-parameter)))
269+
270+
(defun lsp-completion--candidate-kind (item)
271+
"Return ITEM's kind."
272+
(alist-get (lsp:completion-item-kind? (get-text-property 0 'lsp-completion-item item))
273+
lsp-completion--kind->symbol))
274+
243275
(defun lsp-completion--capf-company-match (candidate)
244276
"Return highlight of typed prefix inside CANDIDATE."
245277
(let* ((prefix (downcase
@@ -406,6 +438,7 @@ Also, additional data to attached to each candidate can be passed via PLIST."
406438
;; retrieve candidates
407439
(t (funcall all-completions))))
408440
:annotation-function #'lsp-completion--annotate
441+
:company-candidate-kind #'lsp-completion--candidate-kind
409442
:company-require-match 'never
410443
:company-prefix-length
411444
(save-excursion

test/lsp-completion-test.el

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;;; lsp-completion-test.el --- lsp-completion tests -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2020 Ivan Yonchovski
4+
5+
;; Author: Ivan Yonchovski <[email protected]>
6+
;; Keywords:
7+
8+
;; This program is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation, either version 3 of the License, or
11+
;; (at your option) any later version.
12+
13+
;; This program is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
;;; Commentary:
22+
23+
;;
24+
25+
;;; Code:
26+
27+
(require 'lsp-completion)
28+
(require 'ert)
29+
30+
(ert-deftest lsp-completion-test-candidate-kind ()
31+
(should (eq (lsp-completion--candidate-kind
32+
(propertize " " 'lsp-completion-item
33+
(lsp-make-completion-item :kind 3)))
34+
'function)))
35+
36+
(provide 'lsp-completion-test)
37+
;;; lsp-completion-test.el ends here

0 commit comments

Comments
 (0)