Skip to content

Commit

Permalink
feat(pack): Add Scala language pack (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter authored Aug 4, 2023
1 parent aeecada commit b98fde2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lua/astrocommunity/pack/scala/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Scala Language Pack

Requires:

- `metals` or `coursier` in your path

This plugin pack does the following:

- Adds `scala` treesitter parsers
- Adds `metals` language server
- Adds debugger for scala to `nvim-dap`
- Adds [nvim-metals](https://github.com/scalameta/nvim-metals) for language specific tooling
66 changes: 66 additions & 0 deletions lua/astrocommunity/pack/scala/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
local utils = require "astronvim.utils"

return {
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
if opts.ensure_installed ~= "all" then
opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "scala")
end
end,
},
{
"scalameta/nvim-metals",
init = function()
astronvim.lsp.skip_setup = utils.list_insert_unique(astronvim.lsp.skip_setup, "metals")
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt" },
callback = function()
if vim.fn.executable "metals" ~= 1 and vim.fn.executable "coursier" ~= 1 then
vim.notify "`metals` or `coursier` are required to be installed for `nvim-metals` to work."
return
end

local metals = require "metals"

local user_config = require("astronvim.utils.lsp").config "metals"
local old_on_attach = user_config.on_attach
user_config.on_attach = function(...)
old_on_attach(...)
metals.setup_dap()
end

metals.initialize_or_attach(utils.extend_tbl(metals.bare_config(), user_config))
end,
group = vim.api.nvim_create_augroup("nvim-metals", { clear = true }),
})
end,
},
{
"mfussenegger/nvim-dap",
optional = true,
config = function()
local scala_config = {
{
type = "scala",
request = "launch",
name = "RunOrTest",
metals = {
runType = "runOrTestFile",
},
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = {
runType = "testTarget",
},
},
}
local dap = require "dap"
dap.configurations.scala = dap.configurations.scala and vim.list_extend(dap.configurations.scala, scala_config)
or scala_config
end,
},
}

0 comments on commit b98fde2

Please sign in to comment.