NeovimConf 2022
Chris Kipp
@ckipp01
Scala Center
require("lspconfig").metals.setup{}
cs install metals
vim.keymap.set("n", "K", vim.lsp.buf.hover)
or handle special
workspace/executeCommands
or complete custom protocols like TVP (Tree View Protocol)
and just allows for smoother integrations with tools like nvim-dap
use({'scalameta/nvim-metals', requires = { "nvim-lua/plenary.nvim" }})
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach({})
end,
group = nvim_metals_group,
})
local metals_config = require("metals").bare_config()
metals_config.on_attach = function(client, bufnr)
require("metals").setup_dap()
end
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
local function initialize_or_attach(config)
config = config or conf.get_config_cache()
if invalid_scala_file() then
return
end
add_commands()
if in_disabled_mode(config) then
conf.set_config_cache(config)
return
end
local current_buf = api.nvim_get_current_buf()
local valid_config = conf.validate_config(config, current_buf)
if valid_config then
lsp.start(valid_config)
end
end
M["metals/publishDecorations"] = function(err, result)
if err then
log.error_and_show(
"Server error while publishing decorations. Please see logs for details."
)
log.error(err.message)
end
local uri = result.uri
local bufnr = vim.uri_to_bufnr(uri)
-- Plus some extra sanity checks in here
decoration.clear(bufnr)
for _, deco in ipairs(result.options) do
decoration.set_decoration(bufnr, deco)
end
end
or handle special
workspace/executeCommands
or handle special
workspace/executeCommands
local function execute_command(command_params, callback)
lsp.buf_request(
0,
"workspace/executeCommand",
command_params,
function(err, result, ctx)
if callback then
callback(err, ctx.method, result)
elseif err then
log.error_and_show(
string.format("Could not execute command: %s", err.message)
)
end
end)
end
or handle special
workspace/executeCommands
M.analyze_stacktrace = function()
local trace = fn.getreg("*")
if trace:len() > 0 then
execute_command(
{ command = "metals.analyze-stacktrace", arguments = { trace } }
)
else
log.warn_and_show("No text found in your register.")
end
end
M.switch_bsp = function()
execute_command({ command = "metals.bsp-switch" })
end
M.connect_build = function()
execute_command({ command = "metals.build-connect" })
end
and just allows for smoother integrations with tools like nvim-dap