Closed delfick closed 1 year ago
on_attach
is called per buffer. If you don't want formatting for a buffer, you can just not call on_attach
.
Something like
lspconfig.pyright.setup {
on_attach = function(client)
if not string.match(vim.api.nvim_buf_get_name(0), "site-packages") then
require("lsp-format").on_attach(client)
end
end,
}
Perfect!
Thank you so much.
For prosperity, I did this
local lsp = require('lsp-zero')
...
lsp.configure("pylsp", lspconfig.pylsp.setup {
on_attach = function(client)
if string.match(vim.api.nvim_buf_get_name(0), "/site-packages/") then
return
end
if string.match(vim.api.nvim_buf_get_name(0), "/lib/python") then
return
end
require("lsp-format").on_attach(client)
end,
settings = {
pylsp = {
plugins = {
noy_pyls = { enabled = true },
pydocstyle = { enabled = false },
pycodestyle = { enabled = false },
pyflakes = { enabled = false },
mccabe = { enabled = false },
pylint = { enabled = false },
yapf = { enabled = false },
pyls_isort = { enabled = false },
black = { enabled = true, line_length = 100 },
pylsp_mypy = { enabled = true }
}
}
},
flags = {
debounce_text_changes = 200,
}
})
❤️
Hello,
Is it possible to make it so that it doesn't format certain files. For example anything that matches "/site-packages/" so that I don't end up running the formatter when I've gone into a file inside my python virtualenv?
Thanks