Format on save not working
Opened this issue · 2 comments
Eshanatnight commented
Hey I adapted this config to the rust config that you posted copy pasted the same content in the correct files, but still it is not formatting on save.
I have checked Mason for clang-format, clangd and codelldb
-- null_ls.lua
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local null_ls = require "null-ls"
local opts = {
sources = {
null_ls.builtins.formatting.clang_format,
},
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds {
group = augroup,
buffer = bufnr,
}
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format { bufnr = bufnr }
end,
})
end
end,
}
return opts
--lspconfig.lua
local base = require "plugins.configs.lspconfig"
local on_attach = base.on_attach
local capabilities = base.capabilities
local lspconfig = require "lspconfig"
lspconfig.clangd.setup {
on_attach = function(client, bufnr)
client.server_capabilities.signatureHelpProvider = false
on_attach(client, bufnr)
end,
capabilities = capabilities,
}
lspconfig.tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
}
lspconfig.efm.setup {
init_options = { documentFormatting = true },
filetypes = { "typescript", "typescriptreact" },
settings = {
rootMarkers = { ".git/" },
languages = {
typescript = {
{
formatCommand = "prettier --stdin-filepath ${INPUT}",
formatStdin = true,
},
},
},
},
}
lspconfig.pyright.setup {
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "python" },
}
-- plugins.lua
-- @type ChadrcPlugins
local plugins = {
-- get mason
{
"williamboman/mason.nvim",
dependencies = {
"WhoIsSethDaniel/mason-tool-installer.nvim",
},
-- options
opts = {
ensure_installed = {
"rust-analyzer",
"clangd",
"clang-format",
"codelldb",
"lua-ls",
"black",
"pyright",
},
},
},
-- neovin lspcofig
{
"neovim/nvim-lspconfig",
config = function()
require "plugins.configs.lspconfig"
require "custom.kellsatnite.configs.lspconfig"
-- require "custom.kellsatnite.configs.formatting"
end,
},
-- rust.vim
{
"rust-lang/rust.vim",
ft = "rust",
init = function()
vim.g.rustfmt_autosave = 1
end,
},
-- rust-tools.nvim
{
"simrat39/rust-tools.nvim",
ft = "rust",
dependencies = "neovim/nvim-lspconfig",
opts = function()
return require "custom.kellsatnite.configs.rust-tools"
end,
config = function(_, opts)
require("rust-tools").setup(opts)
end,
},
-- nvim-dap
{
"mfussenegger/nvim-dap",
config = function(_, _)
require("core.utils").load_mappings "dap"
end,
},
-- crates.nvim
{
"saecki/crates.nvim",
dependencies = "hrsh7th/nvim-cmp",
ft = { "rust", "toml" },
config = function(_, opts)
local crates = require "crates"
crates.setup(opts)
crates.show()
end,
},
-- nvim-cmp
{
"hrsh7th/nvim-cmp",
opts = function()
local M = require "plugins.configs.cmp"
table.insert(M.sources, { name = "crates" })
return M
end,
},
-- null-ls depricated
-- {
-- "jose-elias-alvarez/null-ls.nvim",
-- event = "VeryLazy",
-- opt = function()
-- return require "custom.kellsatnite.configs.null-ls"
-- end,
-- },
{
"nvimtools/none-ls.nvim",
event = "VeryLazy",
opt = function()
return require "custom.kellsatnite.configs.none-ls"
end,
},
-- dap-ui
{
"rcarriga/nvim-dap-ui",
event = "VeryLazy",
dependencies = "mfussenegger/nvim-dap",
config = function()
local dap = require "dap"
local dapui = require "dapui"
dapui.setup()
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
end,
},
-- more mason-nvim-dap
{
"jay-babu/mason-nvim-dap.nvim",
event = "VeryLazy",
dependencies = {
"williamboman/mason.nvim",
"mfussenegger/nvim-dap",
},
opts = {
handlers = {},
},
},
-- copilot ? may switch
{
"zbirenbaum/copilot.lua",
lazy = false,
opts = function()
return require "custom.kellsatnite.configs.copilot"
end,
config = function(_, opts)
require("copilot").setup(opts)
end,
},
-- pretty fold
{
"anuvyklack/pretty-fold.nvim",
lazy = false,
config = function()
require("pretty-fold").setup()
end,
},
-- conform
-- {
-- "stevearc/conform.nvim",
-- lazy = false,
-- -- need to test this out
-- -- event = { "BufReadPre", "BufNewFile" },
-- config = function()
-- require "custom.kellsatnite.configs.formatting"
-- end,
-- },
--
-- nvim-lint
-- {
-- "mfussenegger/nvim-lint",
-- event = { "BufReadPre", "BufNewFile" },
-- lazy = false,
--
-- moved to a different file
-- config = function()
-- local lint = require "lint"
--
-- lint.linters_by_ft = {
-- python = { "pylint" },
-- cpp = { "clangtidy" },
-- }
--
-- local lint_augroup = vim.api.nvim_create_augroup("lint", {
-- clear = true,
-- })
--
-- vim.api.nvim_create_autocmd({
-- "BufEnter",
-- "BufWritePost",
-- }, {
-- group = lint_augroup,
-- callback = function()
-- lint.try_lint()
-- end,
-- })
--
-- vim.keymap.set("n", "<leader>l", function()
-- lint.try_lint()
-- end, {
-- desc = "Trigger Linting",
-- })
-- end,
-- config = function()
-- require("custom.kellsatnite.configs.linting").config()
-- end,
-- },
}
return plugins
Not sure what I did wrong. I even tried to use none-ls
but that had the same result. Help will be appreciated.
me0mar commented
null-ls
is not being maintained anymore. Replace jose-elias-alvarez/null-ls.nvim
with nvimtools/none-ls.nvim
, and you're good to go.
Eshanatnight commented
null-ls
is not being maintained anymore. Replacejose-elias-alvarez/null-ls.nvim
withnvimtools/none-ls.nvim
, and you're good to go.
I tried that too, but still didn't work