rust.lua 3.1 KB

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