scala.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. local M = {}
  2. M.config = function()
  3. O.lang.scala = {
  4. metals = {
  5. active = false,
  6. server_version = "0.10.5",
  7. excluded_packages = {},
  8. show_implicit_arguments = false,
  9. show_inferred_type = true,
  10. status_bar_provider = false,
  11. },
  12. formatter = {
  13. exe = "scalafmt",
  14. args = { "--stdin" },
  15. stdin = true,
  16. },
  17. }
  18. end
  19. M.format = function()
  20. O.formatters.filetype["scala"] = {
  21. function()
  22. return {
  23. exe = O.lang.scala.formatter.exe,
  24. args = O.lang.scala.formatter.args,
  25. stdin = O.lang.scala.formatter.stdin,
  26. }
  27. end,
  28. }
  29. O.formatters.filetype["sbt"] = O.formatters.filetype["scala"]
  30. -- To understand sbt files on stdin, scalafmt needs to assume any old filename
  31. -- that ends in .sbt. Using a dummy filename instead of the actual one is
  32. -- required to support buffers of sbt filetype without the extension.
  33. O.formatters.filetype["sbt"].args = { "--stdin", "--assume-filename", "foo.sbt" }
  34. require("formatter.config").set_defaults {
  35. logging = false,
  36. filetype = O.formatters.filetype,
  37. }
  38. end
  39. M.lint = function()
  40. -- TODO: implement linters (if applicable)
  41. return "No linters configured!"
  42. end
  43. M.lsp = function()
  44. -- enable metal server integration
  45. if O.lang.scala.metals.active then
  46. vim.g["metals_server_version"] = O.lang.scala.metals.server_version
  47. -- https://github.com/scalameta/nvim-metals#prerequisites
  48. vim.opt_global.shortmess:remove("F"):append "c"
  49. local metals_config = require("metals").bare_config
  50. metals_config.on_attach = function()
  51. require("completion").on_attach()
  52. end
  53. metals_config.handlers["textDocument/publishDiagnostics"] =
  54. vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  55. virtual_text = {
  56. prefix = "",
  57. },
  58. })
  59. metals_config.settings = {
  60. showImplicitArguments = O.lang.scala.metals.show_implicit_arguments,
  61. showInferredType = O.lang.scala.metals.show_inferred_type,
  62. excludedPackages = O.lang.scala.metals.excluded_packages,
  63. }
  64. metals_config.init_options.statusBarProvider = O.lang.scala.metals.status_bar_provider
  65. require "lsp"
  66. require("metals").initialize_or_attach(metals_config)
  67. end
  68. end
  69. M.dap = function()
  70. -- TODO: implement dap
  71. return "No DAP configured!"
  72. end
  73. return M