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

Add way to provide extra initCommands #656

Closed
wants to merge 1 commit into from

Conversation

gollth
Copy link

@gollth gollth commented Jan 16, 2025

Hello,

first of all thanks for this great plugin, it's my daily driver for a long time one 🙏

I have a particular feature that I'm lacking or don't know how to achieve in rustaceanvim when it comes to debugging: I have a custom lldb init script in my repo (which adds some custom formatters) which I want to apply to every debuggable target there is (executables, nvim-dap targets & neotest debug targets), when using the codelldb adapter.

AFAIK I can only provide initCommands in the .vscode/launch.json, which works for executables, but not for the tests, right?

My idea was let the user configure an optional command in its config, which gets appended to all other init commands of all targets. My user config now looks like this:

  {
    "mrcjkb/rustaceanvim",
    dependencies = { "mfussenegger/nvim-dap" },
    version = "^5",
    lazy = false,
    ft = { "rust" },
    opts = {
      dap = {
        autoload_configurations = true,
        init_commands = "command script import ./lldb/fleet.py",
      },
    }
    -- other config...
}

Maybe there is another already built in way how to solve this, comments very welcome (=

Copy link
Contributor

Review Checklist

Does this PR follow the Contribution Guidelines? Following is a partial checklist:

Proper conventional commit scoping:

  • For example, fix(lsp): some lsp-related bugfix

  • Pull request title has the appropriate conventional commit prefix.

If applicable:

  • Tested
    • Tests have been added.
    • Tested manually (Steps to reproduce in PR description).
  • Updated documentation.

Copy link
Owner

@mrcjkb mrcjkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👋

Thanks for the PR.
Is something like this supported by the rust-analyzer VSCode plugin or by rust-analyzer?
If not, I'd prefer it be requested there first.

Adding it to the rustaceanvim config feels quite hacky. I'd potentially be open to a more general solution, in which rustaceanvim doesn't have to be concerned with which extra fields are added to the DAP configurations.

@mrcjkb mrcjkb enabled auto-merge (squash) January 19, 2025 00:13
@gollth
Copy link
Author

gollth commented Jan 27, 2025

Hey there, sorry for the late reply, was quite busy with work.

I wouldn't know of any way to configure this with codelldb but am really no expert here. Do you have a pointer how to research this?

@mrcjkb
Copy link
Owner

mrcjkb commented Jan 27, 2025

No worries, I'm not in a rush 😄

Do you have a pointer how to research this?

I stopped using debuggers years ago, and only carried over the DAP features from rust-tools.nvim.
But I just had another look at this PR. It looks like what you're trying to achieve is already possible with the dap.configuration.initCommands option:

vim.g.rustaceanvim = {
  dap = {
    configuration = {
      -- ...
      initCommands = {
        "command script import ./lldb/fleet.py",
        -- ...
      },
    },
  },
}

See :h rustaceanvim.dap.client.Config.

@gollth
Copy link
Author

gollth commented Jan 28, 2025

I tried your suggestion, but this fails for me:

Error executing vim.schedule lua callback: ...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:372: attempt to concatenate field 'type' (a nil value)
stack traceback:
	...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:372: in function <...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:311>

@mrcjkb
Copy link
Owner

mrcjkb commented Jan 28, 2025

I tried your suggestion, but this fails for me:

Error executing vim.schedule lua callback: ...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:372: attempt to concatenate field 'type' (a nil value)
stack traceback:
	...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:372: in function <...al/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/dap.lua:311>

You need to set all non-optional fields in the :h rustaceanvim.dap.client.Config type when overriding the default dap.configuration.

Example:

vim.g.rustaceanvim = {
  dap = {
    configuration = {
      name = "Rust debug adapter",
      type = "lldb", -- or "codelldb",
      request = "launch",
      initCommands = {
        "command script import ./lldb/fleet.py",
        -- ...
      },
      stopOnEntry = false,
    },
  },
}

@mrcjkb mrcjkb closed this Jan 28, 2025
auto-merge was automatically disabled January 28, 2025 17:03

Pull request was closed

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

Successfully merging this pull request may close these issues.

2 participants