summaryrefslogtreecommitdiff
path: root/lua/lang/scala.lua
blob: 081c74bfb602ce71337f06f733b88e017eeb8870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local M = {}

M.config = function()
  O.lang.scala = {
    metals = {
      active = false,
      server_version = "0.10.5",
      excluded_packages = {},
      show_implicit_arguments = false,
      show_inferred_type = true,
      status_bar_provider = false,
    },
    formatter = {
      exe = "scalafmt",
      args = { "--stdin" },
      stdin = true,
    },
  }
end

M.format = function()
  O.formatters.filetype["scala"] = {
    function()
      return {
        exe = O.lang.scala.formatter.exe,
        args = O.lang.scala.formatter.args,
        stdin = O.lang.scala.formatter.stdin,
      }
    end,
  }
  O.formatters.filetype["sbt"] = O.formatters.filetype["scala"]
  --  To understand sbt files on stdin, scalafmt needs to assume any old filename
  --  that ends in .sbt.  Using a dummy filename instead of the actual one is
  --  required to support buffers of sbt filetype without the extension.
  O.formatters.filetype["sbt"].args = { "--stdin", "--assume-filename", "foo.sbt" }

  require("formatter.config").set_defaults {
    logging = false,
    filetype = O.formatters.filetype,
  }
end

M.lint = function()
  -- TODO: implement linters (if applicable)
  return "No linters configured!"
end

M.lsp = function()
  -- enable metal server integration
  if O.lang.scala.metals.active then
    vim.g["metals_server_version"] = O.lang.scala.metals.server_version
    -- https://github.com/scalameta/nvim-metals#prerequisites
    vim.opt_global.shortmess:remove("F"):append "c"
    local metals_config = require("metals").bare_config
    metals_config.on_attach = function()
      require("completion").on_attach()
    end
    metals_config.handlers["textDocument/publishDiagnostics"] =
      vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
        virtual_text = {
          prefix = "",
        },
      })
    metals_config.settings = {
      showImplicitArguments = O.lang.scala.metals.show_implicit_arguments,
      showInferredType = O.lang.scala.metals.show_inferred_type,
      excludedPackages = O.lang.scala.metals.excluded_packages,
    }
    metals_config.init_options.statusBarProvider = O.lang.scala.metals.status_bar_provider
    require "lsp"
    require("metals").initialize_or_attach(metals_config)
  end
end

M.dap = function()
  -- TODO: implement dap
  return "No DAP configured!"
end

return M