vim-astro icon indicating copy to clipboard operation
vim-astro copied to clipboard

An error on astro#CollectPathsFromConfig

Open ghost opened this issue 2 years ago β€’ 5 comments

Every time I open an astro file in Nvim with this plugin, I get an error below.

Error opening file: vim/_editor.lua:0: nvim_exec2()..BufReadPost Autocommands for "*.astro"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[19]..script /Users/(my computer name)/.local/share/nvim/lazy/vim-astro/ftplugin/astro.vim[83]..function astro#CollectPathsFromConfig, line 9: Vim(let):E474: Trailing comma: },   }, }

I guess something is going wrong on this line, but I have no idea what to do to fix the error without fixing my tsconfig.json file.

That error happens when my tsconfig.json has to trail commas like this.

{
  "extends": "astro/tsconfigs/strictest",
  "compilerOptions": {
    "paths": {
      "@components/*": ["./src/components/*"],
      "@layouts/*": ["./src/layouts/*"],
    },
  },
}

The reason why I do not want to modify my tsconfig.json is that I do not actually want my prettier or eslint to remove those trailing commas; it is my project's style to do those.

Do you have any solutions for this?

ghost avatar Feb 04 '24 23:02 ghost

When I disabled the formatter and opened the Astro file, the error message was gone, but this is not how I want to fix this problem.

ghost avatar Feb 04 '24 23:02 ghost

First off, I wrote that function with Vim in mind. I haven't tested it in Neovim and don't plan to. There may be differences that I don't know/can't do anything about.

Case in point, the function works correctly in Vim (9.0.1544 and 9.1.0), where :help json_decode() is more tolerant than I would be about trailing commas.

My opinion is that you should format your file correctly.

romainl avatar Apr 19 '24 09:04 romainl

Hey, thank you for your plugin, really appreciate it.

My opinion is that you should format your file correctly.

I think the issue is that the file is formatted correctly. I remember reading somewhere that tsconfig.json is actually a "jsonc" file (or maybe a JSON5 file), which does support trailing commas...

Any chance you could kindly support it so we don't need to create exceptions in prettier for just one file? Thanks a lot

lfilho avatar Aug 15 '24 03:08 lfilho

The core issue is that someone at microsoft decided it would be a good idea to create an underspecified superset of json, jsonc, and keep the .json extension instead of using .jsonc.

The next issue is that Vim's json_decode() seems more relaxed about trailing commas than Neovim's for some reason. This is something that I can't test as I don't use that editor.

The next issue is that there is no jsonc_decode() in vimscript and I'm not aware of an existing implementation. If you can point to such a function somewhere or write it yourself, I'm sure it will be swapped quickly.

FWIW, I'm struggling to get my org to adopt Astro so, despite my interest for it, I actually don't use it at all and I can’t really justify spending the time to write a proper "parser".

romainl avatar Aug 15 '24 07:08 romainl