Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Oct 27, 2024
1 parent 1ea2cc8 commit 350e663
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
20 changes: 9 additions & 11 deletions lua/rustaceanvim/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lua/rustaceanvim/rust_analyzer.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/rustc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 350e663

Please sign in to comment.