@@ -324,6 +324,13 @@ M.stop = function(bufnr, filter)
324
324
return clients
325
325
end
326
326
327
+ --- Restart the LSP client.
328
+ --- Fails silently if the buffer's filetype is not one of the filetypes specified in the config.
329
+ --- @return number | nil client_id The LSP client ID after restart
330
+ M .restart = function ()
331
+ return restart ()
332
+ end
333
+
327
334
--- Reload settings for the LSP client.
328
335
--- @param bufnr ? number The buffer number , defaults to the current buffer
329
336
--- @return vim.lsp.Client[] clients A list of clients that will be have their settings reloaded
@@ -367,11 +374,20 @@ M.set_target_arch = function(bufnr, target)
367
374
end )
368
375
end
369
376
370
- --- Restart the LSP client.
371
- --- Fails silently if the buffer's filetype is not one of the filetypes specified in the config.
372
- --- @return number | nil client_id The LSP client ID after restart
373
- M .restart = function ()
374
- return restart ()
377
+ --- @param ra_settings table
378
+ function M .set_config (ra_settings )
379
+ local bufnr = vim .api .nvim_get_current_buf ()
380
+ local clients = rust_analyzer .get_active_rustaceanvim_clients (bufnr )
381
+ --- @cast clients vim.lsp.Client[]
382
+ for _ , client in ipairs (clients ) do
383
+ local settings = get_start_settings (vim .api .nvim_buf_get_name (bufnr ), client .config .root_dir , config .server )
384
+ --- @diagnostic disable-next-line : inject-field
385
+ settings [' rust-analyzer' ] = vim .tbl_deep_extend (' force' , settings [' rust-analyzer' ], ra_settings )
386
+ client .settings = settings
387
+ client :notify (' workspace/didChangeConfiguration' , {
388
+ settings = client .settings ,
389
+ })
390
+ end
375
391
end
376
392
377
393
--- @enum RustAnalyzerCmd
@@ -381,11 +397,12 @@ local RustAnalyzerCmd = {
381
397
restart = ' restart' ,
382
398
reload_settings = ' reloadSettings' ,
383
399
target = ' target' ,
400
+ config = ' config' ,
384
401
}
385
402
386
403
local function rust_analyzer_user_cmd (opts )
387
404
local fargs = opts .fargs
388
- local cmd = fargs [ 1 ]
405
+ local cmd = table.remove ( fargs , 1 )
389
406
--- @cast cmd RustAnalyzerCmd
390
407
if cmd == RustAnalyzerCmd .start then
391
408
M .start ()
@@ -396,8 +413,17 @@ local function rust_analyzer_user_cmd(opts)
396
413
elseif cmd == RustAnalyzerCmd .reload_settings then
397
414
M .reload_settings ()
398
415
elseif cmd == RustAnalyzerCmd .target then
399
- local target_arch = fargs [2 ]
416
+ local target_arch = fargs [1 ]
400
417
M .set_target_arch (nil , target_arch )
418
+ elseif cmd == RustAnalyzerCmd .config then
419
+ local ra_settings_str = vim .iter (fargs ):join (' ' )
420
+ local f = load (' return ' .. ra_settings_str )
421
+ --- @diagnostic disable-next-line : param-type-mismatch
422
+ local ok , ra_settings = pcall (f )
423
+ if not ok or type (ra_settings ) ~= ' table' then
424
+ return vim .notify (' RustAnalyzer config: invalid Lua table.\n ' .. ra_settings_str , vim .log .levels .ERROR )
425
+ end
426
+ M .set_config (ra_settings )
401
427
end
402
428
end
403
429
@@ -407,7 +433,7 @@ vim.api.nvim_create_user_command('RustAnalyzer', rust_analyzer_user_cmd, {
407
433
complete = function (arg_lead , cmdline , _ )
408
434
local clients = rust_analyzer .get_active_rustaceanvim_clients ()
409
435
--- @type RustAnalyzerCmd[]
410
- local commands = # clients == 0 and { ' start' } or { ' stop' , ' restart' , ' reloadSettings' , ' target' }
436
+ local commands = # clients == 0 and { ' start' } or { ' stop' , ' restart' , ' reloadSettings' , ' target' , ' config ' }
411
437
if cmdline :match (' ^RustAnalyzer%s+%w*$' ) then
412
438
return vim .tbl_filter (function (command )
413
439
return command :find (arg_lead ) ~= nil
0 commit comments