Feature Request: Allow users to set workspaceFolder
more consistently with other IDEs, and make it more useful
#1530
-
Feature Request To add an API allowing users to set
Thanks in advance for considering the idea! Context
In other words, this is a fine default, but surprises come when It's clearly not Discussion This new feature would allow users (perhaps using plugins like project.nvim), LSP or DAP plugin devs (e.g. rustacean.nvim), and developers of IDE-like nvim configs (e.g. LazyVim), to set a more useful A minimalist conceptual example for setting it based on the LSP-detected folder (a method-call API would probably be better): dap = require("dap")
local function on_attach(client)
dap.variables["workspaceFolder"] = client.root_dir -- if nil, `workspaceFolder` would fall back to default impl (`getcwd()`)
end Here's what I currently do, just to make local function on_attach(client, bufnr) -- This function gets run when an LSP connects to a particular buffer.
local is_rust = false
local workspace_folder = client.root_dir or vim.fn.getcwd()
if client ~= nil then
is_rust = client.name:find("rust")
end
if is_rust then
local dap = require("dap")
dap.adapters.codelldb = {
type = "server",
host = "127.0.0.1",
port = "${port}",
executable = {
command = vim.fn.expand("$HOME/.local/share/nvim/mason/bin/codelldb"),
args = { "--port", "${port}" },
},
}
-- keyed by filetype ("rust", "lua", ...)
dap.configurations.rust = {
{
name = "Launch Rust",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", workspace_folder .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}", -- this is (a) just getwd() for nvim-dap, which is actually what I want when running the program (as opposed to the actual workspace folder)
stopOnEntry = true,--false,
},
}
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Relates to neovim/neovim#34622 In the meantime you could use the |
Beta Was this translation helpful? Give feedback.
Relates to neovim/neovim#34622
In the meantime you could use the
on_config
hook to re-implement how${workspaceFolder}
gets resolved. See:help dap-listeners-on_config
. You'd probably have to wrap the default handler to ensure yours runs first.