From b3aacb5f59c0a15cfe3e621f068fd87cc37ffac2 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Fri, 1 Jan 2021 19:33:08 -0800 Subject: jsonls: fix range formatting, add command for formatting buffer --- lua/lspconfig/jsonls.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lua') diff --git a/lua/lspconfig/jsonls.lua b/lua/lspconfig/jsonls.lua index 9db3cb7b..3db6b83d 100644 --- a/lua/lspconfig/jsonls.lua +++ b/lua/lspconfig/jsonls.lua @@ -8,6 +8,9 @@ configs[server_name] = { default_config = { cmd = {bin_name, "--stdio"}; filetypes = {"json"}; + init_options = { + provideFormatter = true; + }; root_dir = util.root_pattern(".git", vim.fn.getcwd()); }; docs = { @@ -22,6 +25,20 @@ vscode-json-languageserver, a language server for JSON and JSON schema ```sh npm install -g vscode-json-languageserver ``` + +vscode-json-languageserver only provides range formatting. You can map a command that applies range formatting to the entire document: + +```lua +require'lspconfig'.jsonls.setup { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0}) + end + } + } +} +``` ]]; default_config = { root_dir = [[root_pattern(".git", vim.fn.getcwd())]]; -- cgit v1.2.3-70-g09d2