From b98fde28477a38f18708c9222a0cffa6999f5b2d Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Fri, 4 Aug 2023 17:26:57 -0400 Subject: [PATCH] feat(pack): Add Scala language pack (#501) --- lua/astrocommunity/pack/scala/README.md | 12 +++++ lua/astrocommunity/pack/scala/init.lua | 66 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 lua/astrocommunity/pack/scala/README.md create mode 100644 lua/astrocommunity/pack/scala/init.lua diff --git a/lua/astrocommunity/pack/scala/README.md b/lua/astrocommunity/pack/scala/README.md new file mode 100644 index 000000000..7e796bb21 --- /dev/null +++ b/lua/astrocommunity/pack/scala/README.md @@ -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 diff --git a/lua/astrocommunity/pack/scala/init.lua b/lua/astrocommunity/pack/scala/init.lua new file mode 100644 index 000000000..071c3299e --- /dev/null +++ b/lua/astrocommunity/pack/scala/init.lua @@ -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, + }, +}