Skip to content

Interactive input for go when using vscode-go #987

@ayamir

Description

@ayamir

Debug adapter definition and debug configuration

I installed vscode-go by mason.

	dap.adapters.go = {
		type = "executable",
		command = "node",
		args = {
			require("mason-registry").get_package("go-debug-adapter"):get_install_path()
				.. "/extension/dist/debugAdapter.js",
		},
	}
	dap.configurations.go = {
		{
			type = "go",
			name = "Debug (file)",
			request = "launch",
			cwd = "${workspaceFolder}",
			program = utils.input_file_path(),
			console = "integratedTerminal",
			dlvToolPath = vim.fn.exepath("dlv"),
			showLog = true,
			showRegisters = true,
			stopOnEntry = false,
		},
		{
			type = "go",
			name = "Debug (file with args)",
			request = "launch",
			cwd = "${workspaceFolder}",
			program = utils.input_file_path(),
			args = utils.input_args(),
			console = "integratedTerminal",
			dlvToolPath = vim.fn.exepath("dlv"),
			showLog = true,
			showRegisters = true,
			stopOnEntry = false,
		},
		{
			type = "go",
			name = "Debug (executable)",
			request = "launch",
			cwd = "${workspaceFolder}",
			program = utils.input_exec_path(),
			args = utils.input_args(),
			console = "integratedTerminal",
			dlvToolPath = vim.fn.exepath("dlv"),
			mode = "exec",
			showLog = true,
			showRegisters = true,
			stopOnEntry = false,
		},
		{
			type = "go",
			name = "Debug (test file)",
			request = "launch",
			cwd = "${workspaceFolder}",
			program = utils.input_file_path(),
			console = "integratedTerminal",
			dlvToolPath = vim.fn.exepath("dlv"),
			mode = "test",
			showLog = true,
			showRegisters = true,
			stopOnEntry = false,
		},
		{
			type = "go",
			name = "Debug (using go.mod)",
			request = "launch",
			cwd = "${workspaceFolder}",
			program = "./${relativeFileDirname}",
			console = "integratedTerminal",
			dlvToolPath = vim.fn.exepath("dlv"),
			mode = "test",
			showLog = true,
			showRegisters = true,
			stopOnEntry = false,
		},
	}

Debug adapter version

0.39.1

Steps to Reproduce

Create a test project:

mkdir test_dap_io
cd test_dap_io
touch test_dap_io.go
go mod init
nvim test_dap_io.go

Fill the file content with:

package main

import "fmt"

func main() {
	var n = 0
	fmt.Printf("Enter a number: ")
	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("The enter number is n = %d\n", n)
}
  1. Set the breakpoint at line 8.
  2. Start debug.
  3. Next

Expected Result

Can input in the terminal and redirect it to dap session.

AFAIK vscode-go supports this feature:
https://github.com/golang/vscode-go/wiki/debugging#configuration
https://github.com/golang/vscode-go/wiki/debugging#handling-stdin

Thanks in advance!

Actual Result

image
dap.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions