How to use null-ls formatter by default #244
-
Hi , im unable to make null-ls formatting work by default for tsserver ( :lua vim.lsp.buf.formatting() ) It prompts me this message : I tried disabling the tsserver and it worked if I ran the vim.lsp.buf.formatting command manually but my keybind for formatting didnt work
The keybind does work for other languages |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Assuming local lspconfig = require("lspconfig")
local null_ls = require("null-ls")
lspconfig.tsserver.setup({
on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>fm", "<cmd>lua vim.lsp.buf.formatting()<CR>", {})
end,
})
null_ls.config({
debug = true,
sources = { null_ls.builtins.formatting.prettier },
})
lspconfig["null-ls"].setup({}) On my end, this makes formatting default to null-ls for |
Beta Was this translation helpful? Give feedback.
-
yea that works! thanks :) |
Beta Was this translation helpful? Give feedback.
-
I'd just like to add for reference that |
Beta Was this translation helpful? Give feedback.
-
besides what @benjamineskola said, so the command would look like |
Beta Was this translation helpful? Give feedback.
Assuming
buf_set_keymap
is just a wrapper forvim.api.nvim_buf_set_keymap
, your keybind is working fine on my end with the following minimal configuration (loaded directly ininit.lua
after setting up plugins):On my end, this makes formatting de…