23
23
24
24
(require 'lsp-dart-protocol )
25
25
(require 'lsp-dart-utils )
26
- (require 'lsp-dart-code-lens )
27
26
28
27
(defcustom lsp-dart-outline t
29
28
" Enable the analysis server outline custom method.
@@ -60,6 +59,12 @@ Defaults to side following treemacs default."
60
59
61
60
; ;; Internal
62
61
62
+ (defvar-local lsp-dart-current-outline nil )
63
+ (defvar-local lsp-dart-current-flutter-outline nil )
64
+
65
+ (defconst lsp-dart--outline-buffer-name " *Dart Outline*" )
66
+ (defconst lsp-dart--flutter-outline-buffer-name " *Flutter Outline*" )
67
+
63
68
(defun lsp-dart-outline--set-metadata (workspace params key-prefix )
64
69
" Save in WORKSPACE the PARAMS metadata with KEY-PREFIX.
65
70
The key is composed of the KEY-PREFIX with PARAMS uri path."
@@ -176,7 +181,7 @@ OUTLINES are the outline items."
176
181
(lsp-dart-outline--outlines->tree uri outlines)
177
182
" Outline"
178
183
t
179
- " *Dart Outline* " )))
184
+ lsp-dart--outline-buffer-name )))
180
185
181
186
(defun lsp-dart-outline--render-flutter-outline-tree (uri outlines )
182
187
" Render an Flutter outline view with the source URI and OUTLINES data."
@@ -185,65 +190,84 @@ OUTLINES are the outline items."
185
190
(lsp-dart-outline--flutter-outline->tree uri outlines)
186
191
" Flutter Outline"
187
192
t
188
- " *Flutter Outline* " )))
193
+ lsp-dart--flutter-outline-buffer-name )))
189
194
190
- (defun lsp-dart-outline--show-outline (buffer ignore-focus? )
195
+ (defun lsp-dart-outline--show-outline (ignore-focus? )
191
196
" Show an outline tree for BUFFER.
192
197
Focus on it if IGNORE-FOCUS? is nil."
193
- (-when -let ((&OutlineNotification? :uri :outline (&Outline :children )) ( lsp-dart-outline--get-metadata buffer " current-outline" ) )
198
+ (-if -let ((&OutlineNotification? :uri :outline (&Outline :children )) lsp-dart-current-outline)
194
199
(-let* ((tree-buffer (lsp-dart-outline--render-outline-tree uri children))
195
200
(window (display-buffer-in-side-window tree-buffer lsp-dart-outline-position-params)))
196
201
(unless ignore-focus?
197
202
(select-window window)
198
- (set-window-dedicated-p window t )))))
203
+ (set-window-dedicated-p window t )))
204
+ (lsp-dart-log " No Dart outline data found" )))
199
205
200
- (defun lsp-dart-outline--show-flutter-outline (buffer ignore-focus? )
206
+ (defun lsp-dart-outline--show-flutter-outline (ignore-focus? )
201
207
" Show a Flutter outline tree for BUFFER.
202
208
Focus on it if IGNORE-FOCUS? is nil."
203
- (-when -let ((&FlutterOutlineNotification? :uri :outline (&FlutterOutline :children )) ( lsp-dart-outline--get-metadata buffer " current-flutter-outline" ) )
209
+ (-if -let ((&FlutterOutlineNotification? :uri :outline (&FlutterOutline :children )) lsp-dart-current-flutter-outline)
204
210
(-let* ((tree-buffer (lsp-dart-outline--render-flutter-outline-tree uri children))
205
211
(window (display-buffer-in-side-window tree-buffer lsp-dart-flutter-outline-position-params)))
206
212
(unless ignore-focus?
207
213
(select-window window)
208
- (set-window-dedicated-p window t )))))
214
+ (set-window-dedicated-p window t )))
215
+ (lsp-dart-log " No Flutter outline data found" )))
209
216
210
- (lsp-defun lsp-dart-outline-handle- outline (workspace (notification &as &OutlineNotification :uri :outline ))
217
+ (lsp-defun lsp-dart-- outline-check ( (notification &as &OutlineNotification :uri ))
211
218
" Outline notification handling from WORKSPACE.
212
219
NOTIFICATION is outline notification data received from server.
213
220
It updates the outline view if it already exists."
214
- (lsp-dart-outline--set-metadata workspace notification " current-outline" )
215
- (when lsp-dart-main-code-lens
216
- (lsp-dart-code-lens-check-main uri outline))
217
- (when lsp-dart-test-code-lens
218
- (lsp-dart-code-lens-check-test uri outline))
219
- (when (get-buffer-window " *Dart Outline*" )
220
- (lsp-dart-outline--show-outline (find-buffer-visiting (lsp--uri-to-path uri)) t )))
221
-
222
- (lsp-defun lsp-dart-outline-handle-flutter-outline (workspace (notification &as &FlutterOutlineNotification :uri ))
221
+ (when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
222
+ (with-current-buffer buffer
223
+ (setq lsp-dart-current-outline notification)
224
+ (when (get-buffer-window lsp-dart--outline-buffer-name)
225
+ (lsp-dart-outline--show-outline t )))))
226
+
227
+ (lsp-defun lsp-dart--flutter-outline-check ((notification &as &FlutterOutlineNotification :uri ))
223
228
" Flutter outline notification handling from WORKSPACE.
224
229
NOTIFICATION is Flutter outline notification data received from server.
225
230
It updates the Flutter outline view if it already exists."
226
- (lsp-dart-outline--set-metadata workspace notification " current-flutter-outline" )
227
- (run-hook-with-args 'lsp-dart-outline-arrived-hook notification)
228
- (when (get-buffer-window " *Flutter Outline*" )
229
- (lsp-dart-outline--show-flutter-outline (find-buffer-visiting (lsp--uri-to-path uri)) t )))
231
+ (when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
232
+ (with-current-buffer buffer
233
+ (setq lsp-dart-current-flutter-outline notification)
234
+ (when (get-buffer-window lsp-dart--flutter-outline-buffer-name)
235
+ (lsp-dart-outline--show-flutter-outline t )))))
230
236
231
237
232
238
; ;; Public interface
233
239
240
+ (define-minor-mode lsp-dart-outline-mode
241
+ " Mode for updating outline."
242
+ nil nil nil
243
+ (cond
244
+ (lsp-dart-outline-mode
245
+ (add-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--outline-check nil t ))
246
+ (t
247
+ (remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--outline-check t ))))
248
+
249
+ (define-minor-mode lsp-dart-flutter-outline-mode
250
+ " Mode for updating flutter outline."
251
+ nil nil nil
252
+ (cond
253
+ (lsp-dart-flutter-outline-mode
254
+ (add-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart--flutter-outline-check nil t ))
255
+ (t
256
+ (remove-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart--flutter-outline-check t ))))
257
+
234
258
;;;### autoload
235
259
(defun lsp-dart-show-outline (ignore-focus? )
236
260
" Show an outline tree and focus on it if IGNORE-FOCUS? is nil."
237
261
(interactive " P" )
238
262
(lsp-dart-assert-sdk-min-version " 2.8.0" )
239
- (lsp-dart-outline--show-outline ( current-buffer ) ignore-focus?) )
263
+ (lsp-dart-outline--show-outline ignore-focus?) )
240
264
241
265
;;;### autoload
242
266
(defun lsp-dart-show-flutter-outline (ignore-focus? )
243
267
" Show a Flutter outline tree and focus on it if IGNORE-FOCUS? is nil."
244
268
(interactive " P" )
245
269
(lsp-dart-assert-sdk-min-version " 2.8.0" )
246
- (lsp-dart-outline--show-flutter-outline ( current-buffer ) ignore-focus?) )
270
+ (lsp-dart-outline--show-flutter-outline ignore-focus?) )
247
271
248
272
(provide 'lsp-dart-outline )
249
273
; ;; lsp-dart-outline.el ends here
0 commit comments