Skip to content

Commit 7ced474

Browse files
committed
Migrate widget guide to have hooks with it own mode
1 parent ecad300 commit 7ced474

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

lsp-dart-flutter-daemon.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
(defun lsp-dart-flutter-daemon--log (level msg &rest args)
3939
"Log for LEVEL, MSG with ARGS adding lsp-dart-flutter-daemon prefix."
40-
(apply #'lsp-dart-custom-log (concat "[FLUTTER " (upcase level) "] ")
41-
msg
42-
args))
40+
(unless (string= "STATUS" (upcase level))
41+
(apply #'lsp-dart-custom-log (concat "[FLUTTER " (upcase level) "] ")
42+
msg
43+
args)))
4344

4445
(defun lsp-dart-flutter-daemon--generate-command-id ()
4546
"Generate a random command id."

lsp-dart-flutter-widget-guide.el

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,18 @@
5050

5151
(defun lsp-dart-flutter-widget-guide--first-non-whitespace-pos (line)
5252
"Return the first non whitepaces position at LINE."
53-
(save-excursion
54-
(goto-char (point-min))
55-
(forward-line line)
56-
(back-to-indentation)
57-
(lsp-make-position :line line
58-
:character (current-column))))
53+
(goto-char (point-min))
54+
(forward-line line)
55+
(back-to-indentation)
56+
(lsp-make-position :line line
57+
:character (current-column)))
5958

6059
(defun lsp-dart-flutter-widget-guide--last-col-at (line)
6160
"Return the last col at LINE."
62-
(save-excursion
63-
(goto-char (point-min))
64-
(forward-line line)
65-
(end-of-line)
66-
(current-column)))
61+
(goto-char (point-min))
62+
(forward-line line)
63+
(end-of-line)
64+
(current-column))
6765

6866
(lsp-defun lsp-dart-flutter-widget-guide--outline->guide ((&FlutterOutline :kind :children :range
6967
(&Range :start
@@ -112,7 +110,8 @@ Return nil if the widget guilde does not apply."
112110
SIZE is the length of the characters list.
113111
LAST-LINE-CHAR is the last column position of LINE.
114112
ANCHOR is the anchor point of the widget guide at LINE."
115-
(let ((chars (make-list size lsp-dart-flutter-widget-guide-space)))
113+
(let ((chars (make-list size lsp-dart-flutter-widget-guide-space))
114+
(max-lisp-eval-depth 1800))
116115
(seq-doseq (guide guide-lines)
117116
(-let* (((&Range :start (&Position :character start-char)
118117
:end (&Position :line end-line :character end-char)) guide)
@@ -141,22 +140,23 @@ ANCHOR is the anchor point of the widget guide at LINE."
141140

142141
(lsp-defun lsp-dart-flutter-widget-guide-check ((&FlutterOutlineNotification :uri :outline))
143142
"Check if there is any widget guide on buffer from uri of OUTLINE-PARAMS."
144-
(-when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
143+
(when-let (buffer (find-buffer-visiting (lsp--uri-to-path uri)))
145144
(with-current-buffer buffer
146145
(remove-overlays (point-min) (point-max) 'category 'lsp-dart-flutter-widget-guide)
147-
(let* ((guides (lsp-dart-flutter-widget-guide--outline->guides outline))
148-
(guides-by-line (lsp-dart-flutter-widget-guide--guides->guides-by-line guides)))
149-
(lsp-dart-plist-each
150-
(lambda (line guide-lines)
151-
(let* ((first-guide-char (-min (--map (min (-> it lsp:range-start lsp:position-character)
152-
(-> it lsp:range-end lsp:position-character)) guide-lines)))
153-
(last-guide-char (-max (--map (max (-> it lsp:range-start lsp:position-character)
154-
(-> it lsp:range-end lsp:position-character)) guide-lines)))
155-
(last-line-char (lsp-dart-flutter-widget-guide--last-col-at line))
156-
(anchor (max 0 (if (< last-line-char first-guide-char) 0 first-guide-char)))
157-
(chars (lsp-dart-flutter-widget-guide--build-chars line guide-lines last-guide-char last-line-char anchor)))
158-
(--each-indexed chars (lsp-dart-flutter-widget-guide--add-overlay-to buffer line (+ it-index anchor) it))))
159-
guides-by-line)))))
146+
(save-excursion
147+
(->> outline
148+
(lsp-dart-flutter-widget-guide--outline->guides)
149+
(lsp-dart-flutter-widget-guide--guides->guides-by-line)
150+
(lsp-dart-plist-each
151+
(lambda (line guide-lines)
152+
(let* ((first-guide-char (-min (--map (min (-> it lsp:range-start lsp:position-character)
153+
(-> it lsp:range-end lsp:position-character)) guide-lines)))
154+
(last-guide-char (-max (--map (max (-> it lsp:range-start lsp:position-character)
155+
(-> it lsp:range-end lsp:position-character)) guide-lines)))
156+
(last-line-char (lsp-dart-flutter-widget-guide--last-col-at line))
157+
(anchor (max 0 (if (< last-line-char first-guide-char) 0 first-guide-char)))
158+
(chars (lsp-dart-flutter-widget-guide--build-chars line guide-lines last-guide-char last-line-char anchor)))
159+
(--each-indexed chars (lsp-dart-flutter-widget-guide--add-overlay-to buffer line (+ it-index anchor) it))))))))))
160160

161161
(define-minor-mode lsp-dart-flutter-widget-guides-mode
162162
"Mode for displaying flutter widget guide lines."
@@ -169,9 +169,5 @@ ANCHOR is the anchor point of the widget guide at LINE."
169169
(remove-overlays (point-min) (point-max) 'category 'lsp-dart-flutter-widget-guide)
170170
(remove-hook 'lsp-dart-outline-arrived-hook #'lsp-dart-flutter-widget-guide-check t)))))
171171

172-
(add-hook 'lsp-before-open-hook (lambda ()
173-
(when lsp-dart-flutter-widget-guides
174-
(lsp-dart-flutter-widget-guides-mode 1))))
175-
176172
(provide 'lsp-dart-flutter-widget-guide)
177173
;;; lsp-dart-flutter-widget-guide.el ends here

lsp-dart.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ PARAMS is the data sent from server."
101101
(lsp-dart-workspace-status "Analyzing project..." workspace)
102102
(lsp-dart-workspace-status nil workspace)))
103103

104+
(defun lsp-dart--activate-features ()
105+
"Activate lsp-dart features if enabled."
106+
(when lsp-dart-flutter-widget-guides
107+
(lsp-dart-flutter-widget-guides-mode 1)))
108+
104109
(lsp-register-client
105110
(make-lsp-client :new-connection
106-
(lsp-stdio-connection 'lsp-dart--server-command)
111+
(lsp-stdio-connection #'lsp-dart--server-command)
107112
:major-modes '(dart-mode)
108113
:priority -1
109114
:initialization-options
@@ -117,6 +122,7 @@ PARAMS is the data sent from server."
117122
("dart/textDocument/publishOutline" #'lsp-dart-outline-handle-outline)
118123
("dart/textDocument/publishFlutterOutline" #'lsp-dart-outline-handle-flutter-outline)
119124
("$/analyzerStatus" #'lsp-dart--handle-analyzer-status))
125+
:after-open-fn #'lsp-dart--activate-features
120126
:server-id 'dart_analysis_server))
121127

122128

0 commit comments

Comments
 (0)