Skip to content

Commit 5e490c3

Browse files
committed
Add mouse support to flutter outline view
1 parent 8b231af commit 5e490c3

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lsp-dart.el

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ ITEMS is the outline items data."
181181
:ret-action (lambda (&rest _) (lsp-dart--outline-tree-ret-action uri range)))))
182182
items))
183183

184+
(defun lsp-dart--build-flutter-outline-widget-actions (uri range)
185+
"Build the action options for the Flutter outline tree view.
186+
URI is the source of the outline.
187+
RANGE is the range for currently build item."
188+
(-when-let (buffer (lsp--buffer-for-file (lsp--uri-to-path uri)))
189+
(with-current-buffer buffer
190+
(goto-char (-> range lsp--range-to-region car))
191+
(->> (lsp-code-actions-at-point)
192+
(-filter (-lambda ((&hash "kind"))
193+
(and kind (equal "refactor" kind))))
194+
(-map (-lambda ((action &as &hash "title"))
195+
`[,title (lsp-execute-code-action ,action)]))))))
196+
184197
(defun lsp-dart--flutter-outline->tree (uri items)
185198
"Builds a Flutter outline tree.
186199
URI is the source of the outline.
@@ -204,24 +217,29 @@ ITEMS is the outline items data."
204217
:children (lambda (&rest _)
205218
(unless (seq-empty-p children)
206219
(lsp-dart--flutter-outline->tree uri children)))
207-
:ret-action (lambda (&rest _) (lsp-dart--outline-tree-ret-action uri range)))))
220+
:ret-action (lambda (&rest _) (lsp-dart--outline-tree-ret-action uri range))
221+
:actions (when widget?
222+
(lsp-dart--build-flutter-outline-widget-actions uri range))
223+
:uri uri)))
208224
items))
209225

210226
(defun lsp-dart--render-outline-tree (uri outline)
211227
"Render an outline view with the source URI and an OUTLINE data."
212-
(lsp-treemacs-render
213-
(lsp-dart--outline->tree uri outline)
214-
"Outline"
215-
t
216-
"*Dart Outline*"))
228+
(save-excursion
229+
(lsp-treemacs-render
230+
(lsp-dart--outline->tree uri outline)
231+
"Outline"
232+
t
233+
"*Dart Outline*")))
217234

218235
(defun lsp-dart--render-flutter-outline-tree (uri outline)
219236
"Render an Flutter outline view with the source URI and an OUTLINE data."
220-
(lsp-treemacs-render
221-
(lsp-dart--flutter-outline->tree uri outline)
222-
"Flutter Outline"
223-
t
224-
"*Flutter Outline*"))
237+
(save-excursion
238+
(lsp-treemacs-render
239+
(lsp-dart--flutter-outline->tree uri outline)
240+
"Flutter Outline"
241+
t
242+
"*Flutter Outline*")))
225243

226244
(defun lsp-dart--show-outline (ignore-focus?)
227245
"Show an outline tree.

0 commit comments

Comments
 (0)