Configure tabSize in jsonls

Hi there,

Apologies if this is a dumb question, but I am using nvim-lspconfig to configure the json language server (jsonls). Contrary to the documentation, it seems like autoformatting is enabled by default, so on save my entire .json file gets reformatted which is great.
However, my work requires 4 space indentation and it formats with 2 spaces. I have trawled what documentation I can find online and cannot find any way to change this to 4 spaces. Is this possible?

Alternatively I will turn off formatting with jsonls and revert to using prettier.

Regards
Simon

1 Like

Autoformmatting is not enabled by default. You must have something on your configuration that does.

:help vim.lsp.buf.range_formatting() specifies some options where you can define what you are looking for. But it also defaults to nvim options for the current options. Like shiftwidth, tabstop so if you set those right it should just work.

Hi there,

Thanks, I managed to fix it in the end. It implied that json formatting only works with range formatting but it definitely works with .formatting() also. I need a better solution but this works for now.

Cheers

1 Like