Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
118 lines
3.2 KiB
Lua
118 lines
3.2 KiB
Lua
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
|
|
|
|
local function register_cap()
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities.experimental = {
|
|
serverStatusNotification = true,
|
|
}
|
|
return capabilities
|
|
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 = register_cap(),
|
|
},
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
]],
|
|
default_config = {
|
|
root_dir = [[root_pattern("Cargo.toml", "rust-project.json")]],
|
|
},
|
|
},
|
|
}
|