Skip to content

Commit 4a2ca84

Browse files
committed
fix: Headers and indentation
1 parent 84b7e3d commit 4a2ca84

17 files changed

+419
-470
lines changed

dap-dlv-go.el

+142-146
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") (f "0.20.0"))
23-
;; Version: 0.1
24-
2521
;;; Commentary:
2622
;; Adapter for https://github.com/go-delve/delve
2723

@@ -36,9 +32,9 @@
3632

3733
(defcustom dap-dlv-go-delve-path
3834
(or (executable-find "dlv")
39-
(expand-file-name
40-
"dlv" (expand-file-name "bin" (or (getenv "GOPATH")
41-
(f-join (getenv "HOME") "go")))))
35+
(expand-file-name
36+
"dlv" (expand-file-name "bin" (or (getenv "GOPATH")
37+
(f-join (getenv "HOME") "go")))))
4238
"The path to the delve command."
4339
:group 'dap-dlv-go
4440
:type 'string)
@@ -55,67 +51,67 @@
5551
(defun dap-dlv-go--populate-default-args (conf)
5652
"Populate CONF with the default arguments."
5753
(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"))))))
54+
(pcase (plist-get conf :mode)
55+
("auto"
56+
(dap-dlv-go--populate-auto-args conf))
57+
("test"
58+
(dap-dlv-go--populate-test-args conf))
59+
("debug"
60+
(dap--put-if-absent
61+
conf :program (f-dirname (buffer-file-name))))
62+
("exec"
63+
(dap--put-if-absent
64+
conf :program
65+
(f-expand (read-file-name "enter path to executable: "))))
66+
("remote"
67+
(dap--put-if-absent conf :host (read-string "enter host: " "127.0.0.1"))
68+
(dap--put-if-absent conf :debugPort
69+
(string-to-number (read-string "enter port: " "2345"))))
70+
("local"
71+
(dap--put-if-absent conf :cwd (f-dirname (buffer-file-name)))
72+
(dap--put-if-absent
73+
conf :processId (string-to-number (read-string "enter pid: " "2345"))))))
7874

7975
(when-let ((env-file (plist-get conf :envFile)))
80-
(plist-put conf :env (dap-dlv-go--parse-env-file env-file)))
76+
(plist-put conf :env (dap-dlv-go--parse-env-file env-file)))
8177

8278
(let ((debug-port (if (string= (plist-get conf :mode)
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))
79+
"remote")
80+
(plist-get conf :debugPort)
81+
(dap--find-available-port))))
82+
(dap--put-if-absent conf :host "localhost")
83+
(when (not (string= "remote" (plist-get conf :mode)))
84+
(plist-put
85+
conf :program-to-start
86+
(format "%s dap --listen 127.0.0.1:%s %s" dap-dlv-go-delve-path debug-port dap-dlv-go-extra-args)))
87+
(plist-put conf :debugServer debug-port))
9288

9389
(if (stringp (plist-get conf :args)) (plist-put conf :args (split-string (plist-get conf :args))) ())
9490

9591
(when (string= (plist-get conf :name) "Test function")
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)))))
92+
(-when-let (name (dap-dlv-go--extract-current--method-or-function-name t))
93+
(dap--put-if-absent conf :args (list (format "-test.run=^%s$" name)))))
9894

9995
(when (string= (plist-get conf :name) "Test subtest")
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)))))
96+
(-when-let (name (concat
97+
(dap-dlv-go--extract-current--method-or-function-name t)
98+
"/"
99+
(shell-quote-argument (dap-dlv-go--extract-current-subtest-name t))))
100+
(dap--put-if-absent conf :args (list (format "-test.run=^%s" name)))))
105101

106102
(-> conf
107-
(dap--put-if-absent :dlvToolPath dap-dlv-go-delve-path)
103+
(dap--put-if-absent :dlvToolPath dap-dlv-go-delve-path)
108104

109-
(dap--put-if-absent :type "go")
110-
(dap--put-if-absent :name "Go Dlv Debug")))
105+
(dap--put-if-absent :type "go")
106+
(dap--put-if-absent :name "Go Dlv Debug")))
111107

112108
(defun dap-dlv-go--populate-auto-args (conf)
113109
"Populate auto arguments according to CONF."
114110
(dap--put-if-absent conf :program (buffer-file-name))
115111

116112
(if (string-suffix-p "_test.go" (buffer-file-name))
117-
(plist-put conf :mode "test")
118-
(plist-put conf :mode "debug")))
113+
(plist-put conf :mode "test")
114+
(plist-put conf :mode "debug")))
119115

120116
(defun dap-dlv-go--populate-test-args (conf)
121117
"Populate auto arguments according to CONF."
@@ -124,59 +120,59 @@
124120
(defun dap-dlv-go--extract-current--method-or-function-name (&optional no-signal?)
125121
"Extract current method or function name."
126122
(let ((symbols (lsp--get-document-symbols)))
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")))))
123+
(or (->> symbols
124+
(-keep
125+
(-lambda ((&DocumentSymbol :kind :range :selection-range))
126+
(-let (((beg . end) (lsp--range-to-region range)))
127+
(and (or (= lsp/symbol-kind-method kind)
128+
(= lsp/symbol-kind-function kind))
129+
(<= beg (point) end)
130+
(lsp-region-text selection-range)))))
131+
(car))
132+
(unless no-signal?
133+
(user-error "No method or function at point")))))
138134

139135
(defun dap-dlv-go--extract-current-subtest-name (&optional no-signal?)
140136
"Extract current subtest name."
141137
(save-excursion
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"))))))
138+
(save-restriction
139+
(search-backward-regexp "^[[:space:]]*{" nil t)
140+
(search-forward-regexp "name:[[:space:]]+[\"`]\\(.*\\)[\"`]\," nil t)
141+
(or (match-string-no-properties 1)
142+
(unless no-signal?
143+
(user-error "No subtest at point"))))))
148144

149145
(defun dap-dlv-go--parse-env-file (file)
150146
"Parse env FILE."
151147
(with-temp-buffer
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))))
148+
(save-match-data
149+
(find-file file)
150+
(setq-local buffer-file-name nil)
151+
(replace-regexp "[[:space:]]*#.*$" "" nil (point-min) (point-max))
152+
(let ((res (make-hash-table)))
153+
(goto-char (point-min))
154+
(while (search-forward-regexp "\\(^[^=].*\\)=\\(.*\\)$" nil t)
155+
(ht-set res (match-string 1) (match-string 2)))
156+
(kill-buffer)
157+
res))))
162158

163159
(defun dap-dlv-go--get-cmd-pid (cmd)
164160
"Return pid of CMD."
165161
(string-to-number
166162
(cadr
167-
(s-split-words
168-
(car
169-
(seq-filter
170-
(lambda(s) (s-contains? cmd s))
171-
(process-lines (executable-find "ps") "aux")))))))
163+
(s-split-words
164+
(car
165+
(seq-filter
166+
(lambda(s) (s-contains? cmd s))
167+
(process-lines (executable-find "ps") "aux")))))))
172168

173169
(defun dap-dlv-go--run-cmd-in-vterm (cmd buf)
174170
"Run CMD with vterm in BUF."
175171
(with-current-buffer buf
176-
(require 'vterm)
177-
(let ((vterm-shell cmd)
178-
(vterm-kill-buffer-on-exit nil))
179-
(vterm-mode))))
172+
(require 'vterm)
173+
(let ((vterm-shell cmd)
174+
(vterm-kill-buffer-on-exit nil))
175+
(vterm-mode))))
180176

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

216212
(dap-register-debug-provider "go" 'dap-dlv-go--populate-default-args)
217213

218214
(dap-register-debug-template "Go Dlv Launch File Configuration"
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))
215+
(list :type "go"
216+
:request "launch"
217+
:name "Launch File"
218+
:mode "auto"
219+
:program nil
220+
:buildFlags nil
221+
:args nil
222+
:env nil))
227223

228224
(dap-register-debug-template "Go Dlv Attach Configuration"
229-
(list :type "go"
230-
:request "attach"
231-
:name "Attach to running process"
232-
:mode "auto"))
225+
(list :type "go"
226+
:request "attach"
227+
:name "Attach to running process"
228+
:mode "auto"))
233229

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

243239
(dap-register-debug-template "Go Dlv Remote Debug"
244-
(list :type "go"
245-
:request "attach"
246-
:name "Dlv Remote Debug"
247-
:mode "remote"))
240+
(list :type "go"
241+
:request "attach"
242+
:name "Dlv Remote Debug"
243+
:mode "remote"))
248244

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

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

dap-gdb-lldb.el

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +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-
;; Version: 0.2
23-
2421
;;; Commentary:
2522
;; Adapter for https://github.com/WebFreak001/code-debug
2623

0 commit comments

Comments
 (0)