Skip to content

Commit c8391c5

Browse files
Merge pull request #3 from abo-abo/master
Use ivy-update-candidates
2 parents e42715d + 610241f commit c8391c5

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

lsp-ivy.el

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
(defun lsp-ivy--format-symbol-match (match)
3636
"Convert the (hash-valued) MATCH returned by `lsp-mode` into a candidate string."
37-
(let ((containerName (gethash "containerName" match))
37+
(let ((container-name (gethash "containerName" match))
3838
(name (gethash "name" match)))
39-
(if (string-empty-p containerName)
39+
(if (or (null container-name) (string-empty-p container-name))
4040
name
41-
(format "%s.%s" containerName name))))
41+
(format "%s.%s" container-name name))))
4242

4343
(defun lsp-ivy--workspace-symbol-action (candidate)
4444
"Jump to selected CANDIDATE."
@@ -51,42 +51,39 @@
5151

5252
(defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
5353
"Search against WORKSPACES with PROMPT and INITIAL-INPUT."
54-
(let (;; contains current user input, followed by the string representations
55-
;; of all currently available candidates
56-
(candidates)
57-
(current-request-id))
54+
(let ((candidates nil)
55+
(current-request-id nil))
5856
(ivy-read
5957
prompt
60-
(lambda (user-input &rest args)
61-
(if (string= user-input (car candidates))
62-
(--map (lsp-ivy--format-symbol-match it) (cdr candidates))
63-
(ignore
64-
(with-lsp-workspaces workspaces
65-
(-let (((request &as &plist :id request-id)
66-
(lsp-make-request
67-
"workspace/symbol"
68-
(list :query user-input))))
69-
(when current-request-id
70-
(lsp--cancel-request current-request-id))
71-
(setq current-request-id request-id)
72-
(lsp-send-request-async
73-
request
74-
(lambda (incoming-candidates)
75-
(setq candidates (cons user-input incoming-candidates))
76-
(let (ivy--old-text)
77-
(ivy--exhibit)))
78-
:mode 'detached))))))
58+
(lambda (user-input)
59+
(with-lsp-workspaces workspaces
60+
(let ((request (lsp-make-request
61+
"workspace/symbol"
62+
(list :query user-input))))
63+
(when current-request-id
64+
(lsp--cancel-request
65+
current-request-id))
66+
(setq current-request-id
67+
(plist-get request :id))
68+
(lsp-send-request-async
69+
request
70+
(lambda (incoming-candidates)
71+
(ivy-update-candidates
72+
(mapcar
73+
#'lsp-ivy--format-symbol-match
74+
(setq candidates incoming-candidates))))
75+
:mode 'detached)))
76+
0)
7977
:dynamic-collection t
8078
:require-match t
8179
:initial-input initial-input
8280
:action (lambda (result)
8381
(let ((match
84-
(--find
85-
(string-equal result (lsp-ivy--format-symbol-match it))
86-
;; KLUDGE: remove current query, find candidate
87-
;; corresponding to selected candidate by linear search
88-
(-drop 1 candidates))))
89-
(when match (lsp-ivy--workspace-symbol-action match)))))))
82+
(cl-find-if
83+
(lambda (it) (string-equal result (lsp-ivy--format-symbol-match it)))
84+
candidates)))
85+
(when match
86+
(lsp-ivy--workspace-symbol-action match)))))))
9087

9188
;;;###autoload
9289
(defun lsp-ivy-workspace-symbol (arg)

0 commit comments

Comments
 (0)