@@ -566,7 +566,7 @@ return {
566566}
567567```
568568
569- ### Rust ([ rust-tools.nvim ] ( https://github.com/simrat39/rust-tools.nvim ) )
569+ ### Rust ([ rustaceanvim ] ( https://github.com/mrcjkb/rustaceanvim ) )
570570
571571:::tip
572572
@@ -581,19 +581,40 @@ return {
581581
582582:::
583583
584- ``` lua title="lua/plugins/rust-tools .lua"
584+ ``` lua title="lua/plugins/rustaceanvim .lua"
585585return {
586- { " simrat39/rust-tools.nvim" , lazy = true }, -- add lsp plugin
586+ {
587+ ' mrcjkb/rustaceanvim' , -- add lsp plugin
588+ version = ' ^5' ,
589+ lazy = false , -- This plugin is already lazy
590+ opts = function (_ , opts )
591+ local astrolsp_avail , astrolsp = pcall (require , " astrolsp" )
592+ local astrolsp_opts = (astrolsp_avail and astrolsp .lsp_opts " rust_analyzer" ) or {}
593+ local server = {
594+ --- @type table | (fun ( project_root : string | nil , default_settings : table | nil ): table ) -- The rust-analyzer settings or a function that creates them.
595+ settings = function (project_root , default_settings )
596+ local astrolsp_settings = astrolsp_opts .settings or {}
597+
598+ local merge_table = require (" astrocore" ).extend_tbl (default_settings or {}, astrolsp_settings )
599+ local ra = require " rustaceanvim.config.server"
600+ -- load_rust_analyzer_settings merges any found settings with the passed in default settings table and then returns that table
601+ return ra .load_rust_analyzer_settings (project_root , {
602+ settings_file_pattern = " rust-analyzer.json" ,
603+ default_settings = merge_table ,
604+ })
605+ end ,
606+ }
607+ return { server = require (" astrocore" ).extend_tbl (astrolsp_opts , server ) }
608+ end ,
609+ -- configure `rustaceanvim` by setting the `vim.g.rustaceanvim` variable
610+ config = function (_ , opts ) vim .g .rustaceanvim = require (" astrocore" ).extend_tbl (opts , vim .g .rustaceanvim ) end ,
611+
612+ },
587613 {
588614 " AstroNvim/astrolsp" ,
589615 --- @type AstroLSPOpts
590616 opts = {
591- setup_handlers = {
592- -- add custom handler
593- rust_analyzer = function (_ , opts )
594- require (" rust-tools" ).setup ({ server = opts })
595- end ,
596- },
617+ handlers = { rust_analyzer = false }, -- Let rustaceanvim setup `rust_analyzer`
597618 },
598619 },
599620 {
0 commit comments