Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup LSP for Rust #370

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lua/config/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,32 @@ if utils.executable("lua-language-server") then
}
end

-- settings for rust-analyzer is copied from https://rust-analyzer.github.io/manual.html#nvim-lsp
if utils.executable("rust-analyzer") then
lspconfig.rust_analyzer.setup {
on_attach = custom_attach,
settings = {
['rust-analyzer'] = {
imports = {
granularity = {
group = "module",
},
prefix = "self",
},
cargo = {
buildScripts = {
enable = true,
},
},
procMacro = {
enable = true
},
},
},
capabilities = capabilities,
}
end

-- Change diagnostic signs.
fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" })
fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" })
Expand Down
7 changes: 7 additions & 0 deletions lua/custom-autocmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ api.nvim_create_autocmd({ "BufWritePre" }, {
end,
})

api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = {"*.c", "*.cc", "*.cpp", "*.h", "*.rs", "*.py"},
callback = function()
vim.lsp.buf.format { asnyc = false }
end,
})

-- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410.
-- It seems that `checktime` does not work in command line. We need to check if we are in command
-- line before executing this command, see also https://vi.stackexchange.com/a/20397/15292 .
Expand Down