Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nulls-ls and reformat after save #217

Open
kamalkech opened this issue Aug 28, 2022 · 2 comments
Open

nulls-ls and reformat after save #217

kamalkech opened this issue Aug 28, 2022 · 2 comments

Comments

@kamalkech
Copy link

that my config of null-ls:

local null_ls_status_ok, null_ls = pcall(require, "null-ls")
if not null_ls_status_ok then
  return
end

-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
local formatting = null_ls.builtins.formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
local diagnostics = null_ls.builtins.diagnostics

local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

null_ls.setup({
  debug = false,
  sources = {
    formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }),
    formatting.black.with({ extra_args = { "--fast" } }),
    formatting.stylua,
    -- diagnostics.flake8
  },
  -- you can reuse a shared lspconfig on_attach callback here
  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()
          -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
          vim.lsp.buf.formatting_sync()
        end,
      })
    end
  end,
})

every time save file i should the correct server (capture bellow), question how can i save and nvim know the correct server, mean i don't need every time choose manually the server ??

image

@Alexis12119
Copy link
Contributor

Maybe you can try vim.lsp.buf.formatting_seq_sync() instead of vim.lsp.buf.formatting_sync().

@nichtsam
Copy link

nichtsam commented Oct 1, 2022

I personally turned of sumneok_lua's document_formatting capabilities just like chris did with the tsserver and let stylua do all the work.

However, If you have multiple and every one does something, I think you can do as @Alexis12119 suggested.

Maybe you can try vim.lsp.buf.formatting_seq_sync() instead of vim.lsp.buf.formatting_sync().

you can :help vim.lsp.buf.formatting_seq_sync() to see what it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants