Metals lsp

This commit is contained in:
2026-05-29 14:39:00 +02:00
parent 35505a79a5
commit 8e7bbdd5af
4 changed files with 53 additions and 6 deletions

View File

@ -11,3 +11,4 @@ require("plugins.flash")
require("plugins.git")
require("plugins.conform")
require("plugins.neogen")
require("plugins.metals")

View File

@ -1,6 +1,11 @@
vim.pack.add({ 'https://github.com/neovim/nvim-lspconfig' })
vim.pack.add({ 'https://github.com/j-hui/fidget.nvim' })
require("fidget").setup()
vim.lsp.enable({ 'lua_ls' })
vim.lsp.enable({ 'clangd' })
-- vim.lsp.enable({ 'metals' })
vim.lsp.config("rust_analyzer", {
settings = {
@ -9,12 +14,12 @@ vim.lsp.config("rust_analyzer", {
{
postfix = { enable = true, },
},
check = {
command = "clippy",
},
}
},
}
check = {
command = "clippy",
},
}
},
}
)
vim.lsp.enable('rust_analyzer')

33
lua/plugins/metals.lua Normal file
View File

@ -0,0 +1,33 @@
vim.pack.add({ "https://github.com/scalameta/nvim-metals" })
local metals_config = require("metals").bare_config()
metals_config.capabilities = require("blink.cmp").get_lsp_capabilities()
metals_config.on_attach = function(client, bufnr)
-- Your existing keymaps, scoped to the buffer
local opts = { buffer = bufnr }
vim.keymap.set("n", "<leader>t", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "<leader>sr", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "<leader>gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "<leader>gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("v", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
-- Inlay hints
vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
end
local ft = { "scala", "sbt", "java" }
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = ft,
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})

View File

@ -16,6 +16,10 @@
"rev": "dca1a190aa85f9065979ef35802fb77131911106",
"src": "https://github.com/stevearc/conform.nvim"
},
"fidget.nvim": {
"rev": "82404b196e73a00b1727a91903beef5ddc319d22",
"src": "https://github.com/j-hui/fidget.nvim"
},
"flash.nvim": {
"rev": "fcea7ff883235d9024dc41e638f164a450c14ca2",
"src": "https://github.com/folke/flash.nvim"
@ -64,6 +68,10 @@
"rev": "bedca8b426b2fee0ccac596d167d71bbe971253f",
"src": "https://github.com/neovim/nvim-lspconfig"
},
"nvim-metals": {
"rev": "4cc98f07ec96bb748a8796831767538e0e4f9be4",
"src": "https://github.com/scalameta/nvim-metals"
},
"nvim-treesitter": {
"rev": "4916d6592ede8c07973490d9322f187e07dfefac",
"src": "https://github.com/nvim-treesitter/nvim-treesitter",