Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

nvim-buck2

This is a collection of helpers to better integrate Buck2 with Neovim.

This plugin makes no support/stability guarantees for now.

Usage

Go to build file

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)

Show last errors

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)

nvim-dap integration

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_file can be used to debug the current file. If the current file is not a leaf owned by a single target, vim.ui.select will be called to select a target.
  • dap.select_target can be used to debug any target, picked via vim.ui.select.
  • dap.current_file can be used to debug the last debugged file again. This is different from nvim-dap's run_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.cpp

Because 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.notify could alleviate this).
  • It will error out in an ugly way if the build fails (integrating with the quickfix list could help with this).

Custom Buck2 binary

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'

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages