Skip to content

Commit 32f8f26

Browse files
Optionally display file paths
1 parent 8691e92 commit 32f8f26

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lsp-ivy.el

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
:group 'lsp-ivy
4848
:type 'boolean)
4949

50+
(defcustom lsp-ivy-show-symbol-filename
51+
t
52+
"Whether to show the project-relative path to a symbol's point of definition."
53+
:group 'lsp-ivy
54+
:type 'boolean)
55+
5056
(defcustom lsp-ivy-filter-symbol-kind
5157
nil
5258
"A list of LSP SymbolKind's to filter out."
@@ -127,24 +133,28 @@
127133
(forward-line line)
128134
(forward-char character))
129135

130-
(defun lsp-ivy--format-symbol-match (symbol-information)
131-
"Convert the match returned by `lsp-mode` into a candidate string.
132-
SYMBOL-INFORMATION is a SymbolInformation object from `lsp-mode`."
133-
(-let* (((&SymbolInformation :name :kind :container-name?) symbol-information)
134-
(type (elt lsp-ivy-symbol-kind-to-face kind))
135-
(typestr (if lsp-ivy-show-symbol-kind
136-
(propertize (format "[%s] " (car type)) 'face (cdr type))
137-
"")))
136+
(lsp-defun lsp-ivy--format-symbol-match
137+
((&SymbolInformation :name :kind :container-name? :location (&Location :uri))
138+
project-root)
139+
"Convert the match returned by `lsp-mode` into a candidate string."
140+
(let* ((type (elt lsp-ivy-symbol-kind-to-face kind))
141+
(typestr (if lsp-ivy-show-symbol-kind
142+
(propertize (format "[%s] " (car type)) 'face (cdr type))
143+
""))
144+
(pathstr (if lsp-ivy-show-symbol-filename
145+
(propertize (format " · %s" (file-relative-name (lsp--uri-to-path uri) project-root))
146+
'face font-lock-comment-face) "")))
138147
(concat typestr (if (or (null container-name?) (string-empty-p container-name?))
139148
(format "%s" name)
140-
(format "%s.%s" container-name? name)))))
149+
(format "%s.%s" container-name? name)) pathstr)))
141150

142151
(lsp-defun lsp-ivy--transform-candidate ((symbol-information &as &SymbolInformation :kind)
143-
filter-regexps?)
152+
filter-regexps? workspace-root)
144153
"Map candidate to nil if it should be excluded based on `lsp-ivy-filter-symbol-kind' or
145154
FILTER-REGEXPS?, otherwise convert it to an `lsp-ivy:FormattedSymbolInformation' object."
146155
(unless (member kind lsp-ivy-filter-symbol-kind)
147-
(let ((textual-representation (lsp-ivy--format-symbol-match symbol-information)))
156+
(let ((textual-representation
157+
(lsp-ivy--format-symbol-match symbol-information workspace-root)))
148158
(when (--all? (string-match-p it textual-representation) filter-regexps?)
149159
(lsp-put symbol-information :textualRepresentation textual-representation)
150160
symbol-information))))
@@ -154,10 +164,11 @@ FILTER-REGEXPS?, otherwise convert it to an `lsp-ivy:FormattedSymbolInformation'
154164
(let* ((prev-query nil)
155165
(unfiltered-candidates '())
156166
(filtered-candidates nil)
167+
(workspace-root (lsp-workspace-root))
157168
(update-candidates
158169
(lambda (all-candidates filter-regexps?)
159170
(setq filtered-candidates
160-
(--keep (lsp-ivy--transform-candidate it filter-regexps?)
171+
(--keep (lsp-ivy--transform-candidate it filter-regexps? workspace-root)
161172
all-candidates))
162173
(ivy-update-candidates filtered-candidates))))
163174
(ivy-read

0 commit comments

Comments
 (0)