daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
369 stars 42 forks source link

Go fails to compile as compiler is not launched in proper directory #174

Closed jcowgar closed 1 year ago

jcowgar commented 1 year ago

I have a simple hello world program. When attempting to debug, I receive the error:

DAP server listening at: 127.0.0.1:34191
‌​Build Error: go build -o /home/jeremy/projects/hello_world/__debug_bin -gcflags all=-N -l /home/jeremy/projects/hello_world/cmd/tools/hello_world
go: go.mod file not found in current directory or any parent directory; see 'go help modules' (exit status 1)
Failed to launch: Build error: Check the debug console for details.‌​​​​​​​
Debugging ended

go.mod does exist in /home/jeremy/projects/hello_world. When I go to that directory in my terminal and run the "go build" command above, a binary is built successfully.

[~/projects/hello_world]
jeremy-> go build -o /home/jeremy/projects/hello_world/__debug_bin -gcflags "all=-N -l" /home/jeremy/projects/hello_world/cmd/tools/hello_world

[~/projects/hello_world]
jeremy-> ls -lah __debug_bin
-rwxr-xr-x 1 jeremy jeremy 1.8M Sep 15 07:39 __debug_bin

My sublime-project is

{
    "folders": [
        {
            "path": ".",
        }
    ],
    "debugger_configurations": [
        {
            "name": "Debug Hello World",
            "type": "go",
            "request": "launch",
            "output": "${project_path}/__debug_bin",
            "program": "${project_path}/cmd/tools/hello_world",
            "cwd": "${project_path}"
        },
    ],
}
louis77 commented 1 year ago

Same problem here.

daveleroy commented 1 year ago

Try setting dlvCwd listed here https://pkg.go.dev/github.com/go-delve/delve/service/dap#LaunchConfig

// DlvCwd is the new working directory for Delve server.
// If specified, the server will change its working
// directory to the specified directory using os.Chdir.
// Any other launch attributes with relative paths interpreted
// using Delve's working directory will use this new directory.
// When Delve needs to build the program (in debug/test modes),
// it will run the go command from this directory as well.
//
// If a relative path is provided as DlvCwd, it will be
// interpreted as a path relative to Delve's current working
// directory.
DlvCwd string `json:"dlvCwd,omitempty"`
louis77 commented 1 year ago

That worked, thank you!

jcowgar commented 1 year ago

Thank you for that! It works!