]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(astro): catch json_decode() error when parsing tsconfig.json
authorChristian Brabandt <cb@256bit.org>
Fri, 29 Aug 2025 16:01:08 +0000 (18:01 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 29 Aug 2025 16:01:08 +0000 (18:01 +0200)
(which is jsonc filetype and there can contain comments)

fixes: #18141

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/ftplugin/astro.vim

index 5d35ba9624c189734ce18d0cfc39c948e1c42332..856b96f23b30cb35c82acbc9e6fee829e89eecc6 100644 (file)
@@ -3,6 +3,7 @@
 " Maintainer:   Romain Lafourcade <romainlafourcade@gmail.com>
 " Last Change:  2024 Apr 21
 "               2024 May 24 by Riley Bruins <ribru17@gmail.com> ('commentstring')
+"               2025 Aug 29 by Vim project, add try/catch around json_decode(), #18141
 
 if exists("b:did_ftplugin")
     finish
@@ -52,13 +53,17 @@ function! s:CollectPathsFromConfig() abort
         endif
     endif
 
-    let paths_from_config = config_json
+    try
+        let paths_from_config = config_json
                 \ ->readfile()
                 \ ->filter({ _, val -> val =~ '^\s*[\[\]{}"0-9]' })
                 \ ->join()
                 \ ->json_decode()
                 \ ->get('compilerOptions', {})
                 \ ->get('paths', {})
+    catch /^Vim\%((\a\+)\)\=:E491:/ " invalid json
+        let paths_from_config = {}
+    endtry
 
     if !empty(paths_from_config)
         let b:astro_paths = paths_from_config