Skip to content

Commit d935536

Browse files
committed
Migrate outline & flutter outline
1 parent f6c7b53 commit d935536

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

lsp-dart-flutter-widget-guide.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ ANCHOR is the anchor point of the widget guide at LINE."
163163
nil nil nil
164164
(cond
165165
(lsp-dart-flutter-widget-guides-mode
166-
(add-hook 'lsp-dart-outline-arrived-hook #'lsp-dart-flutter-widget-guide-check nil t))
166+
(add-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart-flutter-widget-guide-check nil t))
167167
(t
168168
(progn
169169
(remove-overlays (point-min) (point-max) 'category 'lsp-dart-flutter-widget-guide)
170-
(remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart-flutter-widget-guide-check t)))))
170+
(remove-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart-flutter-widget-guide-check t)))))
171171

172172
(provide 'lsp-dart-flutter-widget-guide)
173173
;;; lsp-dart-flutter-widget-guide.el ends here

lsp-dart-outline.el

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Defaults to side following treemacs default."
6060

6161
;;; Internal
6262

63+
(defvar-local lsp-dart-current-outline nil)
64+
(defvar-local lsp-dart-current-flutter-outline nil)
65+
66+
(defconst lsp-dart--outline-buffer-name "*Dart Outline*")
67+
(defconst lsp-dart--flutter-outline-buffer-name "*Flutter Outline*")
68+
6369
(defun lsp-dart-outline--set-metadata (workspace params key-prefix)
6470
"Save in WORKSPACE the PARAMS metadata with KEY-PREFIX.
6571
The key is composed of the KEY-PREFIX with PARAMS uri path."
@@ -176,7 +182,7 @@ OUTLINES are the outline items."
176182
(lsp-dart-outline--outlines->tree uri outlines)
177183
"Outline"
178184
t
179-
"*Dart Outline*")))
185+
lsp-dart--outline-buffer-name)))
180186

181187
(defun lsp-dart-outline--render-flutter-outline-tree (uri outlines)
182188
"Render an Flutter outline view with the source URI and OUTLINES data."
@@ -185,65 +191,88 @@ OUTLINES are the outline items."
185191
(lsp-dart-outline--flutter-outline->tree uri outlines)
186192
"Flutter Outline"
187193
t
188-
"*Flutter Outline*")))
194+
lsp-dart--flutter-outline-buffer-name)))
189195

190-
(defun lsp-dart-outline--show-outline (buffer ignore-focus?)
196+
(defun lsp-dart-outline--show-outline (ignore-focus?)
191197
"Show an outline tree for BUFFER.
192198
Focus on it if IGNORE-FOCUS? is nil."
193-
(-when-let ((&OutlineNotification? :uri :outline (&Outline :children)) (lsp-dart-outline--get-metadata buffer "current-outline"))
199+
(-if-let ((&OutlineNotification? :uri :outline (&Outline :children)) lsp-dart-current-outline)
194200
(-let* ((tree-buffer (lsp-dart-outline--render-outline-tree uri children))
195201
(window (display-buffer-in-side-window tree-buffer lsp-dart-outline-position-params)))
196202
(unless ignore-focus?
197203
(select-window window)
198-
(set-window-dedicated-p window t)))))
204+
(set-window-dedicated-p window t)))
205+
(lsp-dart-log "No Dart outline data found")))
199206

200-
(defun lsp-dart-outline--show-flutter-outline (buffer ignore-focus?)
207+
(defun lsp-dart-outline--show-flutter-outline (ignore-focus?)
201208
"Show a Flutter outline tree for BUFFER.
202209
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"))
210+
(-if-let ((&FlutterOutlineNotification? :uri :outline (&FlutterOutline :children)) lsp-dart-current-flutter-outline)
204211
(-let* ((tree-buffer (lsp-dart-outline--render-flutter-outline-tree uri children))
205212
(window (display-buffer-in-side-window tree-buffer lsp-dart-flutter-outline-position-params)))
206213
(unless ignore-focus?
207214
(select-window window)
208-
(set-window-dedicated-p window t)))))
215+
(set-window-dedicated-p window t)))
216+
(lsp-dart-log "No Flutter outline data found")))
209217

210-
(lsp-defun lsp-dart-outline-handle-outline (workspace (notification &as &OutlineNotification :uri :outline))
218+
(lsp-defun lsp-dart--outline-check ((notification &as &OutlineNotification :uri :outline))
211219
"Outline notification handling from WORKSPACE.
212220
NOTIFICATION is outline notification data received from server.
213221
It updates the outline view if it already exists."
214-
(lsp-dart-outline--set-metadata workspace notification "current-outline")
215222
(when lsp-dart-main-code-lens
216223
(lsp-dart-code-lens-check-main uri outline))
217224
(when lsp-dart-test-code-lens
218225
(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)))
226+
(when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
227+
(with-current-buffer buffer
228+
(setq lsp-dart-current-outline notification)
229+
(when (get-buffer-window lsp-dart--outline-buffer-name)
230+
(lsp-dart-outline--show-outline t)))))
221231

222-
(lsp-defun lsp-dart-outline-handle-flutter-outline (workspace (notification &as &FlutterOutlineNotification :uri))
232+
(lsp-defun lsp-dart--flutter-outline-check ((notification &as &FlutterOutlineNotification :uri))
223233
"Flutter outline notification handling from WORKSPACE.
224234
NOTIFICATION is Flutter outline notification data received from server.
225235
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)))
236+
(when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
237+
(with-current-buffer buffer
238+
(setq lsp-dart-current-flutter-outline notification)
239+
(when (get-buffer-window lsp-dart--flutter-outline-buffer-name)
240+
(lsp-dart-outline--show-flutter-outline t)))))
230241

231242

232243
;;; Public interface
233244

245+
(define-minor-mode lsp-dart-outline-mode
246+
"Mode for updating outline."
247+
nil nil nil
248+
(cond
249+
(lsp-dart-outline-mode
250+
(add-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--outline-check nil t))
251+
(t
252+
(remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart--outline-check t))))
253+
254+
(define-minor-mode lsp-dart-flutter-outline-mode
255+
"Mode for updating flutter outline."
256+
nil nil nil
257+
(cond
258+
(lsp-dart-flutter-outline-mode
259+
(add-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart--flutter-outline-check nil t))
260+
(t
261+
(remove-hook 'lsp-dart-flutter-outline-arrived-hook #'lsp-dart--flutter-outline-check t))))
262+
234263
;;;###autoload
235264
(defun lsp-dart-show-outline (ignore-focus?)
236265
"Show an outline tree and focus on it if IGNORE-FOCUS? is nil."
237266
(interactive "P")
238267
(lsp-dart-assert-sdk-min-version "2.8.0")
239-
(lsp-dart-outline--show-outline (current-buffer) ignore-focus?))
268+
(lsp-dart-outline--show-outline ignore-focus?))
240269

241270
;;;###autoload
242271
(defun lsp-dart-show-flutter-outline (ignore-focus?)
243272
"Show a Flutter outline tree and focus on it if IGNORE-FOCUS? is nil."
244273
(interactive "P")
245274
(lsp-dart-assert-sdk-min-version "2.8.0")
246-
(lsp-dart-outline--show-flutter-outline (current-buffer) ignore-focus?))
275+
(lsp-dart-outline--show-flutter-outline ignore-focus?))
247276

248277
(provide 'lsp-dart-outline)
249278
;;; lsp-dart-outline.el ends here

lsp-dart.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ PARAMS is the data sent from server."
108108
(when lsp-dart-flutter-fringe-colors
109109
(lsp-dart-flutter-fringe-colors-mode 1))
110110
(when lsp-dart-closing-labels
111-
(lsp-dart-closing-labels-mode 1)))
111+
(lsp-dart-closing-labels-mode 1))
112+
(when lsp-dart-outline
113+
(lsp-dart-outline-mode 1))
114+
(when lsp-dart-flutter-outline
115+
(lsp-dart-flutter-outline-mode 1)))
112116

113117
(lsp-register-client
114118
(make-lsp-client :new-connection
@@ -124,8 +128,10 @@ PARAMS is the data sent from server."
124128
:library-folders-fn (lambda (_workspace) (lsp-dart--library-folders))
125129
:notification-handlers (lsp-ht ("dart/textDocument/publishClosingLabels" (lambda (_workspace notification)
126130
(run-hook-with-args 'lsp-dart-closing-labels-arrived-hook notification)))
127-
("dart/textDocument/publishOutline" #'lsp-dart-outline-handle-outline)
128-
("dart/textDocument/publishFlutterOutline" #'lsp-dart-outline-handle-flutter-outline)
131+
("dart/textDocument/publishOutline" (lambda (_workspace notification)
132+
(run-hook-with-args 'lsp-dart-outline-arrived-hook notification)))
133+
("dart/textDocument/publishFlutterOutline" (lambda (_workspace notification)
134+
(run-hook-with-args 'lsp-dart-flutter-outline-arrived-hook notification)))
129135
("$/analyzerStatus" #'lsp-dart--handle-analyzer-status))
130136
:after-open-fn #'lsp-dart--activate-features
131137
:server-id 'dart_analysis_server))

0 commit comments

Comments
 (0)