astrocommunity icon indicating copy to clipboard operation
astrocommunity copied to clipboard

[Feature] Support bacon lsp in pack-rust

Open chaozwn opened this issue 11 months ago • 4 comments

Is your feature related to a problem?

Refer to Bacon: https://github.com/crisidev/bacon-ls?tab=readme-ov-file#manual Refer to Lazyvim: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/rust.lua

Describe the new feature

Baconls is faster than rust-analyzer in analysis. I hope it can be supported.

Additional context

No response

chaozwn avatar Jan 05 '25 16:01 chaozwn

This shouldnt be added to the rust pack. It can be its own pack if needed

Uzaaft avatar Jan 05 '25 19:01 Uzaaft

Tried to add this to a bacon pack, but didnt get it to work.

Uzaaft avatar Jan 14 '25 14:01 Uzaaft

Tried to add this to a bacon pack, but didnt get it to work.

vim.g.astronvim_rust_diagnostics = "bacon-ls"
local diagnostics = vim.g.astronvim_rust_diagnostics or "rust-analyzer"

return {
{
    "AstroNvim/astrolsp",
    ---@type AstroLSPOpts
    opts = function(_, opts)
     -- add this
      if diagnostics ~= "rust-analyzer" then require("astrocore").list_insert_unique(opts.servers, { "bacon_ls" }) end
      return vim.tbl_deep_extend("force", opts, {
        handlers = {
          rust_analyzer = false,
        },
        ---@diagnostic disable: missing-fields
        config = {
          bacon_ls = {
            init_options = {
              updateOnSave = true,
              updateOnSaveWaitMillis = 1000,
              updateOnChange = false,
            },
          },
          rust_analyzer = {
            settings = {
              ["rust-analyzer"] = {
                cargo = {
                  allFeatures = true,
                  loadOutDirsFromCheck = true,
                  buildScripts = {
                    enable = 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 = {
                    ["async-trait"] = { "async_trait" },
                    ["napi-derive"] = { "napi" },
                    ["async-recursion"] = { "async_recursion" },
                  },
                },
                files = {
                  excludeDirs = {
                    ".direnv",
                    ".git",
                    ".github",
                    ".gitlab",
                    "bin",
                    "node_modules",
                    "target",
                    "venv",
                    ".venv",
                  },
                },
              },
            },
          },
        },
      })
    end,
  },
  {
    "WhoIsSethDaniel/mason-tool-installer.nvim",
    optional = true,
    opts = function(_, opts)
      opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "codelldb" })
      if diagnostics ~= "rust-analyzer" then
        require("astrocore").list_insert_unique(opts.ensure_installed, { "bacon" })
      end
    end,
  }
}

chaozwn avatar Jan 14 '25 14:01 chaozwn

and after open rust project, run in terminal bacon -j bacon-ls.

chaozwn avatar Jan 14 '25 14:01 chaozwn