Skip to content

Commit 7f2f18e

Browse files
committed
placeholder option to install lang debugger
1 parent b393e5e commit 7f2f18e

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,5 @@ __marimo__/
222222
node_modules
223223
build
224224
npm-debug.log
225-
.env
225+
.env
226+
js-debug

custom-debugger/main.go

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func main() {
3434
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options]\n\n", os.Args[0])
3535
flag.PrintDefaults()
3636
}
37+
var install bool
38+
flag.BoolVar(&install, "install", false, "install required language debugger if missing")
3739

3840
flag.Parse()
3941

@@ -46,11 +48,13 @@ func main() {
4648
debuggerStopCh := make(chan struct{}, 1)
4749
switch lang {
4850
case "go":
49-
startDelve(debuggerStopCh)
51+
startDelve(debuggerStopCh, install)
5052
case "python":
51-
startDebugPy(debuggerStopCh)
53+
startDebugPy(debuggerStopCh, install)
54+
case "js":
55+
startJsDebug(debuggerStopCh, install)
5256
default:
53-
log.Printf("Running with lang, expect DAP Debugger to be started on port 2345: %s", lang)
57+
log.Printf("Running with lang %s, expect a language debugger to be started on port 2345", lang)
5458
}
5559

5660
addr := fmt.Sprintf(":%d", proxyPort)
@@ -91,7 +95,10 @@ func main() {
9195
}
9296
}
9397

94-
func startDelve(stopCh <-chan struct{}) {
98+
func startDelve(stopCh <-chan struct{}, install bool) {
99+
if install {
100+
// Install delve
101+
}
95102
// Listen on TCP port for Delve server
96103
l, err := net.Listen("tcp", ":2345")
97104
if err != nil {
@@ -154,30 +161,52 @@ func startDelve(stopCh <-chan struct{}) {
154161
}()
155162
}
156163

157-
func startDebugPy(debuggerStopCh <-chan struct{}) {
164+
func startDebugPy(stopCh <-chan struct{}, install bool) {
165+
if install {
166+
// Install debugpy
167+
}
158168
ctx := context.Background()
159169
cmd := exec.CommandContext(ctx, "python", "-m", "debugpy", "--listen", "2345", "--wait-for-client", "standalone_replay.py")
160170
cmd.Dir = "example/python" // Set working directory to the Python example
161171
cmd.Stdout = os.Stdout
162172
cmd.Stderr = os.Stderr
163173
go func() {
164-
165174
log.Println("Starting Python debugpy server on :2345")
166175
if err := cmd.Run(); err != nil {
167176
log.Printf("Error running Python debugpy: %v", err)
168177
}
169178
}()
170179
go func() {
171-
select {
172-
case <-debuggerStopCh:
173-
if err := cmd.Process.Kill(); err != nil {
174-
log.Printf("Error killing Python debugpy: %v", err)
175-
}
176-
log.Println("Python debugger stopped")
180+
<-stopCh
181+
if err := cmd.Process.Kill(); err != nil {
182+
log.Printf("Error killing Python debugpy: %v", err)
177183
}
184+
log.Println("Python debugger stopped")
178185
}()
179186
}
180187

188+
func startJsDebug(stopCh <-chan struct{}, install bool) {
189+
if install {
190+
// Install js-debug
191+
}
192+
ctx := context.Background()
193+
cmd := exec.CommandContext(ctx, "node", "dapDebugServer.js", "2345", "127.0.0.1")
194+
go func() {
195+
log.Println("Starting JS debug on :2345")
196+
if err := cmd.Run(); err != nil {
197+
log.Printf("Error running JS Debug: %v", err)
198+
}
199+
}()
200+
go func() {
201+
<-stopCh
202+
if err := cmd.Process.Kill(); err != nil {
203+
log.Printf("Error killing JS debug: %v", err)
204+
}
205+
log.Println("JS debug stopped")
206+
}()
207+
208+
}
209+
181210
func init() {
182211
log.SetOutput(os.Stdout)
183212
}

0 commit comments

Comments
 (0)