Won't install dap, linters, and formatters
Closed this issue · 3 comments
Here's my minimal init.lua
:
if #vim.api.nvim_list_uis() == 0 then
return
end
require("plugins")
require("lsp")
...
My minimal plugins.lua
local packer = require("packer")
-- Have packer use a popup window
packer.init({
display = {
open_fn = function()
return require("packer.util").float({ border = "rounded" })
end,
},
})
return packer.startup(function(use)
use({ "wbthomason/packer.nvim" })
-- LSP
use({ "neovim/nvim-lspconfig" })
use({ "williamboman/nvim-lsp-installer" })
use({ "jose-elias-alvarez/null-ls.nvim" })
use({ "onsails/lspkind-nvim" })
use({ "tamago324/nlsp-settings.nvim" })
use({ "williamboman/mason.nvim" })
use({ "williamboman/mason-lspconfig.nvim" })
end)
My minimal lsp.lua
:
local mason = require_clean("mason")
local mason_lspconfig = require_clean("mason-lspconfig")
mason.setup({
setup = {
ui = {
border = "rounded",
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
log_level = vim.log.levels.INFO,
max_concurrent_installers = 5,
},
})
local servers = {
"sumneko_lua",
"vimls",
"texlab",
"pylsp",
"bashls",
"clangd",
"cmake",
"html",
"emmet_ls",
"cssls",
"tailwindcss",
"jsonls",
"rust_analyzer",
"solang",
"solc",
"marksman",
"golangci_lint_ls",
"tsserver",
"jdtls",
"yamlls",
}
local ensure_installed = {
"sumneko_lua",
"vimls",
"texlab",
"pylsp",
"bashls",
"clangd",
"cmake",
"html",
"emmet_ls",
"cssls",
"tailwindcss",
"jsonls",
"rust_analyzer",
"solang",
"solc",
"marksman",
"golangci_lint_ls",
"tsserver",
"jdtls",
"yamlls",
"black",
"clang_format",
"latexindent",
"prettier",
"rustfmt",
"sql_formatter",
"standardrb",
"stylua",
"google_java_format",
"shellharden",
"flake8",
"cppcheck",
"write_good",
}
mason_lspconfig.setup({
ensure_installed = ensure_installed,
automatic_installation = true,
})
local lspconfig = require_clean("lspconfig")
for server, _ in pairs(servers) do
lspconfig[server].setup()
end
But mason installs only the servers, not the linters and formatters. I even tried this with the dap servers, but it doesn't work either.
Am I missing something, or is this a bug in the plugin because I've got no idea?
You aren't using mason-tool-installer
anywhere. Was this bug report intended for this repo?
If I assume this was intended for this repo there are a number of problems:
- You aren't using
mason-tool-installer
- You are using
mason-lspconfig
's ensure_installed -- which will only install LSP servers (and will skip over non-LSP servers in your list) - You are using the lspconfig name for each of your LSP servers and not the
mason
name for each server. e.g. lspconfig name:sumneko_lua
,mason
name:lua-language-server
.
For the second point above you can use ensure_installed with mason-lspconfig* if you want, but it's better (at least IMO) to just use
mason-tool-installer` to install everything (see below).
So, let's say you want to use mason-tool-installer
you would change some of your config to:
[...]
require'mason-lspconfig'.setup()
require'mason-tool-installer'.setup({
ensure_installed = {
"lua-language-server",
"vim-language-server",
"texlab",
"python-lsp-server",
"bash-language-server",
"clangd",
"cmake",
"html",
"emmet-ls",
"css-lsp",
"tailwindcss-language-server",
"json-lsp",
"rust-analyzer",
"solang",
"solidity",
"marksman",
"golangci-lint-langserver",
"typescript-language-server",
"jdtls",
"yam-language-server",
"black",
"clang_format",
"latexindent",
"prettier",
"rustfmt",
"sql_formatter",
"standardrb",
"stylua",
"google_java_format",
"shellharden",
"flake8",
"cppcheck",
"write_good",
}
})
[...]
I likely missed a few language servers that have different names. There is a mapping here: https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md that will show the mapping from lspconfig to mason names.
Thank you. I had mason-tool-installer installed, but I configured mason-lsp-config instead. LOL. Anyway, thanks for the solution!
@SingularisArt, as stated by WhoIsSethDaniel mason-tool-installer
works well, If you are looking for an elegant solution, you can check out this example>
Init.lua
-------------------------------------------------
-- Global LSP Servers
vim.api.nvim_set_var("lsp_servers",
{
{
name = 'lua_ls',
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
},
},
},
},
{
name = 'cmake',
settings = {
CMake = {
filetypes = { "cmake", "CMakeLists.txt" }
},
},
},
{
name = 'clangd',
settings = {
clangd = {
-- excludeArgs = { "-stdlib=libc++" }
},
},
},
{
name = 'pyright',
},
}
)
-- Global LSP Linters
vim.api.nvim_set_var("lsp_linters",
{
"luacheck", -- lua
"flake8", -- python
"cpplint", -- C++
}
)
-- Global LSP DAP
vim.api.nvim_set_var("lsp_dap",
{
"debugpy", -- python
"codelldb", -- C++
"cpptools", -- C++
}
)
-- Global LSP Formatters
vim.api.nvim_set_var("lsp_formatters",
{
"luaformatter", -- lua
"black", -- python
"clang-format", -- C++, C
}
)
core/lspconfig.lua
local lsp_servers = vim.api.nvim_get_var('lsp_servers')
-- Convert lsp_servers to a table of strings
local server_names = {}
for _, server in ipairs(lsp_servers) do
table.insert(server_names, server.name)
end
-- Set up mason-lspconfig
require('mason').setup()
require('mason-lspconfig').setup({
ensure_installed = server_names,
})
-- LINTERS | FORMATTERS | DAP
local lsp_linters = vim.api.nvim_get_var('lsp_linters')
local lsp_dap = vim.api.nvim_get_var('lsp_dap')
local lsp_formatters = vim.api.nvim_get_var('lsp_formatters')
local all_lsp_tools = {}
for _, lsp_tool in ipairs(lsp_linters) do
table.insert(all_lsp_tools, lsp_tool)
end
for _, lsp_tool in ipairs(lsp_dap) do
table.insert(all_lsp_tools, lsp_tool)
end
for _, lsp_tool in ipairs(lsp_formatters) do
table.insert(all_lsp_tools, lsp_tool)
end
require('mason-tool-installer').setup (
{
ensure_installed = all_lsp_tools
}
)
-- LINTERS | FORMATTERS | DAP
-- LSP SETUP
local on_attach = function(client,bufnr)
-- Using default Keymaps
end
for _ , lsp in ipairs(lsp_servers) do
require('lspconfig')[lsp.name].setup {
settings = lsp_servers[lsp.settings],
on_attach = on_attach,
}
end
Full config here: rohit-kumar-j/nvim
It provides full control of lsp, formatting, linting, and dap with mason and others fully from within the main init.lua file. Works out of the box with lazy.nvim
and keybindings in Which-key
.
Currently I am actively maintaining it