diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-10-01 05:39:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-01 05:39:12 -0700 |
| commit | bedb2a0df105f68a624a49b867f269b6d55a2c89 (patch) | |
| tree | 877aa3ef8277575a7ffea1ff8f280eeb69b47489 /lua/lspconfig/server_configurations/rust_analyzer.lua | |
| parent | docs: CONTRIBUTING.md cleanup (diff) | |
| download | nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar.gz nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar.bz2 nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar.lz nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar.xz nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.tar.zst nvim-lspconfig-bedb2a0df105f68a624a49b867f269b6d55a2c89.zip | |
refactor: rename "server_configurations" => "configs" #3330
Problem:
The name `server_configurations` is extremely verbose and irritatingly
formal and dogmatic. This overlong name is a constant nuisance when
reading, writing, and coding.
It's also not even correct: these configurations are just as much
"client" configurations as they are "server" configurations.
Solution:
- Rename to a shorter name.
- Leave placeholder files for any old URLs that link to the old
location.
Diffstat (limited to 'lua/lspconfig/server_configurations/rust_analyzer.lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/rust_analyzer.lua | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/lua/lspconfig/server_configurations/rust_analyzer.lua b/lua/lspconfig/server_configurations/rust_analyzer.lua deleted file mode 100644 index 13a36207..00000000 --- a/lua/lspconfig/server_configurations/rust_analyzer.lua +++ /dev/null @@ -1,122 +0,0 @@ -local util = require 'lspconfig.util' -local async = require 'lspconfig.async' - -local function reload_workspace(bufnr) - bufnr = util.validate_bufnr(bufnr) - local clients = util.get_lsp_clients { bufnr = bufnr, name = 'rust_analyzer' } - for _, client in ipairs(clients) do - vim.notify 'Reloading Cargo Workspace' - client.request('rust-analyzer/reloadWorkspace', nil, function(err) - if err then - error(tostring(err)) - end - vim.notify 'Cargo workspace reloaded' - end, 0) - end -end - -local function is_library(fname) - local user_home = util.path.sanitize(vim.env.HOME) - local cargo_home = os.getenv 'CARGO_HOME' or util.path.join(user_home, '.cargo') - local registry = util.path.join(cargo_home, 'registry', 'src') - local git_registry = util.path.join(cargo_home, 'git', 'checkouts') - - local rustup_home = os.getenv 'RUSTUP_HOME' or util.path.join(user_home, '.rustup') - local toolchains = util.path.join(rustup_home, 'toolchains') - - for _, item in ipairs { toolchains, registry, git_registry } do - if util.path.is_descendant(item, fname) then - local clients = util.get_lsp_clients { name = 'rust_analyzer' } - return #clients > 0 and clients[#clients].config.root_dir or nil - end - end -end - -return { - default_config = { - cmd = { 'rust-analyzer' }, - filetypes = { 'rust' }, - single_file_support = true, - 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 cargo_workspace_root - - if cargo_crate_dir ~= nil then - 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) - - 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 - - return cargo_workspace_root - or cargo_crate_dir - or util.root_pattern 'rust-project.json'(fname) - or util.find_git_ancestor(fname) - end, - capabilities = { - experimental = { - serverStatusNotification = true, - }, - }, - before_init = function(init_params, config) - -- See https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26 - if config.settings and config.settings['rust-analyzer'] then - init_params.initializationOptions = config.settings['rust-analyzer'] - end - end, - }, - commands = { - CargoReload = { - function() - reload_workspace(0) - end, - description = 'Reload current cargo workspace', - }, - }, - docs = { - description = [[ -https://github.com/rust-lang/rust-analyzer - -rust-analyzer (aka rls 2.0), a language server for Rust - - -See [docs](https://github.com/rust-lang/rust-analyzer/blob/master/docs/user/generated_config.adoc) for extra settings. The settings can be used like this: -```lua -require'lspconfig'.rust_analyzer.setup{ - settings = { - ['rust-analyzer'] = { - diagnostics = { - enable = false; - } - } - } -} -``` - -Note: do not set `init_options` for this LS config, it will be automatically populated by the contents of settings["rust-analyzer"] per -https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26. - ]], - default_config = { - root_dir = [[root_pattern("Cargo.toml", "rust-project.json")]], - }, - }, -} |
