Comments in JSON files

Hi all, I have been transitioning from CoC and mostly happy with what I have using native lsp and treesitter.
One thing that is currently an issue for me is comments in a tsconfig.json file.
I get errors all over the place Comments are not permitted in JSON
I know comments are not part of the language spec, but hey tell that to Microsoft. Generating a tsconfig.json creates a json file with comments. I know I could just remove the comments, but IIRC CoC had a option to disable them as I didn’t have the errors all over the place. I’m using vscode-json-language-server which is I believe what CoC used, so is there an option I can pass to the setup function?

require "lspconfig".jsonls.setup {
  cmd = {"vscode-json-language-server", "--stdio"},
  filetypes = {"json", "jsonc"},
  init_options = {
    provideFormatter = false
  },
  root_dir = function()
    return vim.loop.cwd()
  end
}

I also tried renaming the file to .jsonc but I don’t get highlighting in .jsonc files even though I have the jsonc treesitter module installed.
So what are other folk doing?
Is there a way to configure the LS to allow comments?
How do you get highlighting in JSONC?

1 Like

Not sure if you have the vim-jsonc plugin installed that will set json files to jsonc filetype and jsonls should stop complaining in your tsconfig.json file.

1 Like

Thank you! I did not have that installed, that fixes it for me.

1 Like

For reference I found it in the coc.nvim configuration file wiki

1 Like