Skip to content

Commit 6b9ca70

Browse files
committed
Use lsp-protocol and plists
1 parent 06cca8b commit 6b9ca70

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

lsp-ivy.el

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
(require 'ivy)
3535
(require 'dash)
36+
37+
(require 'lsp-protocol)
3638
(require 'lsp-mode)
3739

3840
(defgroup lsp-ivy nil
@@ -111,33 +113,34 @@
111113
(cons string face)))
112114

113115

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 hash-table 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?))
125125
(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 hash table."
130+
(-let (((&SymbolInformation :location
131+
(&Location :uri
132+
:range
133+
(&Range :start
134+
(&Position :line :character))))
135+
(cdr symbol-information-candidate)))
133136
(find-file (lsp--uri-to-path uri))
134137
(goto-char (point-min))
135138
(forward-line line)
136139
(forward-char character)))
137140

138-
(defun lsp-ivy--filter-func (candidate)
139-
"Filter CANDIDATE kind from symbol kinds."
140-
(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))
141144

142145
(defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
143146
"Search against WORKSPACES with PROMPT and INITIAL-INPUT."
@@ -147,13 +150,13 @@ MATCH is a cons cell whose cdr is the hash-table from `lsp-mode`."
147150
(with-lsp-workspaces workspaces
148151
(lsp-request-async
149152
"workspace/symbol"
150-
(list :query user-input)
153+
(lsp-make-workspace-symbol-params :query user-input)
151154
(lambda (result)
152155
(ivy-update-candidates
153156
(mapcar
154-
(lambda (data)
155-
(cons (gethash "name" data) data))
156-
(-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))))
157160
:mode 'detached
158161
:cancel-token :workspace-symbol))
159162
0)

0 commit comments

Comments
 (0)