-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pack): Add Scala language pack (#501)
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} |