rust.lua 974 B

1234567891011121314151617181920212223242526272829303132333435
  1. local common = require("lsp.common-config")
  2. local opts = {
  3. capabilities = common.capabilities,
  4. flags = common.flags,
  5. on_attach = function(client, bufnr)
  6. common.disableFormat(client)
  7. common.keyAttach(bufnr)
  8. end,
  9. settings = {
  10. -- to enable rust-analyzer settings visit:
  11. -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
  12. ["rust-analyzer"] = {
  13. -- enable clippy on save
  14. checkOnSave = {
  15. command = "clippy",
  16. },
  17. },
  18. },
  19. }
  20. return {
  21. on_setup = function(server)
  22. local ok_rt, rust_tools = pcall(require, "rust-tools")
  23. if not ok_rt then
  24. print("Failed to load rust tools, will set up `rust_analyzer` without `rust-tools`.")
  25. server.setup(opts)
  26. else
  27. -- We don't want to call lspconfig.rust_analyzer.setup() when using rust-tools
  28. rust_tools.setup({
  29. server = opts,
  30. dap = require("dap.nvim-dap.config.rust"),
  31. })
  32. end
  33. end,
  34. }