Skip to content

Commit

Permalink
fix(rust-analyzer): don't run cargo if Cargo.toml is not found (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitterion authored Nov 19, 2023
1 parent 7384e71 commit 6516abf
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lua/lspconfig/server_configurations/rust_analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,26 @@ return {
end

local cargo_crate_dir = util.root_pattern 'Cargo.toml'(fname)
local cmd = { 'cargo', 'metadata', '--no-deps', '--format-version', '1' }
local cargo_workspace_root

if cargo_crate_dir ~= nil then
cmd[#cmd + 1] = '--manifest-path'
cmd[#cmd + 1] = util.path.join(cargo_crate_dir, 'Cargo.toml')
end
local cmd = {
'cargo',
'metadata',
'--no-deps',
'--format-version',
'1',
'--manifest-path',
util.path.join(cargo_crate_dir, 'Cargo.toml'),
}

local result = async.run_command(cmd)
local cargo_workspace_root
local result = async.run_command(cmd)

if result and result[1] then
result = vim.json.decode(table.concat(result, ''))
if result['workspace_root'] then
cargo_workspace_root = util.path.sanitize(result['workspace_root'])
if result and result[1] then
result = vim.json.decode(table.concat(result, ''))
if result['workspace_root'] then
cargo_workspace_root = util.path.sanitize(result['workspace_root'])
end
end
end

Expand Down

0 comments on commit 6516abf

Please sign in to comment.