forked from emacs-lsp/dap-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dap-go.el
145 lines (124 loc) · 6.37 KB
/
dap-go.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;;; dap-go.el --- Debug Adapter Protocol mode for Go -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Aya Igarashi
;; Author: Aya Igarashi <[email protected]>
;; Keywords: languages
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;; URL: https://github.com/yyoncho/dap-mode
;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (lsp-mode "4.0"))
;; Version: 0.2
;;; Commentary:
;; Adapter for https://github.com/Microsoft/vscode-go
;;; Code:
(require 'dap-mode)
(require 'dap-utils)
(defcustom dap-go-debug-path (expand-file-name "vscode/ms-vscode.go" dap-utils-extension-path)
"The path to go vscode extension."
:group 'dap-go
:type 'string)
(defcustom dap-go-debug-program `("node"
,(f-join dap-go-debug-path "extension/out/src/debugAdapter/goDebug.js"))
"The path to the go debugger."
:group 'dap-go
:type '(repeat string))
(defcustom dap-go-delve-path (or (executable-find "dlv")
(expand-file-name "dlv" (expand-file-name "bin" (getenv "GOPATH"))))
"The path to the delve command."
:group 'dap-go
:type 'string)
(dap-utils-vscode-setup-function "dap-go" "ms-vscode" "go" dap-go-debug-path)
(defun dap-go--populate-default-args (conf)
"Populate CONF with the default arguments."
(setq conf (pcase (plist-get conf :mode)
("auto" (dap-go--populate-auto-args conf))
("debug" (dap--put-if-absent conf :program (f-dirname (buffer-file-name))))
("exec" (dap--put-if-absent conf :program (read-file-name "enter full path to executable without tilde:")))
("remote" (dap--put-if-absent conf :program (f-dirname (buffer-file-name)))
(dap--put-if-absent conf :host (read-string "enter host:" "127.0.0.1"))
(dap--put-if-absent conf :port (string-to-number (read-string "Enter port: " "2345"))))
("local"
(dap--put-if-absent conf :cwd (f-dirname (buffer-file-name)))
(dap--put-if-absent conf :processId (string-to-number (read-string "Enter pid: " "2345"))))
))
(if (plist-get conf :args) (plist-put conf :args (split-string (plist-get conf :args))) ())
(-> conf
(dap--put-if-absent :dap-server-path dap-go-debug-program)
(dap--put-if-absent :dlvToolPath dap-go-delve-path)
(dap--put-if-absent :packagePathToGoModPathMap
(ht<-alist `((,(f-dirname (buffer-file-name)) . ,(lsp-find-session-folder (lsp-session) (buffer-file-name))))))
(dap--put-if-absent :type "go")
(dap--put-if-absent :name "Go Debug")))
(defun dap-go--populate-auto-args (conf)
"Populate auto arguments."
(dap--put-if-absent conf :program (buffer-file-name))
(if (string-suffix-p "_test.go" (buffer-file-name))
(plist-put conf :mode "test")
(plist-put conf :mode "debug")))
(dap-register-debug-provider "go" 'dap-go--populate-default-args)
(dap-register-debug-template "Go Launch File Configuration"
(list :type "go"
:request "launch"
:name "Launch File"
:mode "auto"
:program nil
:buildFlags nil
:args nil
:env nil
:envFile nil))
(dap-register-debug-template "Go Launch Debug Package Configuration"
(list :type "go"
:request "launch"
:name "Launch Debug Package"
:mode "debug"
:program nil
:buildFlags nil
:args nil
:env nil
:envFile nil))
(dap-register-debug-template "Go Launch Unoptimized Debug Package Configuration"
(list :type "go"
:request "launch"
:name "Launch Unoptimized Debug Package"
:mode "debug"
:program nil
:buildFlags "-gcflags '-N -l'"
:args nil
:env nil
:envFile nil))
(dap-register-debug-template "Go Launch Executable Configuration"
(list :type "go"
:request "launch"
:name "Launch Executable"
:mode "exec"
:program nil
:args nil
:env nil
:envFile nil))
(dap-register-debug-template "Go Attach Executable Configuration"
(list :type "go"
:request "attach"
:name "Attach to Executable"
:mode "local"
:program nil
:args nil
:env nil
:envFile nil))
(dap-register-debug-template "Go Connect Remote dlv Configuration"
(list :type "go"
:request "launch"
:name "Connect to Remote dlv"
:mode "remote"
:program nil
:args nil
:env nil
:envFile nil))
(provide 'dap-go)
;;; dap-go.el ends here