Skip to content

Commit 884d86d

Browse files
committed
Don't use `ivy-configure' + display-transformer and undocumented ivy-update-candidates
1 parent 4dcb635 commit 884d86d

File tree

1 file changed

+22
-39
lines changed

1 file changed

+22
-39
lines changed

lsp-ivy.el

+22-39
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,7 @@ SymbolKind (defined in the LSP)."
122122
(cons string face)
123123
(cons string face)))
124124

125-
(eval-when-compile
126-
(lsp-interface
127-
(lsp-ivy:FormattedSymbolInformation
128-
(:kind :name :location :textualRepresentation)
129-
(:containerName :deprecated))))
130-
131-
(lsp-defun lsp-ivy--workspace-symbol-action
125+
(lsp-defun lsp-ivy--goto-symbol
132126
((&SymbolInformation
133127
:location (&Location :uri :range (&Range :start (&Position :line :character)))))
134128
"Jump to selected candidate."
@@ -153,58 +147,47 @@ SymbolKind (defined in the LSP)."
153147

154148
(lsp-defun lsp-ivy--transform-candidate ((symbol-information &as &SymbolInformation :kind)
155149
filter-regexps? workspace-root)
156-
"Map candidate to nil if it should be excluded based on `lsp-ivy-filter-symbol-kind' or
157-
FILTER-REGEXPS?, otherwise convert it to an `lsp-ivy:FormattedSymbolInformation' object."
150+
"Map candidate to nil if it should be excluded based on
151+
`lsp-ivy-filter-symbol-kind' or FILTER-REGEXPS?, otherwise convert it to a cons
152+
of textual representation and the original candidate."
158153
(unless (member kind lsp-ivy-filter-symbol-kind)
159154
(let ((textual-representation
160155
(lsp-ivy--format-symbol-match symbol-information workspace-root)))
161156
(when (--all? (string-match-p it textual-representation) filter-regexps?)
162-
(lsp-put symbol-information :textualRepresentation textual-representation)
163-
symbol-information))))
157+
(cons textual-representation symbol-information)))))
158+
159+
(lsp-defun lsp-ivy--workspace-symbol-action ((_ . sym))
160+
"Jump to the `cdr' of INPUT0, an `&SymbolInformation'."
161+
(lsp-ivy--goto-symbol sym))
164162

165163
(defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
166164
"Search against WORKSPACES with PROMPT and INITIAL-INPUT."
167-
(let* ((prev-query nil)
165+
(let* ((non-essential t)
166+
(prev-query nil)
168167
(unfiltered-candidates '())
169-
(filtered-candidates nil)
170-
(workspace-root (lsp-workspace-root))
171-
(update-candidates
172-
(lambda (all-candidates filter-regexps?)
173-
(setq filtered-candidates
174-
(--keep (lsp-ivy--transform-candidate it filter-regexps? workspace-root)
175-
all-candidates))
176-
(ivy-update-candidates filtered-candidates))))
168+
(workspace-root (lsp-workspace-root)))
177169
(ivy-read
178170
prompt
179171
(lambda (user-input)
180172
(let* ((parts (split-string user-input))
181173
(query (or (car parts) ""))
182174
(filter-regexps? (mapcar #'regexp-quote (cdr parts))))
183-
(when query
184-
(if (string-equal prev-query query)
185-
(funcall update-candidates unfiltered-candidates filter-regexps?)
186-
(with-lsp-workspaces workspaces
187-
(lsp-request-async
188-
"workspace/symbol"
189-
(lsp-make-workspace-symbol-params :query query)
190-
(lambda (result)
191-
(setq unfiltered-candidates result)
192-
(funcall update-candidates unfiltered-candidates filter-regexps?))
193-
:mode 'detached
194-
:cancel-token :workspace-symbol))))
195-
(setq prev-query query))
196-
(or filtered-candidates 0))
175+
(unless (string-equal prev-query query)
176+
(setq unfiltered-candidates
177+
(with-lsp-workspaces workspaces
178+
(lsp-request-while-no-input
179+
"workspace/symbol"
180+
(lsp-make-workspace-symbol-params :query query)))))
181+
(setq prev-query query)
182+
(or (--keep (lsp-ivy--transform-candidate it filter-regexps? workspace-root)
183+
unfiltered-candidates)
184+
0)))
197185
:dynamic-collection t
198186
:require-match t
199187
:initial-input initial-input
200188
:action #'lsp-ivy--workspace-symbol-action
201189
:caller 'lsp-ivy-workspace-symbol)))
202190

203-
(ivy-configure 'lsp-ivy-workspace-symbol
204-
:display-transformer-fn
205-
(-lambda ((&lsp-ivy:FormattedSymbolInformation :textual-representation))
206-
textual-representation))
207-
208191
;;;###autoload
209192
(defun lsp-ivy-workspace-symbol (arg)
210193
"`ivy' for lsp workspace/symbol.

0 commit comments

Comments
 (0)