3737 :group 'lsp-dart
3838 :type 'string )
3939
40+ (defcustom lsp-dart-devtools-prefer-xwidgets nil
41+ " If t and xwidgets support exists, open the devtools in an xwidget-webkit
42+ view.
43+ NOTE XWidgets are still quite buggy so only enable this if you know you have support"
44+ :group 'lsp-dart
45+ :type 'boolean )
46+
4047(defconst lsp-dart-devtools--buffer-name " *LSP Dart - DevTools*" )
41- (defconst lsp-dart-devtools--pub-list-packages-buffer-name " *LSP Dart - Pub list packages*" )
4248
4349(defun lsp-dart-devtools-log (msg &rest args )
4450 " Custom logger for MSG and ARGS."
@@ -75,15 +81,9 @@ If URI is not found on buffer, schedule re-check."
7581
7682(defun lsp-dart-devtools--activated-p ()
7783 " Return non-nil if devtools is activated otherwise nil."
78- (lsp-dart-devtools--clean-buffer lsp-dart-devtools--pub-list-packages-buffer-name)
79- (let* ((pub (lsp-dart-pub-command))
80- (_proc (call-process pub
81- nil
82- lsp-dart-devtools--pub-list-packages-buffer-name
83- nil
84- " global" " list" ))
85- (content (lsp-dart-devtools--buffer-whole-string lsp-dart-devtools--pub-list-packages-buffer-name)))
86- (string-match-p " devtools \\ ([0-9]\\ .[0-9]\\ .[0-9]\\ )" content)))
84+ (let ((output (shell-command-to-string
85+ (mapconcat 'identity `(,@(lsp-dart-pub-command) " global" " list" ) " " ))))
86+ (string-match-p " devtools \\ ([0-9]\\ .[0-9]\\ .[0-9]\\ )" output)))
8787
8888(defun lsp-dart-devtools--activate (callback )
8989 " Activate Dart Devtools via pub then call CALLBACK."
@@ -95,7 +95,7 @@ If URI is not found on buffer, schedule re-check."
9595 (funcall callback))
9696 (lambda (_ ) (lsp-dart-devtools-log " Could not activate DevTools. \
9797Try to activate manually running 'pub global activate devtools'" ))
98- pub " global" " activate" " devtools" )))
98+ ( mapconcat 'identity `( ,@ pub " global" " activate" " devtools" ) " " ) )))
9999
100100(defun lsp-dart-devtools--check-activated (callback )
101101 " Check if devtools is activated otherwise prompt for activate it.
@@ -120,13 +120,13 @@ If it is already activated or after activated successfully, call CALLBACK."
120120 (lambda ()
121121 (if-let ((uri (lsp-workspace-get-metadata " dart-debug-devtools-uri" )))
122122 (funcall callback uri)
123- (let* ((pub (lsp-dart-pub-command))
124- (proc (start-process " Start DevTools"
125- lsp-dart-devtools--buffer-name
126- pub " global" " run" " devtools"
127- " --machine"
128- " --enable-notifications"
129- " --try-ports" " 10" )))
123+ (let* ((pub (lsp-dart-pub-command))
124+ (proc (apply # ' start-process " Start DevTools"
125+ lsp-dart-devtools--buffer-name
126+ `( ,@ pub " global" " run" " devtools"
127+ " --machine"
128+ " --enable-notifications"
129+ " --try-ports" " 10" ) )))
130130 (add-hook 'dap-terminated-hook (-partial #'lsp-dart-devtools--kill-proc proc))
131131 (when lsp-dart-devtools--check-uri-timer
132132 (cancel-timer lsp-dart-devtools--check-uri-timer))
@@ -140,7 +140,12 @@ If it is already activated or after activated successfully, call CALLBACK."
140140 (hide , lsp-dart-devtools-hide-options )
141141 (theme , lsp-dart-devtools-theme ))))
142142 (url (concat " http://" uri " ?" params)))
143- (browse-url url)))
143+ (if (and lsp-dart-devtools-prefer-xwidgets
144+ (featurep 'xwidget-internal ))
145+ (progn
146+ (select-window (split-window (selected-window ) nil 'right ))
147+ (xwidget-webkit-browse-url url))
148+ (browse-url url))))
144149
145150
146151; ;; Public interface
0 commit comments