Skip to content

Commit

Permalink
feat(rust): add bacon-ls and improve debugging (LazyVim#3212)
Browse files Browse the repository at this point in the history
**NOTE: the PR will be in draft until
mason-org/mason-registry#5774 is not merged**

Some improvements in the Rust extra

- Set `codelldb` adapter for rustacean.nvim
- Add support for [bacon-ls](https://github.com/crisidev/bacon-ls)
([blog post](https://lmno.lol/crisidev/bacon-language-server))

`bacon-ls` can be used as an alternative to `rust-analyzer` for
diagnostics, improving `rust-analyzer` performances. This is configured
by `vim.g.lazyvim_rust_diagnostics`, which can be set to `rust-analyzer`
or `bacon-lsp`.

<img width="1063" alt="screenshot"
src="https://github.com/LazyVim/LazyVim/assets/1781140/f50a38ff-0ec0-4d10-8cdc-796d027b16f0">

---------

Co-authored-by: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com>
  • Loading branch information
2 people authored and dunix241 committed Dec 8, 2024
1 parent 574d17f commit af186c4
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions lua/lazyvim/plugins/extras/lang/rust.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
local map = LazyVim.keymap_set
local k = require("lazyvim.keymaps").get_keymaps()
if lazyvim_docs then
-- LSP Server to use for Rust.
-- Set to "bacon-ls" to use bacon-ls instead of rust-analyzer.
-- only for diagnostics. The rest of LSP support will still be
-- provided by rust-analyzer.
vim.g.lazyvim_rust_diagnostics = "rust-analyzer"
end

local diagnostics = vim.g.lazyvim_rust_diagnostics or "rust-analyzer"

return {
recommended = function()
Expand Down Expand Up @@ -38,7 +45,13 @@ return {
{
"williamboman/mason.nvim",
optional = true,
opts = { ensure_installed = { "codelldb" } },
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "codelldb" })
if diagnostics == "bacon-ls" then
vim.list_extend(opts.ensure_installed, { "bacon" })
end
end,
},

{
Expand All @@ -65,8 +78,12 @@ return {
enable = true,
},
},
-- Add clippy lints for Rust.
checkOnSave = true,
-- Add clippy lints for Rust if using rust-analyzer
checkOnSave = diagnostics == "rust-analyzer",
-- Enable diagnostics if using rust-analyzer
diagnostics = {
enable = diagnostics == "rust-analyzer",
},
procMacro = {
enable = true,
ignored = {
Expand All @@ -80,6 +97,16 @@ return {
},
},
config = function(_, opts)
local package_path = require("mason-registry").get_package("codelldb"):get_install_path()
local codelldb = package_path .. "/extension/adapter/codelldb"
local library_path = package_path .. "/extension/lldb/lib/liblldb.dylib"
local uname = io.popen("uname"):read("*l")
if uname == "Linux" then
library_path = package_path .. "/extension/lldb/lib/liblldb.so"
end
opts.dap = {
adapter = require("rustaceanvim.config").get_codelldb_adapter(codelldb, library_path),
}
vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {})
if vim.fn.executable("rust-analyzer") == 0 then
LazyVim.error(
Expand All @@ -95,6 +122,9 @@ return {
"neovim/nvim-lspconfig",
opts = {
servers = {
bacon_ls = {
enabled = diagnostics == "bacon-ls",
},
rust_analyzer = { enabled = false },
},
},
Expand Down

0 comments on commit af186c4

Please sign in to comment.