Skip to content

Commit f6e3211

Browse files
Merge pull request #15 from emacs-lsp/plists
Use lsp-protocol and plists
2 parents dce58b5 + 94d3415 commit f6e3211

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

lsp-ivy.el

+31-27
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
@@ -41,13 +43,13 @@
4143

4244
(defcustom lsp-ivy-show-symbol-kind
4345
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."
4547
:group 'lsp-ivy
4648
:type 'boolean)
4749

4850
(defcustom lsp-ivy-filter-symbol-kind
4951
nil
50-
"A list of LSP SymbolKind's to filter out"
52+
"A list of LSP SymbolKind's to filter out."
5153
:group 'lsp-ivy
5254
:type '(repeat integer))
5355

@@ -79,7 +81,7 @@
7981
("Evnt" . font-lock-builtin-face) ;; Event - 24
8082
("Op " . font-lock-function-name-face) ;; Operator - 25
8183
("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)."
8385
:group 'lsp-ivy
8486
:type '(vector
8587
(cons string face)
@@ -111,32 +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 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?))
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 a SymbolInformation."
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-
(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))
140144

141145
(defun lsp-ivy--workspace-symbol (workspaces prompt initial-input)
142146
"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`."
146150
(with-lsp-workspaces workspaces
147151
(lsp-request-async
148152
"workspace/symbol"
149-
(list :query user-input)
153+
(lsp-make-workspace-symbol-params :query user-input)
150154
(lambda (result)
151155
(ivy-update-candidates
152156
(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))))
156160
:mode 'detached
157161
:cancel-token :workspace-symbol))
158162
0)

0 commit comments

Comments
 (0)