This is a collection of helpers to better integrate Buck2 with Neovim.
This plugin makes no support/stability guarantees for now.
The go_to_build_file function can be used to jump to the BUCK file that owns the current source file.
For example:
vim.keymap.set('n', 'gb', require('buck2').go_to_build_file)The show_last_errors function can be used to put the errors from the last buck2 build command in a scratch buffer, which will be displayed in a new window.
This is useful when running buck2 build outside of Neovim, to either go to the source location of an error or seamlessly search/manipulate the errors from within Neovim.
For example:
vim.keymap.set('n', '<Space>e', require('buck2').show_last_errors)Warning
While the following functions still work, I no longer use them, as I find generating launch.json files using BXL to have a much better UX.
nvim-buck2 provides some helper functions to integrate Buck2 and nvim-dap:
dap.current_filecan be used to debug the current file. If the current file is not a leaf owned by a single target,vim.ui.selectwill be called to select a target.dap.select_targetcan be used to debug any target, picked viavim.ui.select.dap.current_filecan be used to debug the last debugged file again. This is different from nvim-dap'srun_last, as the latter would invoke the picker on each run.
local common_lldb_dap_config = {
type = 'lldb',
request = 'launch',
cwd = '${workspaceFolder}',
runInTerminal = true,
}
local buck2 = require('buck2')
dap.configurations.cpp = {
vim.tbl_extend('error', common_lldb_dap_config, {
name = '[Buck2] Debug current file',
program = buck2.dap.current_file,
}),
vim.tbl_extend('error', common_lldb_dap_config, {
name = '[Buck2] Debug any target',
program = buck2.dap.select_target,
}),
vim.tbl_extend('error', common_lldb_dap_config, {
name = '[Buck2] Debug last target',
program = buck2.dap.last_target,
}),
}
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cppBecause nvim-buck2 builds the target before debugging it (to ensure that it is up to date), it is possible that:
- It will hang while the build is running (using
vim.notifycould alleviate this). - It will error out in an ugly way if the build fails (integrating with the quickfix list could help with this).
By default, nvim-buck2 expects a buck2 binary to be available on the PATH.
You can set vim.g.buck2 to use a custom Buck2 binary (e.g. if you have a local build you want to use, or you use a launcher like Buckle):
vim.g.buck2 = 'buckle'