rust.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. if O.lang.rust.rust_tools.active then
  2. local opts = {
  3. tools = { -- rust-tools options
  4. -- automatically set inlay hints (type hints)
  5. -- There is an issue due to which the hints are not applied on the first
  6. -- opened file. For now, write to the file to trigger a reapplication of
  7. -- the hints or just run :RustSetInlayHints.
  8. -- default: true
  9. autoSetHints = true,
  10. -- whether to show hover actions inside the hover window
  11. -- this overrides the default hover handler
  12. -- default: true
  13. hover_with_actions = true,
  14. runnables = {
  15. -- whether to use telescope for selection menu or not
  16. -- default: true
  17. use_telescope = true,
  18. -- rest of the opts are forwarded to telescope
  19. },
  20. inlay_hints = {
  21. -- wheter to show parameter hints with the inlay hints or not
  22. -- default: true
  23. show_parameter_hints = true,
  24. -- prefix for parameter hints
  25. -- default: "<-"
  26. parameter_hints_prefix = "<-",
  27. -- prefix for all the other hints (type, chaining)
  28. -- default: "=>"
  29. other_hints_prefix = "=>",
  30. -- whether to align to the lenght of the longest line in the file
  31. max_len_align = false,
  32. -- padding from the left if max_len_align is true
  33. max_len_align_padding = 1,
  34. -- whether to align to the extreme right or not
  35. right_align = false,
  36. -- padding from the right if right_align is true
  37. right_align_padding = 7,
  38. },
  39. hover_actions = {
  40. -- the border that is used for the hover window
  41. -- see vim.api.nvim_open_win()
  42. border = {
  43. { "╭", "FloatBorder" },
  44. { "─", "FloatBorder" },
  45. { "╮", "FloatBorder" },
  46. { "│", "FloatBorder" },
  47. { "╯", "FloatBorder" },
  48. { "─", "FloatBorder" },
  49. { "╰", "FloatBorder" },
  50. { "│", "FloatBorder" },
  51. },
  52. },
  53. },
  54. -- all the opts to send to nvim-lspconfig
  55. -- these override the defaults set by rust-tools.nvim
  56. -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
  57. server = {
  58. cmd = { DATA_PATH .. "/lspinstall/rust/rust-analyzer" },
  59. on_attach = require("lsp").common_on_attach,
  60. }, -- rust-analyser options
  61. }
  62. require("rust-tools").setup(opts)
  63. else
  64. require("lspconfig").rust_analyzer.setup {
  65. cmd = { DATA_PATH .. "/lspinstall/rust/rust-analyzer" },
  66. on_attach = require("lsp").common_on_attach,
  67. filetypes = { "rust" },
  68. root_dir = require("lspconfig.util").root_pattern("Cargo.toml", "rust-project.json"),
  69. }
  70. end
  71. -- TODO fix these mappings
  72. vim.api.nvim_exec(
  73. [[
  74. autocmd Filetype rust nnoremap <leader>lm <Cmd>RustExpandMacro<CR>
  75. autocmd Filetype rust nnoremap <leader>lH <Cmd>RustToggleInlayHints<CR>
  76. autocmd Filetype rust nnoremap <leader>le <Cmd>RustRunnables<CR>
  77. autocmd Filetype rust nnoremap <leader>lh <Cmd>RustHoverActions<CR>
  78. ]],
  79. true
  80. )
  81. if O.lang.rust.autoformat then
  82. require("lv-utils").define_augroups {
  83. _rust_format = {
  84. { "BufWritePre", "*.rs", "lua vim.lsp.buf.formatting_sync(nil,1000)" },
  85. },
  86. }
  87. end