|
34 | 34 |
|
35 | 35 | (defun lsp-ivy--format-symbol-match (match)
|
36 | 36 | "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)) |
38 | 38 | (name (gethash "name" match)))
|
39 |
| - (if (string-empty-p containerName) |
| 39 | + (if (or (null container-name) (string-empty-p container-name)) |
40 | 40 | name
|
41 |
| - (format "%s.%s" containerName name)))) |
| 41 | + (format "%s.%s" container-name name)))) |
42 | 42 |
|
43 | 43 | (defun lsp-ivy--workspace-symbol-action (candidate)
|
44 | 44 | "Jump to selected CANDIDATE."
|
|
51 | 51 |
|
52 | 52 | (defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
|
53 | 53 | "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)) |
58 | 56 | (ivy-read
|
59 | 57 | 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) |
79 | 77 | :dynamic-collection t
|
80 | 78 | :require-match t
|
81 | 79 | :initial-input initial-input
|
82 | 80 | :action (lambda (result)
|
83 | 81 | (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))))))) |
90 | 87 |
|
91 | 88 | ;;;###autoload
|
92 | 89 | (defun lsp-ivy-workspace-symbol (arg)
|
|
0 commit comments