Skip to content

Instantly share code, notes, and snippets.

@grncdr
Created March 6, 2016 09:17
Show Gist options
  • Save grncdr/0760c5452099bd7b983c to your computer and use it in GitHub Desktop.
Save grncdr/0760c5452099bd7b983c to your computer and use it in GitHub Desktop.
Load tsconfig.json and add extra syntastic args if found
function! LoadTsConfig()
let search_depth = 20
let dirname = fnamemodify(expand('%'), ":p:h")
while search_depth > 0 && dirname != "/"
let search_depth = search_depth - 1
let filename = dirname . "/tsconfig.json"
" while filename
if filereadable(filename)
let b:tsconfig_path = filename
let tsconfig = jsondecode(join(readfile(filename)))
if has_key(tsconfig, "compilerOptions")
let extra_args = ""
for [key, val] in items(tsconfig.compilerOptions)
if match(key, "^out") >= 0
continue
endif
let extra_args = extra_args . " --" . key
let val = tsconfig.compilerOptions[key]
if type(val) != 6 " booleans are represented simply by being present
let extra_args = extra_args . " " . val
end
endfor
let b:syntastic_typescript_tsc_args = extra_args
endif
break
endif
let dirname = fnamemodify(dirname . "/..", ":p:h")
endwhile
endfunction
au BufEnter *.ts call LoadTsConfig()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment