Skip to content

Commit bf05453

Browse files
committed
Adjust to latest lsp-mode
1 parent 378ac0b commit bf05453

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

lsp-treemacs.el

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,13 @@
141141
"Select the element under cursor."
142142
(interactive)
143143
(let ((key (button-get (treemacs-node-at-point) :data)))
144-
(if (and (consp key) (lsp-diagnostic-p (cdr key)))
145-
(-let (((file . diag) key)
144+
(if (and (consp key) (ht? (cdr key)))
145+
(-let (((file . (&Diagnostic :range (&Range :start))) key)
146146
(session (lsp-session)))
147147
(with-current-buffer (find-file-noselect file)
148148
(with-lsp-workspaces (lsp--try-project-root-workspaces nil nil)
149149
(save-excursion
150-
(goto-char (point-min))
151-
(forward-line (lsp-diagnostic-line diag))
150+
(goto-char (lsp--position-to-point :start))
152151
(lsp-execute-code-action-by-kind "quickfix")))))
153152
(user-error "Not on a diagnostic"))))
154153

@@ -174,11 +173,9 @@
174173
(defun lsp-treemacs-open-error (&rest _)
175174
"Open error."
176175
(interactive)
177-
(-let [(file . diag) (button-get (treemacs-node-at-point) :data)]
176+
(-let [(file . (&Diagnostic :range (&Range :start))) (button-get (treemacs-node-at-point) :data)]
178177
(find-file-other-window file)
179-
(goto-char (point-min))
180-
(forward-line (lsp-diagnostic-line diag))
181-
(forward-char (lsp-diagnostic-column diag))))
178+
(goto-char (lsp--position-to-point start))))
182179

183180
(defun lsp-treemacs--face (root-folder diagnostics)
184181
"Calculate ROOT-FOLDER face based on DIAGNOSTICS."
@@ -187,9 +184,10 @@
187184
(-keep (-lambda ((file-name . file-diagnostics))
188185
(when (s-starts-with? root-folder file-name)
189186
(lsp-diagnostic-severity
190-
(--min-by (> (lsp-diagnostic-severity it)
191-
(lsp-diagnostic-severity other))
192-
file-diagnostics))))
187+
(-min-by (-lambda ((&Diagnostic :severity? left?)
188+
(&Diagnostic :severity? right?))
189+
(> (or left? 0) (or right? 0)))
190+
file-diagnostics))))
193191
it)
194192
-min
195193
(assoc it lsp-treemacs-face-map)
@@ -236,12 +234,13 @@
236234
(->> (lsp-diagnostics)
237235
(gethash file-name)
238236
(-filter #'lsp-treemacs--match-diagnostic-severity)
239-
(--sort (if (= (lsp-diagnostic-line it)
240-
(lsp-diagnostic-line other))
241-
(< (lsp-diagnostic-column it)
242-
(lsp-diagnostic-column other))
243-
(< (lsp-diagnostic-line it)
244-
(lsp-diagnostic-line other))))
237+
(-sort (-lambda ((&Diagnostic :range (&Range :start (&Position :character char-a
238+
:line line-a)))
239+
(&Diagnostic :range (&Range :start (&Position :character char-b
240+
:line line-b))))
241+
(if (= line-a line-b)
242+
(< char-a char-b)
243+
(< line-a line-b))))
245244
(--map (cons file-name it))))
246245

247246
(defun lsp-treemacs--diagnostic-icon (diagnostic)
@@ -259,7 +258,7 @@
259258
:render-action
260259
(treemacs-render-node
261260
:icon (treemacs-as-icon ". " 'face 'font-lock-string-face)
262-
:label-form (propertize (lsp-diagnostic-message item) 'face 'default)
261+
:label-form (propertize (lsp:diagnostic-message item) 'face 'default)
263262
:state treemacs-lsp-error-open-state
264263
:key-form item))
265264

@@ -269,15 +268,17 @@
269268
:query-function (lsp-treemacs--errors (treemacs-button-get node :key))
270269
:ret-action 'lsp-treemacs-open-file
271270
:render-action
272-
(let* ((diag (cl-rest item))
273-
(label (format (propertize "%s %s %s" 'face 'default)
274-
(propertize (format "[%s]" (lsp-diagnostic-source diag))
275-
'face 'shadow)
276-
(lsp-diagnostic-message diag)
277-
(propertize (format "(%s:%s)"
278-
(lsp-diagnostic-line diag)
279-
(lsp-diagnostic-column diag))
280-
'face 'lsp-lens-face))))
271+
(-let* (((&Diagnostic :source?
272+
:message
273+
:range (&Range :start (&Position :line :character))) (cl-rest item))
274+
(label (format (propertize "%s %s %s" 'face 'default)
275+
(if source?
276+
(propertize (format "[%s]" source?)
277+
'face 'shadow)
278+
"")
279+
message
280+
(propertize (format "(%s:%s)" line character)
281+
'face 'lsp-lens-face))))
281282
(treemacs-render-node
282283
:icon (lsp-treemacs--diagnostic-icon (cl-rest item))
283284
:label-form label
@@ -670,7 +671,7 @@
670671

671672
(defun lsp-treemacs-deps--icon (dep expanded)
672673
"Get the symbol for the the kind."
673-
(-let (((&hash "uri" "name" "kind" "entryKind" entry-kind) dep))
674+
(-let (((&hash "uri" "kind" "entryKind" entry-kind) dep))
674675
(concat
675676
(if expanded "" "")
676677
(if (or (= kind 8)
@@ -1037,15 +1038,6 @@
10371038
(interactive)
10381039
(lsp-treemacs--open-file-in-mru filename)))))
10391040

1040-
(defun lsp-treemacs--extract-line (pos)
1041-
"Return the line pointed to by POS (a Position object) in the current buffer."
1042-
(let* ((point (lsp--position-to-point pos))
1043-
(inhibit-field-text-motion t))
1044-
(save-excursion
1045-
(goto-char point)
1046-
(buffer-substring (line-beginning-position)
1047-
(line-end-position)))))
1048-
10491041
(defun lsp-treemacs--extract-line (point)
10501042
"Return the line pointed to by POS (a Position object) in the current buffer."
10511043
(let* ((inhibit-field-text-motion t))

0 commit comments

Comments
 (0)