rust.lua 2.9 KB

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