rust.lua 3.9 KB

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