Skip to content

Commit

Permalink
fix(rust): preserve loading of rust-analyzer.json (#977)
Browse files Browse the repository at this point in the history
merge astrolsp settings in such a way as to preserve the default behavior
of loading local project settings from rust-analyzer.json
  • Loading branch information
Ryex authored May 19, 2024
1 parent c64ad78 commit 33d4209
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lua/astrocommunity/pack/rust/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,23 @@ return {
end

local astrolsp_avail, astrolsp = pcall(require, "astrolsp")
return { server = astrolsp_avail and astrolsp.lsp_opts "rust_analyzer", dap = { adapter = adapter } }
local astrolsp_opts = (astrolsp_avail and astrolsp.lsp_opts "rust_analyzer") or {}
local server = {
---@type table | (fun(project_root:string|nil, default_settings: table|nil):table) -- The rust-analyzer settings or a function that creates them.
settings = function(project_root, default_settings)
local astrolsp_settings = astrolsp_opts.settings or {}

local merge_table = require("astrocore").extend_tbl(default_settings or {}, astrolsp_settings)
local ra = require "rustaceanvim.config.server"
-- load_rust_analyzer_settings merges any found settings with the passed in default settings table and then returns that table
return ra.load_rust_analyzer_settings(project_root, {
settings_file_pattern = "rust-analyzer.json",
default_settings = merge_table,
})
end,
}
local final_server = require("astrocore").extend_tbl(astrolsp_opts, server)
return { server = final_server, dap = { adapter = adapter } }
end,
config = function(_, opts) vim.g.rustaceanvim = require("astrocore").extend_tbl(opts, vim.g.rustaceanvim) end,
},
Expand Down

0 comments on commit 33d4209

Please sign in to comment.