|
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
|
| 21 | +;; Package-Version: 20191028.902 |
20 | 22 | ;; URL: https://github.com/emacs-lsp/lsp-ivy
|
21 | 23 | ;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (lsp-mode "5.0") (ivy "0.13.0"))
|
22 | 24 | ;; Version: 0.1
|
|
33 | 35 | (require 'ivy)
|
34 | 36 | (require 'dash)
|
35 | 37 | (require 'lsp-mode)
|
| 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 | + nil |
| 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 | + |
36 | 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))) |
| 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 (propertize (format "[%s]" (car type)) 'face `(:foreground ,(cdr type))))) |
41 | 120 | (if (or (null container-name) (string-empty-p container-name))
|
42 |
| - name |
43 |
| - (format "%s.%s" container-name name)))) |
| 121 | + (format "%s %s" typestr name) |
| 122 | + (format "%s %s.%s" typestr container-name name)))) |
44 | 123 |
|
45 | 124 | (defun lsp-ivy--workspace-symbol-action (candidate)
|
46 | 125 | "Jump to selected CANDIDATE."
|
|
51 | 130 | (forward-line line)
|
52 | 131 | (forward-char character)))
|
53 | 132 |
|
| 133 | +(defun lsp-ivy--filter-func (candidate) |
| 134 | + (member (gethash "kind" candidate) lsp-ivy-filter-symbol-kind)) |
| 135 | + |
54 | 136 | (defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
|
55 | 137 | "Search against WORKSPACES with PROMPT and INITIAL-INPUT."
|
56 | 138 | (let ((current-request-id nil))
|
|
68 | 150 | (plist-get request :id))
|
69 | 151 | (lsp-send-request-async
|
70 | 152 | request
|
71 |
| - #'ivy-update-candidates |
| 153 | + (lambda (result) |
| 154 | + (ivy-update-candidates (-remove 'lsp-ivy--filter-func result))) |
72 | 155 | :mode 'detached)))
|
73 | 156 | 0)
|
74 | 157 | :dynamic-collection t
|
|
0 commit comments