diff --git a/lua/rustaceanvim/lsp/init.lua b/lua/rustaceanvim/lsp/init.lua index 21be34e0..38a89cae 100644 --- a/lua/rustaceanvim/lsp/init.lua +++ b/lua/rustaceanvim/lsp/init.lua @@ -259,10 +259,7 @@ end ---@return vim.lsp.Client[] clients A list of clients that will be stopped M.stop = function(bufnr, exclude_rustc_target) bufnr = bufnr or vim.api.nvim_get_current_buf() - local clients = rust_analyzer.get_active_rustaceanvim_clients( - bufnr, - { exclude_rustc_target = exclude_rustc_target or DEFAULT_RUSTC_TARGET } - ) + local clients = rust_analyzer.get_active_rustaceanvim_clients(bufnr, { exclude_rustc_target = exclude_rustc_target }) vim.lsp.stop_client(clients) if type(clients) == 'table' then ---@cast clients vim.lsp.Client[] @@ -296,18 +293,19 @@ end ---Updates the target architecture setting for the LSP client associated with the given buffer. ---@param bufnr? number The buffer number, defaults to the current buffer ----@param exclude_rustc_target? string Cargo target triple (e.g., 'x86_64-unknown-linux-gnu') to filter rust-analyzer clients -M.set_target_arch = function(bufnr, exclude_rustc_target) +---@param target? string Cargo target triple (e.g., 'x86_64-unknown-linux-gnu') to filter rust-analyzer clients +M.set_target_arch = function(bufnr, target) + target = target or rustc.DEFAULT_RUSTC_TARGET ---@param client vim.lsp.Client - restart(bufnr, exclude_rustc_target, function(client) + restart(bufnr, target, function(client) rustc.with_rustc_target_architectures(function(rustc_targets) - if rustc_targets[exclude_rustc_target] then - client.settings['rust-analyzer'].cargo.target = exclude_rustc_target + if rustc_targets[target] then + client.settings['rust-analyzer'].cargo.target = target client.notify('workspace/didChangeConfiguration', { settings = client.config.settings }) - vim.notify('Target architecture updated successfully to: ' .. exclude_rustc_target, vim.log.levels.INFO) + vim.notify('Target architecture updated successfully to: ' .. target, vim.log.levels.INFO) return else - vim.notify('Invalid target architecture provided: ' .. tostring(exclude_rustc_target), vim.log.levels.ERROR) + vim.notify('Invalid target architecture provided: ' .. tostring(target), vim.log.levels.ERROR) return end end) diff --git a/lua/rustaceanvim/rust_analyzer.lua b/lua/rustaceanvim/rust_analyzer.lua index 5821deef..219600fa 100644 --- a/lua/rustaceanvim/rust_analyzer.lua +++ b/lua/rustaceanvim/rust_analyzer.lua @@ -1,6 +1,7 @@ ---@mod rustaceanvim.rust_analyzer Functions for interacting with rust-analyzer local os = require('rustaceanvim.os') +local rustc = require('rustaceanvim.rustc') ---@class rustaceanvim.rust-analyzer.ClientAdapter local M = {} @@ -37,7 +38,7 @@ M.get_active_rustaceanvim_clients = function(bufnr, filter) if filter and filter.exclude_rustc_target then clients = vim.tbl_filter(function(client) local cargo_target = vim.tbl_get(client, 'config', 'settings', 'rust-analyzer', 'cargo', 'target') - if filter.exclude_rustc_target == DEFAULT_RUSTC_TARGET and cargo_target == nil then + if filter.exclude_rustc_target == rustc.DEFAULT_RUSTC_TARGET and cargo_target == nil then return false end return cargo_target ~= filter.exclude_rustc_target diff --git a/lua/rustaceanvim/rustc.lua b/lua/rustaceanvim/rustc.lua index f6cc6efc..f9c43e3f 100644 --- a/lua/rustaceanvim/rustc.lua +++ b/lua/rustaceanvim/rustc.lua @@ -2,7 +2,7 @@ local M = {} --- Default target value for rustc when no specific target is provided. --- Used as a fallback to let rustc determine the appropriate target based on the OS. -DEFAULT_RUSTC_TARGET = 'OS' +M.DEFAULT_RUSTC_TARGET = 'OS' ---Local rustc targets cache local rustc_targets_cache = nil