Delve debugger splits command line argument by space #117

Closed
opened 2025-03-18 02:24:23 +03:00 by chubi-x · 1 comment
chubi-x commented 2025-03-18 02:24:23 +03:00 (Migrated from github.com)

I have a program that is supposed to take a json string as input and run some token extraction logic. I'm using flag.Parse to parse the string from the command line and this works when i run the compiled file. However, when i try to debug the code in neovim with delve through nvim-dap-go my string is split by space into separate arguments.

Could there be some bug in the way nvim-dap-go handles delve? Because everything works fine from the command line. It only breaks when i run it with nvim-dap-go.

Here's the source code:

import (
	"flag"
	"io"
	"os"
)
var fileName string
var buf *bytes.Buffer = bytes.NewBuffer(make([]byte, 0))
    flag.StringVar(&fileName, "file", "", "Path to JSON file")
    flag.Parse()
    if fileName != "" {

		openFile, err := os.Open(fileName)

		_, copyErr := io.Copy(buf, openFile)
		handleError("Unable to read file ", err)
		handleError("Error opening file "+fileName, copyErr)
		defer openFile.Close()
	} else if jsonString := flag.Arg(0); jsonString == "" && fileName == "" {
		_, err := io.Copy(buf, os.Stdin)
		handleError("Unable to read from Stdin", err)
	} else {
		buf = bytes.NewBufferString(jsonString)
	}
	Lex(buf)

So if I pass the string '{"key": "value"}' to the program through nvim-dap-go, it's split into '{"key": and "value"}' and so i get only the first half saved into jsonString

Here's my config:

return {

  "mfussenegger/nvim-dap",
  dependencies = {
    "rcarriga/nvim-dap-ui",
    "mfussenegger/nvim-dap-python",
    "nvim-neotest/nvim-nio",
    "theHamsta/nvim-dap-virtual-text",
    "leoluz/nvim-dap-go",
  },
  config = function()
    local dap, dapui = require("dap"), require("dapui")
    local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/")

    require("mason-nvim-dap").setup()
    require("dap-go").setup()
    require("nvim-dap-virtual-text").setup({})
    dapui.setup()
    dap.listeners.before.attach.dapui_config = function()
      dapui.open()
    end
    dap.listeners.before.launch.dapui_config = function()
      dapui.open()
    end
    dap.listeners.before.event_terminated.dapui_config = function()
      dapui.close()
    end
    dap.listeners.before.event_exited.dapui_config = function()
      dapui.close()
    end

    vim.keymap.set("n", "<leader>dc", function()
      dap.continue()
    end, { desc = "continue debugger" })

    vim.keymap.set("n", "<leader>dk", function()
      dap.close()
    end, { desc = "kill debugger" })
    vim.keymap.set("n", "<leader>du", function()
      require("dapui").toggle({ reset = true })
    end, { desc = "Toggle UI" })

    vim.keymap.set("n", "<Leader>dso", function()
      dap.step_over()
    end, { desc = "Step over" })
    vim.keymap.set("n", "<Leader>dsi", function()
      dap.step_into()
    end, { desc = "Step in" })
    vim.keymap.set("n", "<Leader>dso", function()
      dap.step_out()
    end, { desc = "Step out" })

    vim.keymap.set("n", "<Leader>db", function()
      dap.toggle_breakpoint()
    end, { desc = "Toggle breakpoint" })
    vim.keymap.set("n", "<Leader>B", function()
      dap.set_breakpoint()
    end, { desc = "Set breakpoint" })
    vim.keymap.set("n", "<Leader>lp", function()
      dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: "))
    end, { desc = "Log point message" })
    -- vim.keymap.set("n", "<Leader>dr", function()
    --   dap.repl.open()
    -- end, { desc = "Open REPL" })
    vim.keymap.set("n", "<Leader>dl", function()
      dap.run_last()
    end, { desc = "Run last" })
    vim.keymap.set({ "n", "v" }, "<Leader>dh", function()
      require("dap.ui.widgets").hover()
    end, { desc = "Hover" })
    vim.keymap.set({ "n", "v" }, "<Leader>dp", function()
      require("dap.ui.widgets").preview()
    end, { desc = "Preview" })
    vim.keymap.set("n", "<Leader>df", function()
      local widgets = require("dap.ui.widgets")
      widgets.centered_float(widgets.frames)
    end, { desc = "Open Frames" })
    vim.keymap.set("n", "<Leader>ds", function()
      local widgets = require("dap.ui.widgets")
      widgets.centered_float(widgets.scopes)
    end, { desc = "Open Scopes" })
  end,
}

Here are screenshots from the debugger vs the command line:

command line arguments and print out

delve arguments

delve print out

I have a program that is supposed to take a json string as input and run some token extraction logic. I'm using `flag.Parse` to parse the string from the command line and this works when i run the compiled file. However, when i try to debug the code in neovim with delve through nvim-dap-go my string is split by space into separate arguments. Could there be some bug in the way `nvim-dap-go` handles delve? Because everything works fine from the command line. It only breaks when i run it with nvim-dap-go. Here's the source code: ``` import ( "flag" "io" "os" ) var fileName string var buf *bytes.Buffer = bytes.NewBuffer(make([]byte, 0)) flag.StringVar(&fileName, "file", "", "Path to JSON file") flag.Parse() if fileName != "" { openFile, err := os.Open(fileName) _, copyErr := io.Copy(buf, openFile) handleError("Unable to read file ", err) handleError("Error opening file "+fileName, copyErr) defer openFile.Close() } else if jsonString := flag.Arg(0); jsonString == "" && fileName == "" { _, err := io.Copy(buf, os.Stdin) handleError("Unable to read from Stdin", err) } else { buf = bytes.NewBufferString(jsonString) } Lex(buf) ``` So if I pass the string `'{"key": "value"}'` to the program through `nvim-dap-go`, it's split into `'{"key":` and `"value"}'` and so i get only the first half saved into `jsonString` Here's my config: ``` return { "mfussenegger/nvim-dap", dependencies = { "rcarriga/nvim-dap-ui", "mfussenegger/nvim-dap-python", "nvim-neotest/nvim-nio", "theHamsta/nvim-dap-virtual-text", "leoluz/nvim-dap-go", }, config = function() local dap, dapui = require("dap"), require("dapui") local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") require("mason-nvim-dap").setup() require("dap-go").setup() require("nvim-dap-virtual-text").setup({}) dapui.setup() dap.listeners.before.attach.dapui_config = function() dapui.open() end dap.listeners.before.launch.dapui_config = function() dapui.open() end dap.listeners.before.event_terminated.dapui_config = function() dapui.close() end dap.listeners.before.event_exited.dapui_config = function() dapui.close() end vim.keymap.set("n", "<leader>dc", function() dap.continue() end, { desc = "continue debugger" }) vim.keymap.set("n", "<leader>dk", function() dap.close() end, { desc = "kill debugger" }) vim.keymap.set("n", "<leader>du", function() require("dapui").toggle({ reset = true }) end, { desc = "Toggle UI" }) vim.keymap.set("n", "<Leader>dso", function() dap.step_over() end, { desc = "Step over" }) vim.keymap.set("n", "<Leader>dsi", function() dap.step_into() end, { desc = "Step in" }) vim.keymap.set("n", "<Leader>dso", function() dap.step_out() end, { desc = "Step out" }) vim.keymap.set("n", "<Leader>db", function() dap.toggle_breakpoint() end, { desc = "Toggle breakpoint" }) vim.keymap.set("n", "<Leader>B", function() dap.set_breakpoint() end, { desc = "Set breakpoint" }) vim.keymap.set("n", "<Leader>lp", function() dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) end, { desc = "Log point message" }) -- vim.keymap.set("n", "<Leader>dr", function() -- dap.repl.open() -- end, { desc = "Open REPL" }) vim.keymap.set("n", "<Leader>dl", function() dap.run_last() end, { desc = "Run last" }) vim.keymap.set({ "n", "v" }, "<Leader>dh", function() require("dap.ui.widgets").hover() end, { desc = "Hover" }) vim.keymap.set({ "n", "v" }, "<Leader>dp", function() require("dap.ui.widgets").preview() end, { desc = "Preview" }) vim.keymap.set("n", "<Leader>df", function() local widgets = require("dap.ui.widgets") widgets.centered_float(widgets.frames) end, { desc = "Open Frames" }) vim.keymap.set("n", "<Leader>ds", function() local widgets = require("dap.ui.widgets") widgets.centered_float(widgets.scopes) end, { desc = "Open Scopes" }) end, } ``` Here are screenshots from the debugger vs the command line: [command line arguments and print out](https://i.sstatic.net/2Lpk1JM6.png) [delve arguments](https://i.sstatic.net/7AAo3dse.png) [delve print out ](https://i.sstatic.net/IYOnoR8W.png)
stale[bot] commented 2025-09-14 03:14:56 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#117
No description provided.