My nvim configuration
| 1 | ---@brief |
| 2 | --- |
| 3 | --- https://github.com/hrsh7th/vscode-langservers-extracted |
| 4 | --- |
| 5 | --- vscode-json-language-server, a language server for JSON and JSON schema |
| 6 | --- |
| 7 | --- `vscode-json-language-server` can be installed via `npm`: |
| 8 | --- ```sh |
| 9 | --- npm i -g vscode-langservers-extracted |
| 10 | --- ``` |
| 11 | --- |
| 12 | --- `vscode-json-language-server` only provides completions when snippet support is enabled. If you use Neovim older than v0.10 you need to enable completion, install a snippet plugin and add the following override to your language client capabilities during setup. |
| 13 | --- |
| 14 | --- ```lua |
| 15 | --- --Enable (broadcasting) snippet capability for completion |
| 16 | --- local capabilities = vim.lsp.protocol.make_client_capabilities() |
| 17 | --- capabilities.textDocument.completion.completionItem.snippetSupport = true |
| 18 | --- |
| 19 | --- vim.lsp.config('jsonls', { |
| 20 | --- capabilities = capabilities, |
| 21 | --- }) |
| 22 | --- ``` |
| 23 | |
| 24 | ---@type vim.lsp.Config |
| 25 | return { |
| 26 | cmd = { 'vscode-json-language-server', '--stdio' }, |
| 27 | filetypes = { 'json', 'jsonc' }, |
| 28 | init_options = { |
| 29 | provideFormatter = true, |
| 30 | }, |
| 31 | root_dir = function(bufnr, on_dir) |
| 32 | local fname = vim.api.nvim_buf_get_name(bufnr) |
| 33 | local size = vim.fn.getfsize(fname) |
| 34 | if size > 10 * 1024 then |
| 35 | return |
| 36 | end |
| 37 | on_dir(vim.fs.root(bufnr, { '.git' }) or vim.fn.getcwd()) |
| 38 | end, |
| 39 | } |