33
33
34
34
(require 'ivy )
35
35
(require 'dash )
36
+
37
+ (require 'lsp-protocol )
36
38
(require 'lsp-mode )
37
39
38
40
(defgroup lsp-ivy nil
41
43
42
44
(defcustom lsp-ivy-show-symbol-kind
43
45
t
44
- " Whether to show the symbol's kind when showing lsp symbols"
46
+ " Whether to show the symbol's kind when showing lsp symbols. "
45
47
:group 'lsp-ivy
46
48
:type 'boolean )
47
49
48
50
(defcustom lsp-ivy-filter-symbol-kind
49
51
nil
50
- " A list of LSP SymbolKind's to filter out"
52
+ " A list of LSP SymbolKind's to filter out. "
51
53
:group 'lsp-ivy
52
54
:type '(repeat integer))
53
55
79
81
(" Evnt" . font-lock-builtin-face ) ; ; Event - 24
80
82
(" Op " . font-lock-function-name-face ) ; ; Operator - 25
81
83
(" TPar" . font-lock-type-face )] ; ; TypeParameter - 26
82
- " A vector of 26 cons cells, where the ith cons cell contains the string representation and face to use for the i+1th SymbolKind (defined in the LSP)"
84
+ " A vector of 26 cons cells, where the ith cons cell contains the string representation and face to use for the i+1th SymbolKind (defined in the LSP). "
83
85
:group 'lsp-ivy
84
86
:type '(vector
85
87
(cons string face)
111
113
(cons string face)))
112
114
113
115
114
- (defun lsp-ivy--format-symbol-match (match )
115
- " Convert the MATCH returned by `lsp-mode` into a candidate string.
116
- MATCH is a cons cell whose cdr is the hash-table from `lsp-mode`."
117
- (let* ((match (cdr match ))
118
- (container-name (gethash " containerName" match ))
119
- (name (gethash " name" match ))
120
- (type (elt lsp-ivy-symbol-kind-to-face (gethash " kind" match ) ))
121
- (typestr (if lsp-ivy-show-symbol-kind
122
- (propertize (format " [%s ] " (car type)) 'face (cdr type))
123
- " " )))
124
- (concat typestr (if (or (null container-name) (string-empty-p container-name))
116
+ (defun lsp-ivy--format-symbol-match (symbol-information-match )
117
+ " Convert the match returned by `lsp-mode` into a candidate string.
118
+ SYMBOL-INFORMATION-MATCH is a cons cell whose cdr is the SymbolInformation interface from `lsp-mode`."
119
+ (-let* (((&SymbolInformation :name :kind :container-name? ) (cdr symbol-information-match))
120
+ (type (elt lsp-ivy-symbol-kind-to-face kind))
121
+ (typestr (if lsp-ivy-show-symbol-kind
122
+ (propertize (format " [%s ] " (car type)) 'face (cdr type))
123
+ " " )))
124
+ (concat typestr (if (or (null container-name?) (string-empty-p container-name?) )
125
125
(format " %s " name)
126
- (format " %s .%s " container-name name)))))
127
-
128
- (defun lsp-ivy--workspace-symbol-action (candidate )
129
- " Jump to selected CANDIDATE, a cons cell whose cdr is a hash table."
130
- (-let* ((candidate (cdr candidate))
131
- ((&hash " uri" " range" (&hash " start" (&hash " line" " character" )))
132
- (gethash " location" candidate)))
126
+ (format " %s .%s " container-name? name)))))
127
+
128
+ (defun lsp-ivy--workspace-symbol-action (symbol-information-candidate )
129
+ " Jump to selected SYMBOL-INFORMATION-CANDIDATE, a cons cell whose cdr is a a SymbolInformation."
130
+ (-let (((&SymbolInformation :location
131
+ (&Location :uri
132
+ :range
133
+ (&Range :start
134
+ (&Position :line :character ))))
135
+ (cdr symbol-information-candidate)))
133
136
(find-file (lsp--uri-to-path uri))
134
137
(goto-char (point-min ))
135
138
(forward-line line)
136
139
(forward-char character)))
137
140
138
- (defun lsp-ivy--filter-func (candidate )
139
- (member (gethash " kind" candidate) lsp-ivy-filter-symbol-kind))
141
+ (lsp-defun lsp-ivy--filter-func ((&SymbolInformation :kind ))
142
+ " Filter candidate kind from symbol kinds."
143
+ (member kind lsp-ivy-filter-symbol-kind))
140
144
141
145
(defun lsp-ivy--workspace-symbol (workspaces prompt initial-input )
142
146
" Search against WORKSPACES with PROMPT and INITIAL-INPUT."
@@ -146,13 +150,13 @@ MATCH is a cons cell whose cdr is the hash-table from `lsp-mode`."
146
150
(with-lsp-workspaces workspaces
147
151
(lsp-request-async
148
152
" workspace/symbol"
149
- (list :query user-input)
153
+ (lsp-make-workspace-symbol-params :query user-input)
150
154
(lambda (result )
151
155
(ivy-update-candidates
152
156
(mapcar
153
- (lambda (data )
154
- (cons ( gethash " name" data) data ))
155
- (-remove 'lsp-ivy--filter-func result))))
157
+ (- lambda ((symbol-information &as &SymbolInformation :name ) )
158
+ (cons name symbol-information ))
159
+ (-remove # 'lsp-ivy--filter-func result))))
156
160
:mode 'detached
157
161
:cancel-token :workspace-symbol ))
158
162
0 )
0 commit comments