mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when opening REPL with automatic completion trigger

dhruvmanila opened this issue · comments

  • Neovim version: v0.7.0
  • OS: macOS Monterey 12.3.1

Debug adapter definition and debug configuration

Not a problem for any adapter/configuration.

Debug adapter version

Not a problem for any adapter.

Steps to Reproduce

  1. Save the below minimal.lua file
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]

local package_root = '/tmp/nvim/site/pack'
local packer_install_path = package_root .. '/packer/start/packer.nvim'

local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      -- Add plugins to test...
      'mfussenegger/nvim-dap',
    },
    config = {
      package_root = package_root,
      compile_path = packer_install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end

_G.load_config = function()
  -- Add the necessary `init.lua` settings which could include the setup
  -- functions for the plugins...
  local dap = require 'dap'

  vim.api.nvim_create_autocmd('FileType', {
    group = vim.api.nvim_create_augroup('dm__dap_repl', { clear = true }),
    pattern = 'dap-repl',
    callback = require('dap.ext.autocompl').attach,
    desc = 'DAP: REPL completion',
  })

  vim.keymap.set('n', '<space>dr', function()
    dap.repl.toggle { height = math.floor(vim.o.lines * 0.3) }
  end, { desc = 'DAP: Toggle repl' })
end

if vim.fn.isdirectory(packer_install_path) == 0 then
  print 'Installing plugins and dependencies...'
  vim.fn.system {
    'git',
    'clone',
    '--depth=1',
    'https://github.com/wbthomason/packer.nvim',
    packer_install_path,
  }
end

load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
  1. Open Neovim with nvim -n -u path/to/minimal.lua
  2. Toggle repl with <space>dr

Expected Result

To open the REPL and able to attach the autocompletion without any errors.

Actual Result

Stacktrace:

E5108: Error executing lua: /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/repl.lua:24: Vim(append):Error executing lua callback: ...ite/pack/packer/start/nvim-dap/lua/dap/ext/autocompl.lua
:51: bad argument #2 to 'format' (number expected, got table)
stack traceback:
        [C]: in function 'format'
        ...ite/pack/packer/start/nvim-dap/lua/dap/ext/autocompl.lua:51: in function <...ite/pack/packer/start/nvim-dap/lua/dap/ext/autocompl.lua:49>
        [C]: in function 'nvim_buf_set_option'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/repl.lua:24: in function 'new_buf'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:303: in function '_init_buf'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:316: in function 'open'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:277: in function 'toggle'
        /Users/dhruv/dotfiles/config/nvim/minimal.lua:45: in function </Users/dhruv/dotfiles/config/nvim/minimal.lua:44>
stack traceback:
        [C]: in function 'nvim_buf_set_option'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/repl.lua:24: in function 'new_buf'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:303: in function '_init_buf'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:316: in function 'open'
        /tmp/nvim/site/pack/packer/start/nvim-dap/lua/dap/ui.lua:277: in function 'toggle'
        /Users/dhruv/dotfiles/config/nvim/minimal.lua:45: in function </Users/dhruv/dotfiles/config/nvim/minimal.lua:44>

require('dap.ext.autocompl').attach requires the buffer number as first argument or nil to ensure it uses the current buffer.

If you use the new nvim_create_autocmd and link it directly to callback it will receive arguments related to the autocmd event. Try:

vim.api.nvim_create_autocmd('FileType', {
    group = vim.api.nvim_create_augroup('dm__dap_repl', { clear = true }),
    pattern = 'dap-repl',
    callback = function() require('dap.ext.autocompl').attach() end,
    desc = 'DAP: REPL completion',
  })

If you use the new nvim_create_autocmd and link it directly to callback it will receive arguments related to the autocmd event.

Ah, right. I completely forgot about this. I did update other autocmds for this change but for some reason missed this one.

Thanks a lot! 😁