2323(require 'lsp-mode )
2424
2525(require 'lsp-dart-protocol )
26+ (require 'lsp-dart-utils )
2627
2728(defcustom lsp-dart-flutter-widget-guides t
2829 " Enable showing ui guides for flutter widgets hierarchy."
@@ -79,16 +80,15 @@ Return nil if the widget guilde does not apply."
7980 (let ((start-pos (lsp-dart-flutter-widget-guide--first-non-whitespace-pos parent-line)))
8081 (->> children-start
8182 (--map (lsp-make-range :start start-pos
82- :end (lsp-dart-flutter-widget-guide--first-non-whitespace-pos it)))
83- (-flatten)))))))
83+ :end (lsp-dart-flutter-widget-guide--first-non-whitespace-pos it)))))))))
8484
8585(lsp-defun lsp-dart-flutter-widget-guide--outline->guides ((outline &as &FlutterOutline :children ))
8686 " Build the widget guides from OUTLINE recursively."
8787 (unless (seq-empty-p children)
8888 (let ((ext-children (->> children
8989 (--map (lsp-dart-flutter-widget-guide--outline->guides it))
9090 (-non-nil)
91- (-flatten)))
91+ (-flatten-n 1 )))
9292 (ext-outline (lsp-dart-flutter-widget-guide--outline->guide outline)))
9393 (if ext-outline
9494 (-concat ext-outline ext-children)
@@ -102,8 +102,8 @@ Return nil if the widget guilde does not apply."
102102 :end (&Position :line end-line)) guide))
103103 (while (<= start-line end-line)
104104 (if-let ((cur-guides (plist-get guides-by-line start-line)))
105- (add-to-list ' guides-by-line (cons start-line (append cur-guides (list guide))))
106- (add-to-list ' guides-by-line (cons start-line (list guide))))
105+ (setq guides-by-line (plist-put guides-by-line start-line (append cur-guides (list guide))))
106+ (setq guides-by-line (plist-put guides-by-line start-line (list guide))))
107107 (setq start-line (1+ start-line)))))
108108 guides-by-line))
109109
@@ -144,16 +144,17 @@ ANCHOR is the anchor point of the widget guide at LINE."
144144 (remove-overlays (point-min ) (point-max ) 'category 'lsp-dart-flutter-widget-guide )
145145 (let* ((guides (lsp-dart-flutter-widget-guide--outline->guides outline))
146146 (guides-by-line (lsp-dart-flutter-widget-guide--guides->guides-by-line guides)))
147- (seq-doseq (line (mapcar 'car guides-by-line))
148- (let* ((guide-lines (alist-get line guides-by-line))
149- (first-guide-char (-min (--map (min (-> it lsp:range-start lsp:position-character)
147+ (lsp-dart-plist-each
148+ (lambda (line guide-lines )
149+ (let* ((first-guide-char (-min (--map (min (-> it lsp:range-start lsp:position-character)
150+ (-> it lsp:range-end lsp:position-character)) guide-lines)))
151+ (last-guide-char (-max (--map (max (-> it lsp:range-start lsp:position-character)
150152 (-> it lsp:range-end lsp:position-character)) guide-lines)))
151- (last-guide-char (-max (--map (max (-> it lsp:range-start lsp:position-character)
152- (-> it lsp:range-end lsp:position-character)) guide-lines)))
153- (last-line-char (lsp-dart-flutter-widget-guide--last-col-at line))
154- (anchor (max 0 (if (< last-line-char first-guide-char) 0 first-guide-char)))
155- (chars (lsp-dart-flutter-widget-guide--build-chars line guide-lines last-guide-char last-line-char anchor)))
156- (--each-indexed chars (lsp-dart-flutter-widget-guide--add-overlay-to buffer line (+ it-index anchor) it))))))))
153+ (last-line-char (lsp-dart-flutter-widget-guide--last-col-at line))
154+ (anchor (max 0 (if (< last-line-char first-guide-char) 0 first-guide-char)))
155+ (chars (lsp-dart-flutter-widget-guide--build-chars line guide-lines last-guide-char last-line-char anchor)))
156+ (--each-indexed chars (lsp-dart-flutter-widget-guide--add-overlay-to buffer line (+ it-index anchor) it))))
157+ guides-by-line)))))
157158
158159(provide 'lsp-dart-flutter-widget-guide )
159160; ;; lsp-dart-flutter-widget-guide.el ends here
0 commit comments