Skip to content

Commit b0a298d

Browse files
committed
fix: Byte-compile warnings
1 parent ed360fd commit b0a298d

21 files changed

+529
-548
lines changed

dap-chrome.el

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
;; You should have received a copy of the GNU General Public License
1919
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
2020

21-
;; URL: https://github.com/emacs-lsp/dap-mode
22-
;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (lsp-mode "4.0"))
23-
;; Version: 0.2
24-
2521
;;; Commentary:
2622
;; Adapter for https://github.com/chromeide/vscode-chrome
2723

dap-dlv-go.el

Lines changed: 150 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929

3030
(require 'dap-mode)
3131
(require 'dap-utils)
32+
(require 'dap-ui)
3233
(require 'f)
3334
(require 'lsp-mode)
3435
(require 'dash)
3536

3637
(defcustom dap-dlv-go-delve-path
3738
(or (executable-find "dlv")
38-
(expand-file-name
39-
"dlv" (expand-file-name "bin" (or (getenv "GOPATH")
40-
(f-join (getenv "HOME") "go")))))
39+
(expand-file-name
40+
"dlv" (expand-file-name "bin" (or (getenv "GOPATH")
41+
(f-join (getenv "HOME") "go")))))
4142
"The path to the delve command."
4243
:group 'dap-dlv-go
4344
:type 'string)
@@ -47,69 +48,74 @@
4748
:group 'dap-dlv-go
4849
:type 'string)
4950

51+
(defvar vterm-shell)
52+
(defvar vterm-kill-buffer-on-exit)
53+
(declare-function vterm-mode "ext:vterm.el")
54+
5055
(defun dap-dlv-go--populate-default-args (conf)
5156
"Populate CONF with the default arguments."
52-
(setq conf (pcase (plist-get conf :mode)
53-
("auto"
54-
(dap-dlv-go--populate-auto-args conf))
55-
("test"
56-
(dap-dlv-go--populate-test-args conf))
57-
("debug"
58-
(dap--put-if-absent
59-
conf :program (f-dirname (buffer-file-name))))
60-
("exec"
61-
(dap--put-if-absent
62-
conf :program
63-
(f-expand (read-file-name "enter path to executable: "))))
64-
("remote"
65-
(dap--put-if-absent conf :host (read-string "enter host: " "127.0.0.1"))
66-
(dap--put-if-absent conf :debugPort
67-
(string-to-number (read-string "enter port: " "2345"))))
68-
("local"
69-
(dap--put-if-absent conf :cwd (f-dirname (buffer-file-name)))
70-
(dap--put-if-absent
71-
conf :processId (string-to-number (read-string "enter pid: " "2345"))))))
57+
(setq conf
58+
(pcase (plist-get conf :mode)
59+
("auto"
60+
(dap-dlv-go--populate-auto-args conf))
61+
("test"
62+
(dap-dlv-go--populate-test-args conf))
63+
("debug"
64+
(dap--put-if-absent
65+
conf :program (f-dirname (buffer-file-name))))
66+
("exec"
67+
(dap--put-if-absent
68+
conf :program
69+
(f-expand (read-file-name "enter path to executable: "))))
70+
("remote"
71+
(dap--put-if-absent conf :host (read-string "enter host: " "127.0.0.1"))
72+
(dap--put-if-absent conf :debugPort
73+
(string-to-number (read-string "enter port: " "2345"))))
74+
("local"
75+
(dap--put-if-absent conf :cwd (f-dirname (buffer-file-name)))
76+
(dap--put-if-absent
77+
conf :processId (string-to-number (read-string "enter pid: " "2345"))))))
7278

7379
(when-let ((env-file (plist-get conf :envFile)))
74-
(plist-put conf :env (dap-dlv-go--parse-env-file env-file)))
80+
(plist-put conf :env (dap-dlv-go--parse-env-file env-file)))
7581

7682
(let ((debug-port (if (string= (plist-get conf :mode)
77-
"remote")
78-
(plist-get conf :debugPort)
79-
(dap--find-available-port))))
80-
(dap--put-if-absent conf :host "localhost")
81-
(when (not (string= "remote" (plist-get conf :mode)))
82-
(plist-put
83-
conf :program-to-start
84-
(format "%s dap --listen 127.0.0.1:%s %s" dap-dlv-go-delve-path debug-port dap-dlv-go-extra-args)))
85-
(plist-put conf :debugServer debug-port))
83+
"remote")
84+
(plist-get conf :debugPort)
85+
(dap--find-available-port))))
86+
(dap--put-if-absent conf :host "localhost")
87+
(when (not (string= "remote" (plist-get conf :mode)))
88+
(plist-put
89+
conf :program-to-start
90+
(format "%s dap --listen 127.0.0.1:%s %s" dap-dlv-go-delve-path debug-port dap-dlv-go-extra-args)))
91+
(plist-put conf :debugServer debug-port))
8692

8793
(if (stringp (plist-get conf :args)) (plist-put conf :args (split-string (plist-get conf :args))) ())
8894

8995
(when (string= (plist-get conf :name) "Test function")
90-
(-when-let (name (dap-dlv-go--extract-current--method-or-function-name t))
91-
(dap--put-if-absent conf :args (list (format "-test.run=^%s$" name)))))
96+
(-when-let (name (dap-dlv-go--extract-current--method-or-function-name t))
97+
(dap--put-if-absent conf :args (list (format "-test.run=^%s$" name)))))
9298

9399
(when (string= (plist-get conf :name) "Test subtest")
94-
(-when-let (name (concat
95-
(dap-dlv-go--extract-current--method-or-function-name t)
96-
"/"
97-
(shell-quote-argument (dap-dlv-go--extract-current-subtest-name t))))
98-
(dap--put-if-absent conf :args (list (format "-test.run=^%s" name)))))
99-
100+
(-when-let (name (concat
101+
(dap-dlv-go--extract-current--method-or-function-name t)
102+
"/"
103+
(shell-quote-argument (dap-dlv-go--extract-current-subtest-name t))))
104+
(dap--put-if-absent conf :args (list (format "-test.run=^%s" name)))))
105+
100106
(-> conf
101-
(dap--put-if-absent :dlvToolPath dap-dlv-go-delve-path)
102-
103-
(dap--put-if-absent :type "go")
104-
(dap--put-if-absent :name "Go Dlv Debug")))
107+
(dap--put-if-absent :dlvToolPath dap-dlv-go-delve-path)
108+
109+
(dap--put-if-absent :type "go")
110+
(dap--put-if-absent :name "Go Dlv Debug")))
105111

106112
(defun dap-dlv-go--populate-auto-args (conf)
107113
"Populate auto arguments according to CONF."
108114
(dap--put-if-absent conf :program (buffer-file-name))
109115

110116
(if (string-suffix-p "_test.go" (buffer-file-name))
111-
(plist-put conf :mode "test")
112-
(plist-put conf :mode "debug")))
117+
(plist-put conf :mode "test")
118+
(plist-put conf :mode "debug")))
113119

114120
(defun dap-dlv-go--populate-test-args (conf)
115121
"Populate auto arguments according to CONF."
@@ -118,59 +124,59 @@
118124
(defun dap-dlv-go--extract-current--method-or-function-name (&optional no-signal?)
119125
"Extract current method or function name."
120126
(let ((symbols (lsp--get-document-symbols)))
121-
(or (->> symbols
122-
(-keep
123-
(-lambda ((&DocumentSymbol :kind :range :selection-range))
124-
(-let (((beg . end) (lsp--range-to-region range)))
125-
(and (or (= lsp/symbol-kind-method kind)
126-
(= lsp/symbol-kind-function kind))
127-
(<= beg (point) end)
128-
(lsp-region-text selection-range)))))
129-
(car))
130-
(unless no-signal?
131-
(user-error "No method or function at point")))))
127+
(or (->> symbols
128+
(-keep
129+
(-lambda ((&DocumentSymbol :kind :range :selection-range))
130+
(-let (((beg . end) (lsp--range-to-region range)))
131+
(and (or (= lsp/symbol-kind-method kind)
132+
(= lsp/symbol-kind-function kind))
133+
(<= beg (point) end)
134+
(lsp-region-text selection-range)))))
135+
(car))
136+
(unless no-signal?
137+
(user-error "No method or function at point")))))
132138

133139
(defun dap-dlv-go--extract-current-subtest-name (&optional no-signal?)
134140
"Extract current subtest name."
135141
(save-excursion
136-
(save-restriction
137-
(search-backward-regexp "^[[:space:]]*{" nil t)
138-
(search-forward-regexp "name:[[:space:]]+[\"`]\\(.*\\)[\"`]\," nil t)
139-
(or (match-string-no-properties 1)
140-
(unless no-signal?
141-
(user-error "No subtest at point"))))))
142+
(save-restriction
143+
(search-backward-regexp "^[[:space:]]*{" nil t)
144+
(search-forward-regexp "name:[[:space:]]+[\"`]\\(.*\\)[\"`]\," nil t)
145+
(or (match-string-no-properties 1)
146+
(unless no-signal?
147+
(user-error "No subtest at point"))))))
142148

143149
(defun dap-dlv-go--parse-env-file (file)
144150
"Parse env FILE."
145151
(with-temp-buffer
146-
(save-match-data
147-
(find-file file)
148-
(setq-local buffer-file-name nil)
149-
(replace-regexp "[[:space:]]*#.*$" "" nil (point-min) (point-max))
150-
(let ((res (make-hash-table)))
151-
(goto-char (point-min))
152-
(while (search-forward-regexp "\\(^[^=].*\\)=\\(.*\\)$" nil t)
153-
(ht-set res (match-string 1) (match-string 2)))
154-
(kill-buffer)
155-
res))))
152+
(save-match-data
153+
(find-file file)
154+
(setq-local buffer-file-name nil)
155+
(replace-regexp "[[:space:]]*#.*$" "" nil (point-min) (point-max))
156+
(let ((res (make-hash-table)))
157+
(goto-char (point-min))
158+
(while (search-forward-regexp "\\(^[^=].*\\)=\\(.*\\)$" nil t)
159+
(ht-set res (match-string 1) (match-string 2)))
160+
(kill-buffer)
161+
res))))
156162

157163
(defun dap-dlv-go--get-cmd-pid (cmd)
158164
"Return pid of CMD."
159165
(string-to-number
160166
(cadr
161-
(s-split-words
162-
(car
163-
(seq-filter
164-
(lambda(s) (s-contains? cmd s))
165-
(process-lines (executable-find "ps") "aux")))))))
167+
(s-split-words
168+
(car
169+
(seq-filter
170+
(lambda(s) (s-contains? cmd s))
171+
(process-lines (executable-find "ps") "aux")))))))
166172

167173
(defun dap-dlv-go--run-cmd-in-vterm (cmd buf)
168174
"Run CMD with vterm in BUF."
169175
(with-current-buffer buf
170-
(require 'vterm)
171-
(let ((vterm-shell cmd)
172-
(vterm-kill-buffer-on-exit nil))
173-
(vterm-mode))))
176+
(require 'vterm)
177+
(let ((vterm-shell cmd)
178+
(vterm-kill-buffer-on-exit nil))
179+
(vterm-mode))))
174180

175181
(defun dap-dlv-go--run-cmd-in-vterm-get-pid (cmd buf)
176182
"Run CMD in vterm inside BUF and return pid."
@@ -182,80 +188,80 @@
182188
With `C-u' you can edit command before run."
183189
(interactive)
184190
(let* ((exe (f-expand (read-file-name "enter path to executable: ")))
185-
(cmd (if (equal (car current-prefix-arg) 4)
186-
(read-string "command: " exe)
187-
exe))
188-
(buf (generate-new-buffer
189-
(format "*%s console*"
190-
(f-base exe))))
191-
(debug-port (dap--find-available-port))
192-
(pid (dap-dlv-go--run-cmd-in-vterm-get-pid cmd buf)))
193-
(dap-start-debugging-noexpand (list :type "go"
194-
:request "attach"
195-
:name "Attach to running process"
196-
:mode "local"
197-
:host "localhost"
198-
:debugServer debug-port
199-
:processId pid
200-
:dlvToolPath dap-dlv-go-delve-path
201-
:program-to-start
202-
(format
203-
"%s dap --listen 127.0.0.1:%s %s"
204-
dap-dlv-go-delve-path
205-
debug-port
206-
dap-dlv-go-extra-args)))
207-
(display-buffer buf)
208-
(dap-ui--show-buffer buf)))
191+
(cmd (if (equal (car current-prefix-arg) 4)
192+
(read-string "command: " exe)
193+
exe))
194+
(buf (generate-new-buffer
195+
(format "*%s console*"
196+
(f-base exe))))
197+
(debug-port (dap--find-available-port))
198+
(pid (dap-dlv-go--run-cmd-in-vterm-get-pid cmd buf)))
199+
(dap-start-debugging-noexpand (list :type "go"
200+
:request "attach"
201+
:name "Attach to running process"
202+
:mode "local"
203+
:host "localhost"
204+
:debugServer debug-port
205+
:processId pid
206+
:dlvToolPath dap-dlv-go-delve-path
207+
:program-to-start
208+
(format
209+
"%s dap --listen 127.0.0.1:%s %s"
210+
dap-dlv-go-delve-path
211+
debug-port
212+
dap-dlv-go-extra-args)))
213+
(display-buffer buf)
214+
(dap-ui--show-buffer buf)))
209215

210216
(dap-register-debug-provider "go" 'dap-dlv-go--populate-default-args)
211217

212218
(dap-register-debug-template "Go Dlv Launch File Configuration"
213-
(list :type "go"
214-
:request "launch"
215-
:name "Launch File"
216-
:mode "auto"
217-
:program nil
218-
:buildFlags nil
219-
:args nil
220-
:env nil))
219+
(list :type "go"
220+
:request "launch"
221+
:name "Launch File"
222+
:mode "auto"
223+
:program nil
224+
:buildFlags nil
225+
:args nil
226+
:env nil))
221227

222228
(dap-register-debug-template "Go Dlv Attach Configuration"
223-
(list :type "go"
224-
:request "attach"
225-
:name "Attach to running process"
226-
:mode "auto"))
229+
(list :type "go"
230+
:request "attach"
231+
:name "Attach to running process"
232+
:mode "auto"))
227233

228234
(dap-register-debug-template "Go Dlv Launch Executable Configuration"
229-
(list :type "go"
230-
:request "launch"
231-
:name "Launch Executable"
232-
:mode "exec"
233-
:program nil
234-
:args nil
235-
:env nil))
235+
(list :type "go"
236+
:request "launch"
237+
:name "Launch Executable"
238+
:mode "exec"
239+
:program nil
240+
:args nil
241+
:env nil))
236242

237243
(dap-register-debug-template "Go Dlv Remote Debug"
238-
(list :type "go"
239-
:request "attach"
240-
:name "Dlv Remote Debug"
241-
:mode "remote"))
244+
(list :type "go"
245+
:request "attach"
246+
:name "Dlv Remote Debug"
247+
:mode "remote"))
242248

243249
(dap-register-debug-template "Go Dlv Test Current Function Configuration"
244-
(list :type "go"
245-
:request "launch"
246-
:name "Test function"
247-
:mode "test"
248-
:program nil
249-
:args nil
250-
:env nil))
250+
(list :type "go"
251+
:request "launch"
252+
:name "Test function"
253+
:mode "test"
254+
:program nil
255+
:args nil
256+
:env nil))
251257

252258
(dap-register-debug-template "Go Dlv Test Current Subtest Configuration"
253-
(list :type "go"
254-
:request "launch"
255-
:name "Test subtest"
256-
:mode "test"
257-
:program nil
258-
:args nil
259-
:env nil))
259+
(list :type "go"
260+
:request "launch"
261+
:name "Test subtest"
262+
:mode "test"
263+
:program nil
264+
:args nil
265+
:env nil))
260266
(provide 'dap-dlv-go)
261267
;;; dap-dlv-go.el ends here

0 commit comments

Comments
 (0)