rust.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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"}, {"─", "FloatBorder"},
  44. {"╮", "FloatBorder"}, {"│", "FloatBorder"},
  45. {"╯", "FloatBorder"}, {"─", "FloatBorder"},
  46. {"╰", "FloatBorder"}, {"│", "FloatBorder"}
  47. }
  48. }
  49. },
  50. -- all the opts to send to nvim-lspconfig
  51. -- these override the defaults set by rust-tools.nvim
  52. -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
  53. server = {
  54. cmd = {DATA_PATH .. "/lspinstall/rust/rust-analyzer"},
  55. on_attach = require'lsp'.common_on_attach
  56. } -- rust-analyser options
  57. }
  58. require('rust-tools').setup(opts)
  59. else
  60. require'lspconfig'.rust_analyzer.setup {
  61. cmd = {DATA_PATH .. "/lspinstall/rust/rust-analyzer"},
  62. on_attach = require'lsp'.common_on_attach,
  63. filetypes = {"rust"},
  64. root_dir = require'lspconfig.util'.root_pattern("Cargo.toml",
  65. "rust-project.json")
  66. }
  67. end
  68. -- TODO fix these mappings
  69. vim.api.nvim_exec([[
  70. autocmd Filetype rust nnoremap <leader>lm <Cmd>RustExpandMacro<CR>
  71. autocmd Filetype rust nnoremap <leader>lH <Cmd>RustToggleInlayHints<CR>
  72. autocmd Filetype rust nnoremap <leader>le <Cmd>RustRunnables<CR>
  73. autocmd Filetype rust nnoremap <leader>lh <Cmd>RustHoverActions<CR>
  74. ]], true)
  75. if O.lang.rust.autoformat then
  76. require('lv-utils').define_augroups({
  77. _rust_format = {
  78. {'BufWritePre', '*.rs', 'lua vim.lsp.buf.formatting_sync(nil,1000)'}
  79. }
  80. })
  81. end