|
15 | 15 | ;; You should have received a copy of the GNU General Public License
|
16 | 16 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
17 | 17 |
|
18 |
| -;; Author: Sebastian Sturm |
| 18 | +;; Authors: Sebastian Sturm |
| 19 | +;; Oliver Rausch |
19 | 20 | ;; Keywords: languages, debug
|
20 | 21 | ;; URL: https://github.com/emacs-lsp/lsp-ivy
|
21 | 22 | ;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (lsp-mode "5.0") (ivy "0.13.0"))
|
22 |
| -;; Version: 0.1 |
| 23 | +;; Version: 0.2 |
23 | 24 | ;;
|
24 | 25 |
|
25 | 26 | ;;; Commentary:
|
|
34 | 35 | (require 'dash)
|
35 | 36 | (require 'lsp-mode)
|
36 | 37 |
|
| 38 | +(defgroup lsp-ivy nil |
| 39 | + "LSP support for ivy-based symbol completion" |
| 40 | + :group 'lsp-mode) |
| 41 | + |
| 42 | +(defcustom lsp-ivy-show-symbol-kind |
| 43 | + t |
| 44 | + "Whether to show the symbol's kind when showing lsp symbols" |
| 45 | + :group 'lsp-ivy |
| 46 | + :type 'boolean) |
| 47 | + |
| 48 | +(defcustom lsp-ivy-filter-symbol-kind |
| 49 | + nil |
| 50 | + "A list of LSP SymbolKind's to filter out" |
| 51 | + :group 'lsp-ivy |
| 52 | + :type '(repeat integer)) |
| 53 | + |
| 54 | +(defcustom lsp-ivy-symbol-kind-to-string |
| 55 | + [(" " . "red") ;; Unknown - 0 |
| 56 | + ("File" . "red") ;; File - 1 |
| 57 | + ("Modu" . "red") ;; Module - 2 |
| 58 | + ("Nmsp" . "red") ;; Namespace - 3 |
| 59 | + ("Pack" . "red") ;; Package - 4 |
| 60 | + ("Clss" . "red") ;; Class - 5 |
| 61 | + ("Meth" . "violet") ;; Method - 6 |
| 62 | + ("Prop" . "violet") ;; Property - 7 |
| 63 | + ("Fld " . "violet") ;; Field - 8 |
| 64 | + ("Cons" . "red") ;; Constructor - 9 |
| 65 | + ("Enum" . "red") ;; Enum - 10 |
| 66 | + ("Intf" . "red") ;; Interface - 11 |
| 67 | + ("Func" . "darkgreen") ;; Function - 12 |
| 68 | + ("Var " . "blue") ;; Variable - 13 |
| 69 | + ("Cnst" . "blue") ;; Constant - 14 |
| 70 | + ("Str " . "blue") ;; String - 15 |
| 71 | + ("Num " . "blue") ;; Number - 16 |
| 72 | + ("Bool " . "blue") ;; Boolean - 17 |
| 73 | + ("Arr " . "blue") ;; Array - 18 |
| 74 | + ("Obj " . "blue") ;; Object - 19 |
| 75 | + ("Key " . "blue") ;; Key - 20 |
| 76 | + ("Null" . "red") ;; Null - 21 |
| 77 | + ("EmMm" . "violet") ;; EnumMember - 22 |
| 78 | + ("Srct" . "red") ;; Struct - 23 |
| 79 | + ("Evnt" . "red") ;; Event - 24 |
| 80 | + ("Op " . "red") ;; Operator - 25 |
| 81 | + ("TPar" . "red")] ;; TypeParameter - 26 |
| 82 | + "A vector of 26 cons cells, where the ith cons cell contains the string representation and foreground color to use for the i+1th SymbolKind (defined in the LSP)" |
| 83 | + :group 'lsp-ivy |
| 84 | + :type '(vector |
| 85 | + (cons string color) |
| 86 | + (cons string color) |
| 87 | + (cons string color) |
| 88 | + (cons string color) |
| 89 | + (cons string color) |
| 90 | + (cons string color) |
| 91 | + (cons string color) |
| 92 | + (cons string color) |
| 93 | + (cons string color) |
| 94 | + (cons string color) |
| 95 | + (cons string color) |
| 96 | + (cons string color) |
| 97 | + (cons string color) |
| 98 | + (cons string color) |
| 99 | + (cons string color) |
| 100 | + (cons string color) |
| 101 | + (cons string color) |
| 102 | + (cons string color) |
| 103 | + (cons string color) |
| 104 | + (cons string color) |
| 105 | + (cons string color) |
| 106 | + (cons string color) |
| 107 | + (cons string color) |
| 108 | + (cons string color) |
| 109 | + (cons string color) |
| 110 | + (cons string color) |
| 111 | + (cons string color))) |
| 112 | + |
| 113 | + |
37 | 114 | (defun lsp-ivy--format-symbol-match (match)
|
38 | 115 | "Convert the (hash-valued) MATCH returned by `lsp-mode` into a candidate string."
|
39 |
| - (let ((container-name (gethash "containerName" match)) |
40 |
| - (name (gethash "name" match))) |
41 |
| - (if (or (null container-name) (string-empty-p container-name)) |
42 |
| - name |
43 |
| - (format "%s.%s" container-name name)))) |
| 116 | + (let* ((container-name (gethash "containerName" match)) |
| 117 | + (name (gethash "name" match)) |
| 118 | + (type (elt lsp-ivy-symbol-kind-to-string (gethash "kind" match) )) |
| 119 | + (typestr (if lsp-ivy-show-symbol-kind |
| 120 | + (propertize (format "[%s] " (car type)) 'face `(:foreground ,(cdr type))) |
| 121 | + ""))) |
| 122 | + (concat typestr (if (or (null container-name) (string-empty-p container-name)) |
| 123 | + (format "%s" name) |
| 124 | + (format "%s.%s" container-name name))))) |
44 | 125 |
|
45 | 126 | (defun lsp-ivy--workspace-symbol-action (candidate)
|
46 | 127 | "Jump to selected CANDIDATE."
|
|
51 | 132 | (forward-line line)
|
52 | 133 | (forward-char character)))
|
53 | 134 |
|
| 135 | +(defun lsp-ivy--filter-func (candidate) |
| 136 | + (member (gethash "kind" candidate) lsp-ivy-filter-symbol-kind)) |
| 137 | + |
54 | 138 | (defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
|
55 | 139 | "Search against WORKSPACES with PROMPT and INITIAL-INPUT."
|
56 | 140 | (let ((current-request-id nil))
|
|
68 | 152 | (plist-get request :id))
|
69 | 153 | (lsp-send-request-async
|
70 | 154 | request
|
71 |
| - #'ivy-update-candidates |
| 155 | + (lambda (result) |
| 156 | + (ivy-update-candidates (-remove 'lsp-ivy--filter-func result))) |
72 | 157 | :mode 'detached)))
|
73 | 158 | 0)
|
74 | 159 | :dynamic-collection t
|
|
0 commit comments