Correct way to setup? #274
-
I am migrating from Formatter to null-ls. Here is my current null-ls config: (full init.lua: https://gist.github.com/benfrain/97f2b91087121b2d4ba0dcc4202d252f): -- Setup lspconfig.
require("lspconfig").cssls.setup({
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
})
require("lspconfig").tsserver.setup({
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
})
-- Here is the formatting config
local null_ls = require("null-ls")
local lSsources = {
null_ls.builtins.formatting.prettier.with({
filetypes = {
"javascript","typescript","css","scss","html","json","yaml","markdown","graphql","md","txt",
},
}),
null_ls.builtins.formatting.stylua,
}
null_ls.setup({
sources = lSsources,
})
vim.cmd("autocmd BufWritePost * lua vim.lsp.buf.formatting_seq_sync()") However, while formatting is working, I a have two issues:
What do I need to change in my configuration? I clearly aren't using this tool correctly. Help me Obi Wan... |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 14 replies
-
There's a few things that might be going wrong here. First, make sure you're setting up null-ls using the instructions here, which require two separate steps ( require("lspconfig").tsserver.setup({
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
on_attach = function(client)
client.resolved_capabilities.document_formatting = false
end,
}) I have no idea about the extra diagnostics thing, but are you sure they're coming from null-ls? Nothing in your config should affect diagnostics at all, so could you try commenting out your null-ls setup and see if the issue still pops up? |
Beta Was this translation helpful? Give feedback.
-
Hi @jose-elias-alvarez – thanks for that. The only part of that set up I don't understand is what I need to do with the require("lspconfig")["null-ls"].setup({
on_attach = my_custom_on_attach
}) Do I need the require("lspconfig")["null-ls"].setup({}) I apologise if this is obvious stuff, I'm very new to Lua! BTW – I think the diagostic thing was spurious, removed all caches and reinstalled plugins and it is behaving as expected. That has also fixed the weird formatting of the tags in template literals too. No idea what was going on there. |
Beta Was this translation helpful? Give feedback.
-
Hello! I also have problems configuring this plugin correctly... My configuration formats when saving, but I get the following:
My config: local servers = {'tsserver', 'html', 'cssls'}
local nvim_lsp = require('lspconfig')
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
require'lspconfig'.tsserver.setup{
on_attach = function(client)
client.resolved_capabilities.document_formatting = false
end,
} local null_ls = require("null-ls")
local sources = {
null_ls.builtins.formatting.prettier,
}
null_ls.config({ sources = sources })
-- add to a specific server's on_attach,
-- or to a common on_attach callback to enable for all supported filetypes
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
end
end
require("lspconfig")["null-ls"].setup({
-- see the nvim-lspconfig documentation for available configuration options
on_attach = on_attach
}) |
Beta Was this translation helpful? Give feedback.
-
@jrafaaael It looks like you are setting up |
Beta Was this translation helpful? Give feedback.
-
Is there a way for I know it can be done, but was just wondering if someone else has done it already so that I can make my life a bit easier. Otherwise, I'll go ahead and try to do it myself, but it would be interesting to compare solutions regardless. Thanks everyone! |
Beta Was this translation helpful? Give feedback.
-
Hey Jose, I'm having trouble with the setup because it broke for me a couple of months ago. Reading the docs, your dotfiles and some issues. I have added the Here is a snippet of what my setup lsp.nullLs = function()
local ls = require('null-ls')
local utils = require('utils')
ls.setup({
debug = true,
on_attach = utils.on_attach,
sources = {
ls.builtins.completion.spell,
-- ls.builtins.formatting.stylua,
-- ls.builtins.formatting.eslint,
-- ls.builtins.formatting.prettier,
-- ls.builtins.diagnostics.eslint,
},
})
end
And here is the error I'm getting. |
Beta Was this translation helpful? Give feedback.
There's a few things that might be going wrong here. First, make sure you're setting up null-ls using the instructions here, which require two separate steps (
null_ls.setup
is deprecated). Then, you probably want to turn offtsserver
formatting to avoid conflicts:I have no idea about the extra diagnostics thing, but are you sure they're coming from null-ls? Nothing in your config should affect diagnostics at all, so could you try comme…