Add rust-analyzer
This commit is contained in:
parent
c9c3b5678e
commit
1ab09ff0dd
2 changed files with 40 additions and 0 deletions
|
@ -7,6 +7,7 @@ require("config.lsp.pyright")
|
||||||
require("config.lsp.clangd")
|
require("config.lsp.clangd")
|
||||||
require("config.lsp.vls")
|
require("config.lsp.vls")
|
||||||
require("config.lsp.lua_ls")
|
require("config.lsp.lua_ls")
|
||||||
|
require("config.lsp.rust_analyzer")
|
||||||
|
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local keymap = vim.keymap.set
|
local keymap = vim.keymap.set
|
||||||
|
|
39
lua/config/lsp/rust_analyzer.lua
Normal file
39
lua/config/lsp/rust_analyzer.lua
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
local bin_name = "rust-analyzer"
|
||||||
|
local cmd = { bin_name }
|
||||||
|
|
||||||
|
local config = vim.fs.find("Cargo.toml", {
|
||||||
|
upward = true,
|
||||||
|
stop = vim.loop.os_homedir(),
|
||||||
|
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
|
||||||
|
})
|
||||||
|
|
||||||
|
if next(config) then
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "rust",
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.start({
|
||||||
|
name = "rust-analyzer",
|
||||||
|
cmd = cmd,
|
||||||
|
root_dir = config[1],
|
||||||
|
settings = {
|
||||||
|
["rust-analyzer"] = {
|
||||||
|
checkOnSave = {
|
||||||
|
command = "clippy"
|
||||||
|
},
|
||||||
|
check = {
|
||||||
|
command = "check"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = vim.lsp.protocol.make_client_capabilities(),
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
pattern = "*.rs",
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format({ timeout_ms = 2000 })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
Loading…
Reference in a new issue