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

[Feature Request] set dap.defaults options #1509

Open
JJJHolscher opened this issue May 10, 2024 · 2 comments
Open

[Feature Request] set dap.defaults options #1509

JJJHolscher opened this issue May 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@JJJHolscher
Copy link

JJJHolscher commented May 10, 2024

nvim-dap has a remarkable amount of configuration options behind the require('dap').defaults. See :h dap.defaults for a subset and more of them in :h dap-configuration.
I'd like to set those options through nixvim.

what does not work

In a normal neovim setting, those should be set after calling setup(). Which I think is the reason for why the following does not work in my nix configuration:

# this errors with a "option does not exist"
dap.defaults.fallback.exception_breakpoints = "default";  # the global behavior
dap.defaults.python.exception_breakpoints = ["uncaught"];  # the python-specific behavior

# this is ignored
dap.extraOptions.defaults.python.exception_breakpoints = ["uncaught"];
dap.configurations.python.exception_breakpoints = ["uncaught"];
dap.configurations.python.defaults.exception_breakpoints = ["uncaught"];

workaround

I now work around this with

  autoCmd = [{
    event = [ "BufEnter" "BufWinEnter" ];
    pattern = [ "*.py" "*.md" "*.qmd" "*.ipynb" ];
    command = "lua require('dap').defaults.python.exception_breakpoints = {'uncaught'}";
  }];

proposed interface

I think it would be nice if defaults could be set with

dap.defaults.<configuration or fallback> = { };

since that's closest to the lua interface. Stuff like

dap.configurations.<configuration or fallback>.defaults = { };
# or worse:
dap.configurations.<configuration or fallback> = { };

seems less intuitive to me.

a probably bad idea for generalization

Maybe, you'd even want to generalize by always making it so that in nixvim, options that aren't accepted by the setup are then attempted to be added to the plugin's table.

So this

plugin.option = "value";

does something like (forgive the python)

plugin = require(plugin)
setup_options = {}
other_options = {}
# this loop is a botched and surely-inaccurate attempt for me to gesture at
# what I think is the status quo for how you check whether a setup function
# accepts particular options
for option, value in user_supplied_options.items():
    # in actuallity you're probably doing something more recursive here
    if option in arguments_of(plugin.setup):
        setup_options[option] = value
    else:
        other_options[option] = value

plugin.setup(setup_options)
for option,value in other_options.items():
    assert has_attr(plugin, option)  # this might or might not be good enough error handling
    plugin.option = value

though, this is not my main issue. If the above code makes you go "what the bleep are you talking about?" then feel free to just ignore it (and politely don't tell me what word the "bleep" masked out).

offered help

I would at some point make a pull requiest if no one did this but "at some point" is probably >2 months in the future.
If you'd like to wait for my pull request, I'd appreciate (but I do not feel entitled to) a pointer on how post-setup lua code tends to be run for plugins that have setup for that.
Or, if you'd never want this functionality for the dap plugin, then that'd also be nice to know (I think I'd disagree, but respectfully so) and I'll just keep using my workaround.

@JJJHolscher JJJHolscher added the bug Something isn't working label May 10, 2024
@JJJHolscher

This comment was marked as resolved.

@MattSturgeon MattSturgeon added enhancement New feature or request and removed bug Something isn't working labels May 17, 2024
@MattSturgeon
Copy link
Collaborator

I'd appreciate a pointer on how post-setup lua code tends to be run for plugins that have setup for that.

Generally speaking, I think we normally do pre/post setup code by calling setup manually.

Plugins implemented with mkNeovimPlugin tend to automatically generate code to call setup, but mkNeovimPlugin could easily be extended to accept pre/postExtraConfigLua arguments if needed.

In a normal neovim setting, those should be set after calling setup(). Which I think is the reason for why [it] does not work in my nix configuration

I don't think we ever call a DAP setup function, however we do do some "setup config" by adding lines to plugins.dap.extensionConfigLua (internal option) and here:

extraConfigLua =
(optionalString (cfg.adapters != null) ''
require("dap").adapters = ${helpers.toLuaObject options.adapters}
'')
+ (optionalString (options.configurations != null) ''
require("dap").configurations = ${helpers.toLuaObject options.configurations}
'')
+ (optionalString (cfg.signs != null) ''
local __dap_signs = ${helpers.toLuaObject options.signs}
for sign_name, sign in pairs(__dap_signs) do
vim.fn.sign_define(sign_name, sign)
end
'')
+ cfg.extensionConfigLua;

Maybe someone more familiar with our DAP module could help better here.

Maybe, you'd even want to generalize by always making it so that in nixvim, options that aren't accepted by the setup are then attempted to be added to the plugin's table.

I'm not sure what you mean by this, since the plugin settings table is what is passed to the setup function.

As for options unknown to nixvim, these are included in the table passed to setup (as-per RFC42) for any module that has been written/refactored recently.

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

No branches or pull requests

2 participants