diff options
| author | kitterion <kitterion@users.noreply.github.com> | 2023-11-19 08:29:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 15:29:48 +0800 |
| commit | 6516abf5ac7d017480c8c8e08c0d24066bcb8d43 (patch) | |
| tree | 8a707ccbdc766b98cae826a8c9ff215b0c15ae10 /lua/lspconfig/server_configurations/rust_analyzer.lua | |
| parent | fix: util.root_pattern prioritises pattern order (#2885) (diff) | |
| download | nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar.gz nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar.bz2 nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar.lz nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar.xz nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.tar.zst nvim-lspconfig-6516abf5ac7d017480c8c8e08c0d24066bcb8d43.zip | |
fix(rust-analyzer): don't run cargo if Cargo.toml is not found (#2905)
Diffstat (limited to 'lua/lspconfig/server_configurations/rust_analyzer.lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/rust_analyzer.lua | 27 |
1 files changed, 17 insertions, 10 deletions
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 |
