Skip to content

Commit 5686da3

Browse files
committed
Migrate closing labels
1 parent cd9f766 commit 5686da3

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

lsp-dart-closing-labels.el

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
(require 'lsp-mode)
2323

24+
(require 'lsp-dart-protocol)
25+
2426
(defcustom lsp-dart-closing-labels t
2527
"Enable the analysis server closing labels feature.
2628
When set to non-nil, dart/textDocument/publishClosingLabel notifications will
@@ -38,28 +40,23 @@ be sent with information to render editor closing labels."
3840
:type 'float
3941
:group 'lsp-dart)
4042

41-
(defun lsp-dart-closing-labels-handle (_workspace params)
42-
"Closing labels notification handling.
43-
PARAMS closing labels notification data sent from WORKSPACE."
44-
(-let* (((&hash "uri" "labels") params)
45-
(buffer (lsp--buffer-for-file (lsp--uri-to-path uri))))
46-
(when buffer
47-
(with-current-buffer buffer
48-
(remove-overlays (point-min) (point-max) 'lsp-dart-closing-labels t)
49-
(seq-doseq (label-ht labels)
50-
(save-excursion
51-
(-let* ((label (gethash "label" label-ht))
52-
(range (gethash "range" label-ht))
53-
((beg . end) (lsp--range-to-region range))
54-
(end-line (progn
55-
(goto-char end)
56-
(line-end-position)))
57-
(overlay (make-overlay beg end-line buffer)))
58-
(overlay-put overlay 'lsp-dart-closing-labels t)
59-
(overlay-put overlay 'after-string (propertize (concat lsp-dart-closing-labels-prefix " " label)
60-
'display `((height ,lsp-dart-closing-labels-size))
61-
'cursor t
62-
'font-lock-face 'font-lock-comment-face)))))))))
43+
(lsp-defun lsp-dart-closing-labels-handle (_workspace (&ClosingLabelsNotification :uri :labels))
44+
"Closing labels notification handler."
45+
(when-let (buffer (lsp--buffer-for-file (lsp--uri-to-path uri)))
46+
(with-current-buffer buffer
47+
(remove-overlays (point-min) (point-max) 'lsp-dart-closing-labels t)
48+
(seq-doseq (label labels)
49+
(save-excursion
50+
(-let* (((beg . end) (lsp--range-to-region (lsp:closing-label-range label)))
51+
(end-line (progn
52+
(goto-char end)
53+
(line-end-position)))
54+
(overlay (make-overlay beg end-line buffer)))
55+
(overlay-put overlay 'lsp-dart-closing-labels t)
56+
(overlay-put overlay 'after-string (propertize (concat lsp-dart-closing-labels-prefix " " (lsp:closing-label-label label))
57+
'display `((height ,lsp-dart-closing-labels-size))
58+
'cursor t
59+
'font-lock-face 'font-lock-comment-face))))))))
6360

6461
(provide 'lsp-dart-closing-labels)
6562
;;; lsp-dart-closing-labels.el ends here

lsp-dart-protocol.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
(lsp-interface
2525
(AnalyzerStatusNotification (:isAnalyzing) nil))
2626

27+
(lsp-interface
28+
(ClosingLabelsNotification (:uri :labels) nil)
29+
(ClosingLabel (:label :range) nil))
30+
2731
(lsp-interface
2832
(OutlineNotification (:uri :outline) nil)
2933
(Outline (:element :range :codeRange :children) nil)

0 commit comments

Comments
 (0)