diff options
| author | Raphael <glepnir@neovim.pro> | 2023-06-03 15:08:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-03 15:08:57 +0800 |
| commit | 90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299 (patch) | |
| tree | ce03bcd46b35539ffa1b1e2bd6e9f41e49ac4ad7 /lua | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar.gz nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar.bz2 nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar.lz nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar.xz nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.tar.zst nvim-lspconfig-90f5b0c2d7c5d3deb76b5deb0ecc379023c4f299.zip | |
fix(rust_analyzer): check file is library (#2645)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/rust_analyzer.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lua/lspconfig/server_configurations/rust_analyzer.lua b/lua/lspconfig/server_configurations/rust_analyzer.lua index 6d2ab33d..ea84a07a 100644 --- a/lua/lspconfig/server_configurations/rust_analyzer.lua +++ b/lua/lspconfig/server_configurations/rust_analyzer.lua @@ -48,11 +48,28 @@ local function get_workspace_dir(cmd) return stdout and stdout['workspace_root'] or nil end +local function is_library(fname) + local cargo_home = os.getenv 'CARGO_HOME' or util.path.join(vim.env.HOME, '.cargo') + local registry = util.path.join(cargo_home, 'registry', 'src') + local toolchains = util.path.join(vim.env.HOME, '.rustup', 'toolchains') + for _, item in ipairs { toolchains, registry } do + if fname:sub(1, #item) == item then + local clients = vim.lsp.get_active_clients { name = 'rust_analyzer' } + return clients[#clients].config.root_dir + end + end +end + return { default_config = { cmd = { 'rust-analyzer' }, filetypes = { 'rust' }, root_dir = function(fname) + local reuse_active = is_library(fname) + if reuse_active then + return reuse_active + end + local cargo_crate_dir = util.root_pattern 'Cargo.toml'(fname) local cmd = { 'cargo', 'metadata', '--no-deps', '--format-version', '1' } if cargo_crate_dir ~= nil then |
