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

Extend get api of breakpoints to retrieve a bp at specific line #1204

Open
asmodeus812 opened this issue Apr 29, 2024 · 2 comments
Open

Extend get api of breakpoints to retrieve a bp at specific line #1204

asmodeus812 opened this issue Apr 29, 2024 · 2 comments

Comments

@asmodeus812
Copy link
Contributor

Problem Statement

There is no way to get a breakpoint at a specific line number at the moment. The breakpoint.get api can be extended to match the other api's for breakpoints to optionally get a line number, similarly to toggle,remove, set etc.

Possible Solutions

No response

Considered Alternatives

At the moment we have to do use get, to get all of them, and then filter on the line number, to get the one we want.

@mfussenegger
Copy link
Owner

I do have in mind to revamp the breakpoint API somewhat in the direction of something like:

  • dap.bp.get(opts) (filters, etc.)
  • dap.bp.set(opts)
  • dap.bp.jump({ count })

Could you give a bit more context on your use-case that you'd want to get the breakpoint on a specific line number?

@asmodeus812
Copy link
Contributor Author

For me i have done something like that, to obtain a break point at a line if there is any (see below). The reason is that i have a binding which can update / edit a breakpoint at a position to change
condition/logmessage/hitCondition, so it has to check if there is already breakpoint present at the given line number to obtain the current state/config for the breakpoint, then i run set_breakpoint to replace it with the updated state (which is based on the original bp), otherwise if none exists a new bp will be created with default state again using the set_breakpoint api.

    local ok, bp = pcall(require, "dap.breakpoints")
    if not ok or not bp then
        return {}
    end

    local points = bp.get(vim.api.nvim_get_current_buf())
    local _, entry = next(points or {})
    if entry then
        -- TODO: not the best idea, there should be an
        -- api in dap to get the bp by linenr directly
        local lnum = vim.api.nvim_win_get_cursor(0)[1]
        for _, pt in ipairs(entry) do
            if pt and pt.line == lnum then
                return pt
            end
        end
    end
    return nil

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

No branches or pull requests

2 participants