From 6516abf5ac7d017480c8c8e08c0d24066bcb8d43 Mon Sep 17 00:00:00 2001 From: kitterion Date: Sun, 19 Nov 2023 08:29:48 +0100 Subject: fix(rust-analyzer): don't run cargo if Cargo.toml is not found (#2905) --- .../server_configurations/rust_analyzer.lua | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/rust_analyzer.lua b/lua/lspconfig/server_configurations/rust_analyzer.lua index 656c459d..22575b47 100644 --- a/lua/lspconfig/server_configurations/rust_analyzer.lua +++ b/lua/lspconfig/server_configurations/rust_analyzer.lua @@ -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 -- cgit v1.2.3-70-g09d2