Skip to content

Commit f02daae

Browse files
authored
Merge pull request #177 from elken/fix/devtools
Devtools improvements
2 parents a312fe8 + 65b308b commit f02daae

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ matching names.
150150

151151
You can also open the [Dart DevTools](https://dart.dev/tools/dart-devtools) on the current debug session with `lsp-dart-open-devtools`.
152152

153+
It's also possible to spawn the devtools inside an
154+
[XWidgets](https://www.emacswiki.org/emacs/EmacsXWidgets) frame by enabling
155+
`lsp-dart-devtools-prefer-xwidgets` and ensuring that your emacs has proper
156+
support for xwidgets frames.
157+
158+
NVIDIA users may have to enable the below environment variables:
159+
160+
``` shell
161+
WEBKIT_DISABLE_COMPOSITING_MODE=1
162+
WEBKIT_FORCE_SANDBOX=0
163+
```
164+
165+
153166
### Commands
154167

155168
lsp-dart supports running Flutter and Dart commands as following:

lsp-dart-devtools.el

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@
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. \
9797
Try 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

Comments
 (0)