Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-dap-r

nvim-dap-r adds R support to nvim-dap through rarr or daptadap.

It is not the debugger. It registers the R adapter, default R configurations, and a few helper commands. The DAP server and R runtime state live in rarr or in the active R console through daptadap.

Requirements

rarr.nvim and R.nvim do not install this adapter. Add nvim-dap-r separately when you want R debugging through nvim-dap.

Installation

Install it like any other Neovim plugin:

{
  "ilyaZar/nvim-dap-r",
  dependencies = {
    "mfussenegger/nvim-dap",
  },
  config = function()
    require("dap-r").setup()
  end,
}

For a local development checkout, point your plugin manager at this repository:

{
  name = "nvim-dap-r",
  dir = vim.fn.expand("~/path/to/nvim-dap-r"),
  dependencies = {
    "mfussenegger/nvim-dap",
  },
  config = function()
    require("dap-r").setup()
  end,
}

Setup

Call setup in your Neovim config:

require("dap-r").setup()

This registers two nvim-dap configurations for R buffers:

  • Attach to rarr
  • Launch rarr

If rarr.nvim is installed, nvim-dap-r can discover its active rarr console session. Otherwise, Launch rarr starts rarr and attaches nvim-dap.

To use the classic R.nvim console backend, install daptadap in the R library used by your console and select the classic backend:

require("dap-r").setup({
  backend = "classic",
  classic = {
    auto_start = false,
    watch_console = true,
    console = "r-nvim",
  },
})

Usage

Use the commands:

:DapRStart
:DapRAttach
:DapRLaunch
:DapRDebugSource
:DapRClassicStart
:DapRClassicAttach
:DapRClassicDebugSource
  • :DapRStart attaches to the active rarr session or starts rarr
  • :DapRAttach attaches to an existing rarr session
  • :DapRLaunch starts rarr and attaches nvim-dap
  • :DapRDebugSource attaches with the current source file as program
  • :DapRClassicStart starts daptadap in the active R.nvim console
  • :DapRClassicAttach attaches nvim-dap to the classic console backend
  • :DapRClassicDebugSource sources the current file through daptadap

The same actions are available from Lua:

require("dap-r").start()
require("dap-r").attach()
require("dap-r").launch()
require("dap-r").debug_source()
require("dap-r").classic_start()
require("dap-r").classic_attach()
require("dap-r").classic_debug_source()

After attaching, use regular nvim-dap commands:

require("dap").continue()
require("dap").toggle_breakpoint()
require("dap").step_over()
require("dap").step_into()
require("dap").step_out()
require("dap").terminate()

Keymaps

nvim-dap-r does not set global keymaps. It does install guarded R-buffer step maps by default:

  • c continues
  • n steps over
  • s steps into
  • S steps out

These maps call nvim-dap only while an R DAP session is stopped. Otherwise they pass the original key back to Vim, so normal search, substitute, and change commands keep working outside the debugger.

Change or disable them in setup:

require("dap-r").setup({
  debug_keymaps = {
    enabled = true,
    continue = "c",
    step_over = "n",
    step_into = "s",
    step_out = "S",
  },
})

Set one key to false, or disable the whole group with debug_keymaps = false.

For common breakpoint and start keys, let nvim-dap-r create R-buffer maps:

require("dap-r").setup({
  keymaps = {
    start = "<leader>dc",
    breakpoint = "<leader>db",
  },
})

Or call the helper yourself from an R filetype callback:

require("dap-r").setup_keymaps(bufnr, {
  start = "<leader>dc",
  breakpoint = "<leader>db",
})

If you also want c, n, s, and S inside nvim-dap-ui buffers, map them there with normal require("dap").* calls. Those buffers are owned by nvim-dap-ui, not by nvim-dap-r.

UI Plugins

nvim-dap-r does not manage debugger panes, watches, scopes, virtual text, or the nvim-dap-ui control row. Use regular nvim-dap UI plugins for that:

The default nvim-dap-ui controls are clickable icons, not number keys:

Icon Action
/ continue/pause
step into
step over
step out
step back
run last
terminate
disconnect

The icons can vary with your font and nvim-dap-ui config. Some actions, such as step back, also depend on adapter support.

Configuration

Most users can keep the defaults:

require("dap-r").setup({
  backend = "rarr",
  rarr = {
    command = "rarr",
    args = {},
    mode = "auto",
    host = "127.0.0.1",
    port = nil,
    metadata_path = nil,
  },
  classic = {
    enabled = true,
    package = "daptadap",
    host = "127.0.0.1",
    port = 0,
    metadata_path = nil,
    auto_start = true,
    watch_console = true,
    console = "r-nvim",
  },
  configurations = true,
  filetypes = { "r", "rmd", "quarto", "rnoweb" },
  integrate_rarr_nvim = true,
  commands = true,
  keymaps = false,
  debug_keymaps = {
    enabled = true,
    step_over = "n",
    step_into = "s",
    step_out = "S",
    continue = "c",
  },
  source_window = {
    enabled = true,
    focus_on_stop = true,
    focus_delay_ms = 30,
  },
})

Set source_window = false if you want to manage nvim-dap source window selection entirely in your own config.

About

R debug adapter protocal (DAP) glue for nvim-dap, with rarr and daptadap backends.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages