Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to next/previous breakpoint #792

Open
BlueDrink9 opened this issue Dec 20, 2022 · 6 comments
Open

Jump to next/previous breakpoint #792

BlueDrink9 opened this issue Dec 20, 2022 · 6 comments

Comments

@BlueDrink9
Copy link

Problem Statement

Often I want to move or disable a breakpoint. It would be great to have a function I could map as a motion to to jump straight to that breakpoint.

Possible Solutions

Map to something (like ]b) so that I can immediately jump to where my next breakpoint is. From there I can disable it and move it one line down, for example, or modify the line that I am inspecting.

Considered Alternatives

Could parse it out of breakpoints list myself, but I think this would be generally useful and I think it fits with a vim philosophy

@mfussenegger
Copy link
Owner

:DapBreakpoints or :lua require('dap').list_breakpoints() adds the breakpoints to the quickfix list, so you can use :cnext and :cprev to jump between breakpoints.

@BlueDrink9

This comment was marked as duplicate.

@nyngwang

This comment was marked as duplicate.

@nyngwang

This comment was marked as off-topic.

@chrisgrieser
Copy link

chrisgrieser commented Mar 6, 2024

I made a small function that directly uses the breakpoint data to go to the next breakpoint, without the quickfix list as intermediary. If you are at a breakpoint, it goes to the next breakpoint, otherwise, it goes to the first breakpoint. You can bind it to something like ]p and [p.

---@param dir "next"|"prev"
local function gotoBreakpoint(dir)
	local breakpoints = require("dap.breakpoints").get()
	if #breakpoints == 0 then
		vim.notify("No breakpoints set", vim.log.levels.WARN)
		return
	end
	local points = {}
	for bufnr, buffer in pairs(breakpoints) do
		for _, point in ipairs(buffer) do
			table.insert(points, { bufnr = bufnr, line = point.line })
		end
	end

	local current = {
		bufnr = vim.api.nvim_get_current_buf(),
		line = vim.api.nvim_win_get_cursor(0)[1],
	}

	local nextPoint
	for i = 1, #points do
		local isAtBreakpointI = points[i].bufnr == current.bufnr and points[i].line == current.line
		if isAtBreakpointI then
			local nextIdx = dir == "next" and i + 1 or i - 1
			if nextIdx > #points then nextIdx = 1 end
			if nextIdx == 0 then nextIdx = #points end
			nextPoint = points[nextIdx]
			break
		end
	end
	if not nextPoint then nextPoint = points[1] end

	vim.cmd(("buffer +%s %s"):format(nextPoint.line, nextPoint.bufnr))
end

If @mfussenegger is open to it, I can make a PR for this.

@mfussenegger
Copy link
Owner

If @mfussenegger is open to it, I can make a PR for this.

I won't be adding anything in that direction until the other breakpoint variants are implemented (data, function, etc.) because it will likely influence the API, and I don't want to deal with BWC hassle in that regard.
That's all kinda on my roadmap for a nvim-dap 1.0

the dap.breakpoints module is btw. not stable, so it can break with any commit without a deprecation warning/cycle. Only the documented functions are safe to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants