Coder Social home page Coder Social logo

mason-nvim-dap.nvim's Introduction

mason-nvim-dap bridges mason.nvim with the nvim-dap plugin - making it easier to use both plugins together.

Introduction

mason-nvim-dap.nvim closes some gaps that exist between mason.nvim and nvim-dap. Its main responsibilities are:

  • provide extra convenience APIs such as the :DapInstall command
  • allow you to (i) automatically install, and (ii) automatically set up a predefined list of adapters
  • translate between dap adapter names and mason.nvim package names (e.g. python <-> debugpy)

It is recommended to use this extension if you use mason.nvim and nvim-dap. (This plugin won't really work without them)

**Note: this plugin uses the dap adapter names in the APIs it exposes - not mason.nvim package names.

Star History

Star History Chart

Requirements

Installation

{
    "williamboman/mason.nvim",
    "mfussenegger/nvim-dap",
    "jay-babu/mason-nvim-dap.nvim",
}
use {
    "williamboman/mason.nvim",
    "mfussenegger/nvim-dap",
    "jay-babu/mason-nvim-dap.nvim",
}

Setup

It's important that you set up the plugins in the following order:

  1. mason.nvim
  2. mason-nvim-dap.nvim

Pay extra attention to this if you're using a plugin manager to load plugins for you, as there are no guarantees it'll load plugins in the correct order unless explicitly instructed to.

require("mason").setup()
require("mason-nvim-dap").setup()

Refer to the Configuration section for information about which settings are available.

Commands

  • :DapInstall [<adapter>...] - installs the provided adapter
  • :DapUninstall <adapter> ... - uninstalls the provided adapter

Configuration

You may optionally configure certain behavior of mason-nvim-dap.nvim when calling the .setup() function. Refer to the default configuration for a list of all available settings.

Example:

require("mason-nvim-dap").setup({
    ensure_installed = { "python", "delve" }
})

Default configuration

local DEFAULT_SETTINGS = {
    -- A list of adapters to install if they're not already installed.
    -- This setting has no relation with the `automatic_installation` setting.
    ensure_installed = {},

	-- NOTE: this is left here for future porting in case needed
	-- Whether adapters that are set up (via dap) should be automatically installed if they're not already installed.
	-- This setting has no relation with the `ensure_installed` setting.
	-- Can either be:
	--   - false: Daps are not automatically installed.
	--   - true: All adapters set up via dap are automatically installed.
	--   - { exclude: string[] }: All adapters set up via mason-nvim-dap, except the ones provided in the list, are automatically installed.
	--       Example: automatic_installation = { exclude = { "python", "delve" } }
    automatic_installation = false,

    -- See below on usage
    handlers = nil,
}

Handlers usage (Automatic Setup)

The handlers table provides a dynamic way of setting up sources and any other logic needed; it can also do that during runtime. To override the fallback handler put your custom one as first list element in the table. To override any other handler pass your custom function to the respective key. Handler functions take one argument - the default config table, which you customize to your liking:

local config = {
	name -- adapter name

	-- All the items below are looked up by the adapter name.
	adapters -- https://github.com/jay-babu/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/adapters.lua
	configurations -- https://github.com/jay-babu/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/configurations.lua
	filetypes -- https://github.com/jay-babu/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/filetypes.lua
}

Note, especially if you are migrating from setup_handlers(), that you have to call require('mason-nvim-dap').default_setup(config) with your customized config table in all your handler overrides!

Basic Customization

require ('mason-nvim-dap').setup({
    ensure_installed = {'stylua', 'jq'},
    handlers = {}, -- sets up dap in the predefined manner
})

Advanced Customization

require ('mason-nvim-dap').setup({
    ensure_installed = {'stylua', 'jq'},
    handlers = {
        function(config)
          -- all sources with no handler get passed here

          -- Keep original functionality
          require('mason-nvim-dap').default_setup(config)
        end,
        python = function(config)
            config.adapters = {
	            type = "executable",
	            command = "/usr/bin/python3",
	            args = {
		            "-m",
		            "debugpy.adapter",
	            },
            }
            require('mason-nvim-dap').default_setup(config) -- don't forget this!
        end,
    },
})

Available Dap Adapters

See https://github.com/jay-babu/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/source.lua

mason-nvim-dap.nvim's People

Contributors

aeceon avatar aosterhage avatar binaryfly avatar bluedrink9 avatar chomosuke avatar github-actions[bot] avatar haris-ak avatar herrvonvoid avatar jay-babu avatar jinzhongjia avatar jiriks74 avatar lennyphoenix avatar linmajia avatar mehalter avatar melodyogonna avatar natr1x avatar nikitalocalhost avatar nsi-inco avatar robsonpeixoto avatar sjcobb2022 avatar xbt573 avatar yogeshkotadiya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mason-nvim-dap.nvim's Issues

Delve no working

Thanks your woring in mason-nvim-dap.nvim.
There is a error when I run DapContinue

No configuration found for `go`. You need to add configs to `dap.configurations.go` (See `:h dap-configuration`)

I use Lazy install nevim package

 {
    "jay-babu/mason-nvim-dap.nvim",
    config = function ()
      require("mason-nvim-dap").setup({
        ensure_installed = {  "delve" },
         automatic_installation = true,
      })
    
    end
  },

Thanks again

automatic setup takes ~400ms during config

Hi

I recently added mason-nvim-dap to my config. I am particularly interested in the automatic_setup feature, which work great BTW! Thanks for that.

However, since this addition I noticed that my startup time significantly increased. Using nvim --headless --startuptime tmp/startup +qa, I noticed that the adapter portion of mason-nvim-dap was taking around 400ms. Here is an extract of the profile:

120.316  000.826  000.826: require('mason-nvim-dap')
120.415  000.085  000.085: require('mason-nvim-dap.settings')
120.661  000.102  000.102: require('mason-nvim-dap.mappings.source')
120.676  000.242  000.141: require('mason-nvim-dap.ensure_installed')
543.765  422.617  422.617: require('mason-nvim-dap.mappings.adapters')              // this part requires 422ms apparently
543.871  000.098  000.098: require('mason-nvim-dap.mappings.filetypes')
544.023  000.066  000.066: require('mason-registry.index')
546.120  000.059  000.059: require('mason-core.functional.type')
592.397  048.523  048.397: require('mason-nvim-dap.mappings.configurations')
592.467  000.062  000.062: require('mason-nvim-dap.automatic_setup')
592.711  000.089  000.089: require('mason-nvim-dap.api.command')

and here the related extract of my config (I use lazy):

return {
    "jay-babu/mason-nvim-dap.nvim",
    dependencies = {
        "williamboman/mason.nvim",
        "mfussenegger/nvim-dap",
    },
    config = function()
        require("mason-nvim-dap").setup {
            automatic_setup = true,
            ensure_installed = {
                "bash",
                "codelldb",
                "delve",
                "python"
            },
            handlers = {}
        }
    end
}

I thought that possibly one of the dap adapter in particular was at fault. So I tried commenting all of them in the ensure_installed section, but it does not seem to help. I am currently using this commit: b8b01c3.

If you need more info, or need me to run some experiment to help zoom in on the problem, let me know, I would be happy to help😄

Thanks!

Some adapters are not found

Some adapters that are in source.lua are not present in the (new) adapter folder. This generates errors when starting nvim. When I comment out javadbg, javatest and php everything seems to work fine.

Should these adapters still be added?

Thanks!

Seeing an issue running in headless mode

I have some aliases and plumbing set up for bootstrapping a new machine. One of the steps is to fire off packer to get all of my nvim plugins sorted. I get errors from this plugin (only when headless, works fine if I call PackerSync inside nvim). I'm happy to do anything I can to provide more details.

For what it's worth, Mason fails to install things quietly due to the nature of the PackerComplete event; it doesn't wait for hooks.

Thanks for the great plugin!

~/.config main* ❯ alias nps
nps='nvim --headless +'\''autocmd User PackerComplete qa'\'' +'\''PackerSync'\'

~/.config main* ❯ nps
[mason] [ERROR 14:45:46] ...pack/packe...t #1 to '?' (string expected, got nil)[mason] [ERROR 14:45:46] ...pack/packe...t #1 to '?' (string expected, got nil)[mason] [ERROR 14:45:48] ...pack/packe...t #1 to '?' (string expected, got nil)[mason] [ERROR 14:45:48] ...pack/packe...t #1 to '?' (string expected, got nil)

Not able to install a package when the version is defined.

Mason version: 1.6.0
mason-nvim-dap.nvim version: 2.1.1

For instance, the following config (based on Lazyvim plugin manager) would not be able to properly install the javadbg without setting the debug to True.

return {
    "jay-babu/mason-nvim-dap.nvim",
    opts = function(_, opts)
      if type(opts.ensure_installed) == "table" then
        vim.list_extend(opts.ensure_installed, {"[email protected]" })
      end
    end,
  }

But I have no problem when the version is NOT defined

return {
    "jay-babu/mason-nvim-dap.nvim",
    opts = function(_, opts)
      if type(opts.ensure_installed) == "table" then
        vim.list_extend(opts.ensure_installed, {"javadbg" })
      end
    end,
  }

I have not tried but similar problems could happen also with your other plugin for managing the installation of linters and formatters (here)

This issue should be reported in mason (as the problem is actually there).

How to share configuration of adapter with multiple languages?

First off thanks for this plugin, I'm feeling kind of overwhelmed with dap setup and configuration, and am finding these sorts of things helpful.

Second piece is probably me just being pretty dense, but I'm trying to figure out how to use this plugin to configure the rust debugger. It's supposed to be one that also uses lldb, but I'm not sure how to reference that adapter in my setup_handlers. Any assistance or tips would be really helpful.

feat: add dynamic configuration for rust using codelldb

Hi, I'm using this plugin for managing my dap debuggers and I was trying to use the default configuration for codelldb.

My understanding is that you've provided an agnostic config to work with C/C++/Rust by always asking for the user to input the executable path.

I've started working on a way to improve our developer experience in rust by:

  • building the app before debugging
  • parsing the build output to get the executable path from cargo
  • fail in case we have an error building it
dap.configurations.rust = {
	{
		name = "LLDB: Launch",
		type = "codelldb",
		request = "launch",
		program = function()
			local output = vim.fn.systemlist("cargo build -q --message-format=json 2>1")
			for _, l in ipairs(output) do
				local json = vim.json.decode(l)
				if json == nil then
					error("error parsing json")
				end
				if json.success == false then
					return error("error building package")
				end
				if json.executable ~= nil then
					return json.executable
				end
			end
		end,
		cwd = "${workspaceFolder}",
		stopOnEntry = false,
		args = {},
	},
}

I'm not quite sure if this follows any best practices but I just wanted to share how I did it and hopefully get some feedback as to which kind of features you want to support in mason-nvim-dap. Would you be interested in having such features? Does it make sense to create something like this for other languages + debuggers? Let me know what you think.

js-debug-adapter configuration doesn't work

I have installed js-debug-adapter with :DapInstall js but I can not start a debugging session with :DapContinue

No configuration found for javascript. You need to add configs to dap.configurations.javascript (See :h dap-configuration).

image

I also installed firefox-debug-adapter and it works fine. So there must be a problem with js-debug-adapter

vscode launch json does not work properly anymore

Hello, one of the latest commits broke my setup, but I do not know why, maybe it's a bug, maybe it's because of breaking changes.

So I'm using a vscode launch.json to configure my dap in a cpp project using the mason package cpptools. My configuration was fine in b4af78d. However, since 2b5f8a2, my configuration broke and always returns the following message, when I try to start the debugger: The selected configuration references adapter 'cppdbg', but dap.adapters.cppdbg is undefined.

Configuration for mason-dap:

    if vim.fn.filereadable('.vscode/launch.json') then
        -- map launch.json type to filetypes (e.g. cppdbg = { 'c', 'cpp' })
        require('dap.ext.vscode').load_launchjs(nil, { cppdbg = { 'c', 'cpp' } })
    end

.vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "gdb: launch test",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/build/test_main",
      "args": [],
      "cwd": "${workspaceFolder}",
      "linux": {
        "MIMode": "gdb"
      },
      "windows": {},
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

I hope someone can help me, or atleast point me in the right direction. Thanks in advance :)

Unable to require default mappings (adapter, config, filetype etc) if `automatic_setup` is boolean

I know it's a bit of a strange way of using it, but I want to use manual adapter setup but for some adapter wanted to pull the default ones. If I try to call default adapters like require('mason-nvim-dap.mappings.adapters') I get an error like this:

E5113: Error while calling lua chunk: ...n-nvim-dap.nvim/lua/mason-nvim-dap/mappings/adapters.lua:91: attempt to index field 'automatic_setup' (a boolean value)

Which is expected because automatic_setup field is a boolean but it always tries to access adapters field in it.

This behavior can be fixed by adding a boolean/table check or slightly modify func_or_extend function.

I opened this issue to learn if the current behavior is "how things should work" or not. If not I can also open a PR for it.

Add mapping support for type = "pwa-chrome"

Some launch.json we work with contain type = "pwa-chrome" in the definition, it seems unanimous with the type = chrome definitions so would be interested to see what's involved with treating it the same

Please add other adapters

Or at least add option to pass unknown adapters from setup_handlers to dap

  • bash
  • codelldb
  • java-debug-adapter
  • java-test
  • js-debug-adapter
  • mockdebug
  • pupeet-editor-services
  • elixir-ls

[PYTHON] Add default configuration to attach to an already running debugpy server

Hey, thanks a lot for your work :)

I tried to debug a web server written in Python using your plugin, but it wasn't working. And for a good reason because it seems that according to that:

-- The first three options are required by nvim-dap
type = 'python', -- the type here established the link to the adapter definition: `dap.adapters.python`
request = 'launch',
name = 'Python: Launch file',
program = '${file}', -- This configuration will launch the current file if used.
pythonPath = venv_path and (venv_path .. '/bin/python') or nil,

Your plugin doesn't support attaching to a remote debugpy instance. It only supports launching a file directly, unlike the NodeJS config for example:

name = 'Node2: Attach to process',
type = 'node2',
request = 'attach',
processId = require('dap.utils').pick_process,

It would be super nice to be able to trigger that code path in nvim-dap-python using the default configuration of your plugin !

I don't have enough Lua knowledge to submit a PR for this, but if someone is willing to implement this, here's a minimal reproducible example:

# Create a virtualenv
$ python3 -m venv venv
# Activate it
$ source venv/bin/activate
# Install debugpy (the debug adapter of Microsoft for Python)
$ pip install debugpy

Create a test.py file like so:

from time import sleep
import debugpy

debugpy.listen(("127.0.0.1", 5678))

while True:
    print("Still not attached ?")
    sleep(3)

Run it manually from your shell:

$ python -Xfrozen_modules=off test.py

Then go to neovim, toggle a breakpoint to the print statement, and try to attach to the debugger.

Improve documentation for Automatic Setup Usage

Hi, I was following Kickstart.nvim, which includes this plugin as optional. After enabling it I had to solve issues with setup_handlers (outdated on their end), but even after that, I had the issue of getting no errors but still DAP adapters not being loaded in.

My config:

require('mason-nvim-dap').setup {
  automatic_setup = true,
  ensure_installed = {
    'chrome',
    'firefox',
    'php',
    'js',
  },
}

Automatic installation of related mason plugins worked fine, but still DAP would complain about no adapters being setup for given filetype. It was only after adding an empty handler object to my config that it started working:

require('mason-nvim-dap').setup {
  automatic_setup = true,
  ensure_installed = {
    'chrome',
    'firefox',
    'php',
    'js',
  },
  handlers = {},
}

As can be checked against current README.md, Automatic Setup doesn't state anywhere that this is necessary. Is there something I'm doing wrong or is the handlers value indeed required?

Other than that, brutal work!
Cheers!

Ensure_installed doesn't automatically install on startup

Hi,
Switched from packer.nvim to lazy.nvim and when starting Mason, the ensure_installed dap are note installed automatically.
The plugin is loaded and works but I have to install them manually one by one.
Also note that Mason & nvim-dap are loaded too.

Please see :

Enregistrement.de.l.ecran.2023-01-11.a.15.22.25.mov

Here's my config :

Package manager

        "williamboman/mason.nvim",
        cmd = "Mason",
        config = require("ls-devs.lazy.mason").config,
        dependencies = {
          { "williamboman/mason-lspconfig.nvim" },
          {
            "jay-babu/mason-null-ls.nvim",
            config = require("ls-devs.lazy.mason-null-ls").config,
          },
          {
            "jay-babu/mason-nvim-dap.nvim",
            config = require("ls-devs.lazy.mason-nvim-dap").config,
            dependencies = {
              { "mfussenegger/nvim-dap" },
            },
          },
        },

Mason-nvim-dap

local M = {}

M.config = function()
  local dap = require("dap")
  local mason_nvim_dap = require("mason-nvim-dap")

  mason_nvim_dap.setup({
    automatic_installation = true,
    ensure_installed = {
      "debugpy",
      "codelldb",
      "node-debug2-adapter",
      "php-debug-adapter",
      "go-debug-adapter",
      "js-debug-adapter",
    },
    automatic_setup = true,
  })

  mason_nvim_dap.setup_handlers({
    function(source_name)
      require("mason-nvim-dap.automatic_setup")(source_name)
    end,
    python = function()
      dap.adapters.python = {
        type = "executable",
        command = "python3.10",
        args = { "-m", "debugpy.adapter" },
      }

      dap.configurations.python = {
        {
          type = "python",
          request = "launch",
          name = "Launch file",
          program = "${file}",
          pythonPath = function()
            return "/usr/bin/python3.10"
          end,
        },
      }
    end,
  })
end

return M

Ruby dap-udapter.

Thank you for your plugin. Are you going to add any Ruby on Rails adapter?

"ENOENT: no such file or directory" after launching LLDB: Launch

image

Sorry if this is a dumb question. I am new to neovim and am starting from this kickstart.nvim repository here: https://github.com/John-Boccio/nvim

The changes I have made are in the main branch, all it consists of is the following:

│diff --git a/init.lua b/init.lua                                                                                                                                                                                                                                                  │
│index a7667dd..281434c 100644                                                                                                                                                                                                                                                     │
│--- a/init.lua                                                                                                                                                                                                                                                                    │
│+++ b/init.lua                                                                                                                                                                                                                                                                    │
│@@ -218,8 +218,8 @@ require('lazy').setup({                                                                                                                                                                                                                                       │
│   -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart                                                                                                                                                                                    │
│   --       These are some example plugins that I've included in the kickstart repository.                                                                                                                                                                                        │
│   --       Uncomment any of the lines below to enable them.                                                                                                                                                                                                                      │
│-  -- require 'kickstart.plugins.autoformat',                                                                                                                                                                                                                                     │
│-  -- require 'kickstart.plugins.debug',                                                                                                                                                                                                                                          │
│+  require 'kickstart.plugins.autoformat',                                                                                                                                                                                                                                        │
│+  require 'kickstart.plugins.debug',                                                                                                                                                                                                                                             │
│                                                                                                                                                                                                                                                                                  │
│   -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`                                                                                                                                                           │
│   --    You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping                                                                                                                                                                      │
│diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua                                                                                                                                                                                                    │
│index 7fc783f..1bab69b 100644                                                                                                                                                                                                                                                     │
│--- a/lua/kickstart/plugins/debug.lua                                                                                                                                                                                                                                             │
│+++ b/lua/kickstart/plugins/debug.lua                                                                                                                                                                                                                                             │
│@@ -39,6 +39,8 @@ return {                                                                                                                                                                                                                                                        │
│       ensure_installed = {                                                                                                                                                                                                                                                       │
│         -- Update this to ensure that you have the debuggers for the langs you want                                                                                                                                                                                              │
│         'delve',                                                                                                                                                                                                                                                                 │
│+        'codelldb',                                                                                                                                                                                                                                                              │
│+        'cppdbg',                                                                                                                                                                                                                                                                │
│       },                                                                                                                                                                                                                                                                         │
│     }    

After going into my basic C++ test project, I ran :DapInstall codelldb. Then I set a break point and launched "LLDB: Launch" and provided the path to my executable. The error is shown in the screen shot.

Elixir adapter not found

Today I received this error message, when I deleted this plugin elixir-tools.nvim. Also, the error could be, because I downloaded new versions of the plugins.

2023-04-20T13:37:11 lazy.nvim  ERROR Failed to run `config` for mason-nvim-dap.nvim

...m-dap.nvim/lua/mason-nvim-dap/mappings/adapters/init.lua:7: module 'mason-nvim-dap.mappings.adapters.elixir' not found:
        no field package.preload['mason-nvim-dap.mappings.adapters.elixir']
cache_loader: module mason-nvim-dap.mappings.adapters.elixir not found
cache_loader_lib: module mason-nvim-dap.mappings.adapters.elixir not found
cache_loader: module mason-nvim-dap.mappings.adapters.elixir not found
cache_loader_lib: module mason-nvim-dap.mappings.adapters.elixir not found
        no file './mason-nvim-dap/mappings/adapters/elixir.lua'
        no file '/opt/homebrew/share/luajit-2.1.0-beta3/mason-nvim-dap/mappings/adapters/elixir.lua'
        no file '/usr/local/share/lua/5.1/mason-nvim-dap/mappings/adapters/elixir.lua'
        no file '/usr/local/share/lua/5.1/mason-nvim-dap/mappings/adapters/elixir/init.lua'
        no file '/opt/homebrew/share/lua/5.1/mason-nvim-dap/mappings/adapters/elixir.lua'
        no file '/opt/homebrew/share/lua/5.1/mason-nvim-dap/mappings/adapters/elixir/init.lua'
        no file './mason-nvim-dap/mappings/adapters/elixir.so'
        no file '/usr/local/lib/lua/5.1/mason-nvim-dap/mappings/adapters/elixir.so'
        no file '/opt/homebrew/lib/lua/5.1/mason-nvim-dap/mappings/adapters/elixir.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './mason-nvim-dap.so'
        no file '/usr/local/lib/lua/5.1/mason-nvim-dap.so'
        no file '/opt/homebrew/lib/lua/5.1/mason-nvim-dap.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

# stacktrace:
  - /mason-nvim-dap.nvim/lua/mason-nvim-dap/mappings/adapters/init.lua:7 _in_ **__index**
  - /mason-nvim-dap.nvim/lua/mason-nvim-dap/init.lua:49 _in_ **fn**
  - /mason.nvim/lua/mason-core/optional.lua:91 _in_ **if_present**
  - /mason-nvim-dap.nvim/lua/mason-nvim-dap/init.lua:41 _in_ **fn**
  - /mason.nvim/lua/mason-core/functional/list.lua:98 _in_ **each**
  - /mason-nvim-dap.nvim/lua/mason-nvim-dap/init.lua:61 _in_ **setup_handlers**
  - /mason-nvim-dap.nvim/lua/mason-nvim-dap/init.lua:87 _in_ **setup**
  - ~/.config/nvim/lua/astronvim/utils/init.lua:91

I need help, how can I download this adapter, or how can I fix this message without adapter installation.

My NeoVim config is here - IvanProg00/AstroNvim.

Add interopability with mason-lspconfig

I have https://github.com/williamboman/mason-lspconfig.nvim installed which automatically installs configures LSPs for me

This results in e.g. pyright in the mason packages.

Sadly this tool only looks for https://github.com/jayp0521/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/source.lua#L7 (python)

Could we expand the mapping to include various others, like pyright, to the corresponding DAP?

Like adding

	['pyright'] = 'debugpy',

or making the left side a list;

	{ 'python', 'pyright' } = 'debugpy',

which of course needed other changes, ....

Or maybe I'm using this wrong? How would I end up with a python folder in the packages? mason only returns it's own valid packages, which doesn't include python

Python gunicorn server with dap

Hi,
I am facing two issues which are as follow:

Neovim is taking global python3 path instead of the local python path.
I want to debug the server of gunicorn. I need to expose ports for that.
Considering i am using .vscode/launch.json, how i can modify my launch setting to resolve the above two problems?
Here is how i have defined my settings for dap:

{
    "mfussenegger/nvim-dap",

    dependencies = {

      -- fancy UI for the debugger
      {
        "rcarriga/nvim-dap-ui",
      -- stylua: ignore
      keys = {
        { "<leader>du", function() require("dapui").toggle({ }) end, desc = "Dap UI" },
        { "<leader>de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} },
      },
        opts = {},
        config = function(_, opts)
          -- setup dap config by VsCode launch.json file
          require("dap.ext.vscode").load_launchjs()
          local dap = require "dap"
          local dapui = require "dapui"
          dapui.setup(opts)
          dap.listeners.after.event_initialized["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
        end,
      },

      -- virtual text for the debugger
      {
        "theHamsta/nvim-dap-virtual-text",
        opts = {},
      },

      -- which key integration
      {
        "folke/which-key.nvim",
        optional = true,
        opts = {
          defaults = {
            ["<leader>d"] = { name = "+debug" },
          },
        },
      },

      -- mason.nvim integration
      {
        "jay-babu/mason-nvim-dap.nvim",
        dependencies = "mason.nvim",
        cmd = { "DapInstall", "DapUninstall" },
        opts = {
          -- Makes a best effort to setup the various debuggers with
          -- reasonable debug configurations
          automatic_installation = true,

          -- You can provide additional configuration to the handlers,
          -- see mason-nvim-dap README for more information
          handlers = {},

          -- You'll need to check that you have the required things installed
          -- online, please don't ask me how to install them :)
          ensure_installed = {
            -- Update this to ensure that you have the debuggers for the langs you want
          },
        },
      },
    },

  -- stylua: ignore
  keys = {
    { "<leader>dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" },
    { "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
    { "<leader>dc", function() require("dap").continue() end, desc = "Continue" },
    { "<leader>da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" },
    { "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
    { "<leader>dg", function() require("dap").goto_() end, desc = "Go to line (no execute)" },
    { "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
    { "<leader>dj", function() require("dap").down() end, desc = "Down" },
    { "<leader>dk", function() require("dap").up() end, desc = "Up" },
    { "<leader>dl", function() require("dap").run_last() end, desc = "Run Last" },
    { "<leader>do", function() require("dap").step_out() end, desc = "Step Out" },
    { "<leader>dO", function() require("dap").step_over() end, desc = "Step Over" },
    { "<leader>dp", function() require("dap").pause() end, desc = "Pause" },
    { "<leader>dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" },
    { "<leader>ds", function() require("dap").session() end, desc = "Session" },
    { "<leader>dt", function() require("dap").terminate() end, desc = "Terminate" },
    { "<leader>dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" },
  },

    config = function()
      -- local Config = require "nvchad.config"
      vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" })

      -- for name, sign in pairs(Config.icons.dap) do
      --   sign = type(sign) == "table" and sign or { sign }
      --   vim.fn.sign_define(
      --     "Dap" .. name,
      --     { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] }
      --   )
      -- end
    end,
  },

Automatic setup doesn't work with codelldb on Windows

I want to preface by saying that I assume this will be the case for all adapters installed via mason.nvim on Windows.

I've installed codelldb via mason.nvim and done the typical setup:

require('mason').setup({})
require('mason-nvim-dap').setup({
  automatic_setup = true
})
require('mason-nvim-dap').setup_handlers({})

This does configure dap.adapters.codelldb but with the following values:

{
  executable = {
    args = { "--port", "${port}" },
    command = "codelldb",
    detached = false
  },
  port = "${port}",
  type = "server"
}

Running :DapContinue will prompt nvim-dap to ask for the executable location and once provided will error out on:

.../.local/share/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1153: ENOENT: no such file or directory

Enabling DEBUG level logs in nvim-dap shows:

[ DEBUG ] 2023-03-23T15:37:56Z-0400 ] ....local/share/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1120 ]	"Starting debug adapter server executable"	{
  args = { "--port", "${port}" },
  command = "codelldb",
  detached = false
}

which is the same configuration that mason-nvim-dap.nvim has setup via automatic_setup. The issue is that, for whatever reason, codelldb is not recognized as a file but codelldb.cmd is since this is the file actually installed by mason:

> ls ~/.local/share/nvim-data/mason/bin/
codelldb.cmd

If I modify the configuration like so:

:lua require('dap').adapters.codelldb.executable.command = 'codelldb.cmd'

then everything works great. But this defeats the purpose of automatic_setup for me.

I've been saying that I'm on Windows because I'm assuming its important but I don't actually know yet as I haven't tested on Linux (which I can if needed). I'm assuming Linux works or someone would have noticed by now.

how to change codelldb configuration?

the default codelldb configuration is

M.codelldb = {
	{
		name = 'LLDB: Launch',
		type = 'codelldb',
		request = 'launch',
		program = function()
			return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
		end,
		cwd = '${workspaceFolder}',
		stopOnEntry = false,
		args = {},
	},
}

how do i change both the adapter and the configuration for a language using the advanced customization to get something like this:

dap.adapters.codelldb = {
    type = "server",
    port = "${port}",
    executable = {
        command = os.getenv("XDG_DATA_HOME") .. "/nvim/mason/bin/codelldb",
        args = { "--port", "${port}" },
    },
}

dap.configurations.c = {
    {
        name = "launch file",
        type = "codelldb",
        request = "launch",
        program = "${fileDirname}/" .. "${fileBasenameNoExtension}",
        cwd = "${fileDirname}",
        stopOnEntry = false,
        args = {}
    }
}

dap doesn't seem to have a `setup` function

The documentation says to have

require("mason").setup()
require("dap").setup()
require("mason-nvim-dap").setup()

But, having require("dap").setup() causes this error:

Error detected while processing /home/cassidy/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/cassidy/.config/nvim/lua/lsp.lua:44: attempt to call field 'setup' (a nil value)
stack traceback:
        /home/cassidy/.config/nvim/lua/lsp.lua:44: in main chunk
        [C]: in function 'require'
        /home/cassidy/.config/nvim/init.lua:2: in main chunk

default config for cppdbg not working

error:
Sat_Jul_29_12-18-10_PM_IST_2023

my config:

-- plugin/dap.lua
{

      "mfussenegger/nvim-dap",
      {
        "jay-babu/mason-nvim-dap.nvim",
        config = function()
          require('mason-nvim-dap').setup({
            automatic_setup = true,
            handlers = {
              function(config)
                require('mason-nvim-dap').default_setup(config)
              end,
            },
          })
        end
      },
      {
        'rcarriga/nvim-dap-ui',
        config = function()
          require("dapui").setup()
        end
      }
    }

Not automatic install ensure_installed content

In the init.lua file

"jay-babu/mason-nvim-dap.nvim",
        event = "BufRead",
        
        opts = function()
            return require "custom.plugins.configs.mason-dap"
        end,

        config = function(_, opts)
            require("mason-nvim-dap").setup(opts)
        end,

mason-dap.lua file return the table that want to be installed:

local options = {
    ensure_installed = {
        "prettier",
        "js-debug-adapter",
        "debugpy",
        "cpptools",
        "bash-debug-adapter"
    },
    
    automatic_installation = true,
}

-- if os_name == "Linux" then
--     table.remove(options.ensure_installed, get_os_name.tablefind(options.ensure_installed, "csharp_ls"))
-- end

return options

setup_handlers() migration and default_setup() name confuses

hi, I just migrated from setup_handlers() to setup({handlers = {...}}) and had a hard time to realize that you had to call default_setup(customized_config) in every custom handler. I would not expect a function which is to be used in custom handlers regularly to have "default" in it's name. Especially since you'd always call it - even when you overwrite the default handler, as then you'd just wrap it and do something extra before calling it. Therefore I believe a name like setup_src(config) would be more fitting.

I would also recommend to be more specific in the migration notes, which function you now have to call in every handler.

Awesome pluing,
kind regards

mason-nvim-dap/automatic_setup.lua:8: loop or previous error loading module 'mason-nvim-dap.mappings.configurations'

After updating mason and mason-nvim-dap I'm started to get this error message several times at the start. I tried with minimum configurations and it still the same.

require ('mason-nvim-dap').setup({
    automatic_setup = true,
})
require 'mason-nvim-dap'.setup_handlers {}

And tried this to see which config triggers it:

require ('mason-nvim-dap').setup({
    automatic_setup = true,
})
require 'mason-nvim-dap'.setup_handlers {
    function(source_name)
        vim.pretty_print(source_name)
        require('mason-nvim-dap.automatic_setup')(source_name)
    end,
}

Error output at the end is like this:

"python"
Error detected while processing /home/kofteistkofte/.config/nvim/after/plugin/dap.lua:
...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "bash-debug-adapter".
"codelldb"
...son-nvim-dap.nvim/lua/mason-nvim-dap/automatic_setup.lua:8: loop or previous error loading module 'mason-nvim-dap.mappings.configurations'
"bash"
...son-nvim-dap.nvim/lua/mason-nvim-dap/automatic_setup.lua:8: loop or previous error loading module 'mason-nvim-dap.mappings.configurations'
"cppdbg"
...son-nvim-dap.nvim/lua/mason-nvim-dap/automatic_setup.lua:8: loop or previous error loading module 'mason-nvim-dap.mappings.configurations'
Press ENTER or type command to continue

There is also bash-debug-adapter error but I'm not sure this related to mason or mason-nvim-dap.

CodeLLDB don't work properly with c++

CodeLLDB don't work properly with C++

When I use codelldb to debug a code,it doesn't stop at the breakpoint,just run through
image

REMARKS:It works properly in rust.I don't know why.

Bug then opening

Installed bush dap with mason
And have these error when opening nvim: automatic setup can't found bash-debug-adapter with mason
Screen: https://www.mediafire.com/view/8b1mshlhgym393l/Screenshot_from_2023-04-01_23-03-51.png/file
Error in text: ...l/share/nvim/lazy/mason.nvim/lua/mason-registry/init.lua:79: Cann
ot find package "bash-debug-adapter".
...son-nvim-dap.nvim/lua/mason-nvim-dap/automatic_setup.lua:8: loop
or previous error loading module 'mason-nvim-dap.mappings.configurat
ions'

Automatic setup of cppdbg not working

When running DapContinue and after inserting the executable I get the following error:

Error on Launch: Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger. Please specify the "MIDebuggerPath" option

here is my config:

 local dap_servers_to_install = { 'cppdbg' }
        
require('mason').setup()
require("mason-nvim-dap").setup({
  ensure_installed = dap_servers_to_install,
  automatic_setup = true,
})

require 'mason-nvim-dap'.setup_handlers()
Screencast.from.2022-12-17.19-52-16.mp4

feat: lldb-vscode

We already have codelldb, which works fine when configured like this.

But adding lldb-vscode to mason-nvim-dap would have the advantage of adding the bin to /mason/bin, so it can be referenced on the adapter like

      dap.adapters.lldb = {
        type = 'executable',
        command = vim.fn.stdpath('data')..'/mason/bin/lldb-vscode',
        name = 'lldb'
      }

Using codelldb one has to hardcode the path like: command = '/usr/bin/lldb-vscode'

If this is not possible is not a big deal. Thank you for for amazing work.

Crash on input() in python

Python configuration doesn't work. For some reason output goes in the REPL and so it's impossible to give user input, therefore it crashes whenever there is input()

Allow mapping of different adapter type to existing type

My team is mostly using vscode for typescript with the launch.json config uses 'pwa-node' type.

When I load the launch.json to DAP with this I have to perform a mapping

require('dap.ext.vscode').load_launchjs(nil, { ['pwa-node'] = { 'typescript' } })

As well as in the mason-nvim-dap configuration, I need to perform this remap:

{
	"jay-babu/mason-nvim-dap.nvim",
	dependencies = {
		"mfussenegger/nvim-dap",
	},
	config = function()
		require("mason-nvim-dap").setup({
			ensure_installed = { "js", "node2" },
			handlers = {
				function(config)
					require("mason-nvim-dap").default_setup(config)
				end,
				node2 = function(config)
					config.configurations = nil
					require("mason-nvim-dap").default_setup(config)
				end,
			},
		})

		local dap = require("dap")
		dap.adapters['pwa-node'] = dap.adapters.node2
	end,
}

I'm wondering if this mapping could be simplified in the mason-nvim-dap as a config. That would be very useful.

How can I config RUST configuration with mason-dap

HI, I have a problem of config rust dap.
I want to add my configuration for launching and use mason-dap's default adapter config(you known rust adapter config is complex...).

FYI:

  1. I leave codelldb in ensure_installed due to mason-dap map the rust filetype to codelldb and config codelldb adapter.
  2. I can debug correctly these rust cargo projects without these new configuration. So I think rust-tool and codelldb debug server is OK.

error is:
Failed to run config for rust-tools.nvim

...l/share/nvim/lazy/mason.nvim/lua/mason-registry/init.lua:80: Cannot find package "codelldb".

stacktrace:

  • /mason.nvim/lua/mason-registry/init.lua:80 in get_package
  • /astrocommunity/lua/astrocommunity/pack/rust/rust.lua:17 in values
  • /opt/homebrew/Cellar/neovim/0.9.0/share/nvim/runtime/filetype.lua:22
  • /opt/homebrew/Cellar/neovim/0.9.0/share/nvim/runtime/filetype.lua:21

lua code are below...

{
    "jay-babu/mason-nvim-dap.nvim",
    require("mason-nvim-dap").setup {
      automatic_setup = true,
      ensure_installed = {
        "python",
        "codelldb",
      },
      handlers = {
        function(config)
          -- all sources with no handler get passed here
          -- Keep original functionality
          require("mason-nvim-dap").default_setup(config)
        end,
        codelldb = function(config)
          config.configurations = {
            {
              name = "LLDB: Launch(codellde.log ENABLED)",
              type = "codelldb",
              request = "launch",
              program = function()
                return vim.fn.input(">>Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
              end,
              cwd = "${workspaceFolder}",
              stopOnEntry = true,
              args = {
                -- https://github.com/vadimcn/codelldb/wiki/LLDB-Logging
                -- initCommands = { "log enable gdb-remote default", "log enable lldb default" },
              },
            },
          }
          require("mason-nvim-dap").default_setup(config) -- don't forget this!
        end,
      },
    },
  },
}

If you move the current directory, it will stop working. I don't know the cause.

When I start neovim from the mason directory it works, but when I move the directory and try to start dap it doesn't work. Could I ask the reason.
スクリーンショット 2023-06-21 185155
スクリーンショット 2023-06-21 185324

スクリーンショット 2023-06-21 185459
スクリーンショット 2023-06-21 185412

I have the same issue with other than php

------------------------------------configuration-------------------------------------------------
require('mason-nvim-dap').setup({`
ensure_installed = servers,
handlers = {
function(config)
-- all sources with no handler get passed here

  -- Keep original functionality
  require('mason-nvim-dap').default_setup(config)
end,

cpp = function(config)
  config.adapters = {
    id = 'cppdbg',
    type = 'executable',
    command = '/usr/local/bin/extension/debugAdapters/bin/OpenDebugAD7',
  }

  config.configurations = {
    {
      name = "Launch file",
      type = "cppdbg",
      request = "launch",
      program = function()
        return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
      end,
      cwd = '${workspaceFolder}',
      stopAtEntry = true,
    },
  }
  require('mason-nvim-dap').default_setup(config) -- don't forget this!
end,

php = function(config)
  config.adapters = {
    type = 'executable',
    command = 'node',
    args = { '/usr/local/bin/vscode-php-debug/out/phpDebug.js' }
  }

  config.configurations = {
    {
      type = 'php',
      request = 'launch',
      name = 'Listen for Xdebug',
      port = 9003,
      program = "${file}", -- This configuration will launch the current file if used.
    },
  }
  require('mason-nvim-dap').default_setup(config) -- don't forget this!
end,

},
})

----------------------------------end----------------------------------

mappings/adapters.lua can be very slow due to vim.fn.exepath

vim.fn.exepath will look for the argument on the PATH. This can be a very slow operation if the argument cannot be found since a new system call will be made for every directory on the path.

In my case I am running WSL on windows were it is not uncommon to have directories from the windows file system in the PATH. That file system is incredibly slow however and in this case makes requiring mappings/adapters.lua take several seconds.

I suggest finding either some way to lazily load the mappings or either an option to allow user's to only setup adapters that they actually have installed.

How to setup custom configurations with automatic setup

Hey, how can I set up custom language configurations after the change to setup_handlers()? The README shows an example with adapters, but I can't figure out how to do it in this case.

When I use the code below, the information I get is No configuration found for `python`. You need to add configs to `dap.configurations.python` (See `:h dap-configuration`).

require("mason").setup()
require("mason-nvim-dap").setup({
    automatic_setup = true,
    configurations = {
            function(config)
              -- all sources with no handler get passed here

              -- Keep original functionality
              require('mason-nvim-dap').default_setup(config)
            end,
            python = function(config)
                config.configurations = {
                    {
                        type = 'python', -- the type here established the link to the adapter definition: `dap.adapters.python`
                        request = 'launch',
                        name = 'Python: Launch file',
                        program = '${file}', -- This configuration will launch the current file if used.
                        pythonPath = '/bin/python',
                    },
                }
                require('mason-nvim-dap').default_setup(config) -- don't forget this!
            end,
        },
})

Can't get automatic setup to work

To reproduce:

Use the following init.lua:

Click to expand
-- Ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.expand('~/.config/nvim'))
vim.opt.packpath:remove(vim.fn.expand('~/.local/share/nvim/site'))

-- Append test directory
local test_dir = vim.fn.expand('~/code-other/nvim-test-config') -- NOTE: Add the path to the location of this file here
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- Install packer
local install_path = test_dir .. '/pack/packer/start/packer.nvim'
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
  vim.cmd('packadd packer.nvim')
  install_plugins = true
end

local packer = require('packer')

packer.init({
  package_root = test_dir .. '/pack',
  compile_path = test_dir .. '/plugin/packer_compiled.lua'
})

vim.g.mapleader = ' '

packer.startup(function()
  function Use(module)
    use(require(string.format('configs.%s', module)))
  end

  -- Packer can manage itself
  packer.use 'wbthomason/packer.nvim'

  -----------------------------
  -- Here's the configuration -
  -----------------------------

  use { 'mfussenegger/nvim-dap',
    requires = {
      'williamboman/mason.nvim',
      'jayp0521/mason-nvim-dap.nvim',
    },
    config = function()
      require('mason').setup()
      require('mason-nvim-dap').setup({
        automatic_setup = true,
      })
    end
  }

  -----------------------------
  --   End of configuration   -
  -----------------------------

  if install_plugins then
    packer.sync()
  else
    -- load plugins at your earliest convenience
    vim.defer_fn(function()
      vim.cmd('doautocmd User LoadPlugins')
    end, 1)
  end
end)

Here's the TL;DR for the init.lua:

use { 'mfussenegger/nvim-dap',
  requires = {
    'williamboman/mason.nvim',
    'jayp0521/mason-nvim-dap.nvim',
  },
  config = function()
    require('mason').setup()
    require('mason-nvim-dap').setup({
      automatic_setup = true,
    })
  end
}
  1. > nvim -u path/to/config/above/init.lua
  2. :PackerSync
  3. :DapInstall python
  4. :q (Restart Neovim just to be sure)
  5. > nvim -u path/to/config/above/init.lua test.py
  6. DapContinue
  7. The following message is printed:
No configuration found for `python`. You need to add configs to `dap.configurations.python` (See `:h dap-configuration`)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.