Skip to content

Commit db7438a

Browse files
committed
Migrate code lens
1 parent d935536 commit db7438a

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lsp-dart-code-lens.el

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,18 @@ NAMES arg is optional and are the group of tests representing a test name."
175175
(unless (seq-empty-p children)
176176
(lsp-dart-code-lens--add-test buffer children concatened-names)))))
177177

178-
179-
;; Public
180-
181-
(lsp-defun lsp-dart-code-lens-check-main (uri (&Outline :children))
178+
(lsp-defun lsp-dart--main-code-lens-check ((&OutlineNotification :uri :outline (&Outline :children)))
182179
"Check URI and outline for main method adding lens to it."
183180
(-let* ((buffer (find-buffer-visiting (lsp--uri-to-path uri)))
184181
(main-outline (lsp-dart-code-lens--find-main-outline children)))
185182
(when buffer
186183
(with-current-buffer buffer
187184
(remove-overlays (point-min) (point-max) 'lsp-dart-main-code-lens t)
188-
(save-excursion
189-
(when main-outline
185+
(when main-outline
186+
(save-excursion
190187
(lsp-dart-code-lens--build-main-overlay buffer main-outline)))))))
191188

192-
(lsp-defun lsp-dart-code-lens-check-test (uri (&Outline :children))
189+
(lsp-defun lsp-dart--test-code-lens-check ((&OutlineNotification :uri :outline (&Outline :children)))
193190
"Check URI and outline for test adding lens to it."
194191
(when (lsp-dart-test-file-p uri)
195192
(when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
@@ -198,5 +195,30 @@ NAMES arg is optional and are the group of tests representing a test name."
198195
(save-excursion
199196
(lsp-dart-code-lens--add-test buffer children))))))
200197

198+
199+
;; Public
200+
201+
(define-minor-mode lsp-dart-main-code-lens-mode
202+
"Mode for displaying code lens on main methods."
203+
nil nil nil
204+
(cond
205+
(lsp-dart-main-code-lens-mode
206+
(add-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--main-code-lens-check nil t))
207+
(t
208+
(progn
209+
(remove-overlays (point-min) (point-max) 'lsp-dart-main-code-lens t)
210+
(remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--main-code-lens-check t)))))
211+
212+
(define-minor-mode lsp-dart-test-code-lens-mode
213+
"Mode for displaying code lens on main methods."
214+
nil nil nil
215+
(cond
216+
(lsp-dart-test-code-lens-mode
217+
(add-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--test-code-lens-check nil t))
218+
(t
219+
(progn
220+
(remove-overlays (point-min) (point-max) 'lsp-dart-test-code-lens t)
221+
(remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--test-code-lens-check t)))))
222+
201223
(provide 'lsp-dart-code-lens)
202224
;;; lsp-dart-code-lens.el ends here

lsp-dart-outline.el

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
(require 'lsp-dart-protocol)
2525
(require 'lsp-dart-utils)
26-
(require 'lsp-dart-code-lens)
2726

2827
(defcustom lsp-dart-outline t
2928
"Enable the analysis server outline custom method.
@@ -215,14 +214,10 @@ Focus on it if IGNORE-FOCUS? is nil."
215214
(set-window-dedicated-p window t)))
216215
(lsp-dart-log "No Flutter outline data found")))
217216

218-
(lsp-defun lsp-dart--outline-check ((notification &as &OutlineNotification :uri :outline))
217+
(lsp-defun lsp-dart--outline-check ((notification &as &OutlineNotification :uri))
219218
"Outline notification handling from WORKSPACE.
220219
NOTIFICATION is outline notification data received from server.
221220
It updates the outline view if it already exists."
222-
(when lsp-dart-main-code-lens
223-
(lsp-dart-code-lens-check-main uri outline))
224-
(when lsp-dart-test-code-lens
225-
(lsp-dart-code-lens-check-test uri outline))
226221
(when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
227222
(with-current-buffer buffer
228223
(setq lsp-dart-current-outline notification)

lsp-dart.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
(require 'lsp-dart-utils)
3333
(require 'lsp-dart-flutter-daemon)
3434
(require 'lsp-dart-closing-labels)
35+
(require 'lsp-dart-code-lens)
3536
(require 'lsp-dart-outline)
3637
(require 'lsp-dart-flutter-fringe-colors)
3738
(require 'lsp-dart-flutter-widget-guide)
@@ -112,7 +113,11 @@ PARAMS is the data sent from server."
112113
(when lsp-dart-outline
113114
(lsp-dart-outline-mode 1))
114115
(when lsp-dart-flutter-outline
115-
(lsp-dart-flutter-outline-mode 1)))
116+
(lsp-dart-flutter-outline-mode 1))
117+
(when lsp-dart-main-code-lens
118+
(lsp-dart-main-code-lens-mode 1))
119+
(when lsp-dart-test-code-lens
120+
(lsp-dart-test-code-lens-mode 1)))
116121

117122
(lsp-register-client
118123
(make-lsp-client :new-connection

0 commit comments

Comments
 (0)