Files
LazyVim/lua/lazyvim/plugins/extras/lang/scala.lua
István Donkó 859646f628 feat(scala): add key for worksheet hover (#3853)
## What is this PR for?

Worksheet hovering is a useful feature provided by `metals` to see not
just the end result, but also the entire output of a function call, as
can be seen here for example:
https://youtu.be/Jv9B1crzpWM?t=16m20s

Having a default key assigned not only makes it more convenient, but
also increases discoverability.

(I was also contemplating `<leader>mK` as the mapping to be in line with
`K` for regular hover, but I wasn't convinced that the consistency is
worth the extra keypress.)

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2024-11-08 14:09:17 +01:00

102 lines
2.6 KiB
Lua

return {
recommended = function()
return LazyVim.extras.wants({
ft = "scala",
root = { "build.sbt", "build.sc", "build.gradle", "pom.xml" },
})
end,
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "scala" } },
},
{
"scalameta/nvim-metals",
ft = { "scala", "sbt" },
config = function() end,
},
{
"neovim/nvim-lspconfig",
opts = {
servers = {
metals = {
keys = {
{
"<leader>me",
function()
require("telescope").extensions.metals.commands()
end,
desc = "Metals commands",
},
{
"<leader>mc",
function()
require("metals").compile_cascade()
end,
desc = "Metals compile cascade",
},
{
"<leader>mh",
function()
require("metals").hover_worksheet()
end,
desc = "Metals hover worksheet",
},
},
init_options = {
statusBarProvider = "off",
},
settings = {
showImplicitArguments = true,
excludedPackages = { "akka.actor.typed.javadsl", "com.github.swagger.akka.javadsl" },
},
},
},
setup = {
metals = function(_, opts)
local metals = require("metals")
local metals_config = vim.tbl_deep_extend("force", metals.bare_config(), opts)
metals_config.on_attach = LazyVim.has("nvim-dap") and metals.setup_dap or nil
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt" },
callback = function()
metals.initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
return true
end,
},
},
},
{
"mfussenegger/nvim-dap",
optional = true,
opts = function()
-- Debug settings
local dap = require("dap")
dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "RunOrTest",
metals = {
runType = "runOrTestFile",
--args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example
},
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = {
runType = "testTarget",
},
},
}
end,
},
}