rust.lua 3.4 KB

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