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.

Revisions

  1. grncdr created this gist Mar 6, 2016.
    34 changes: 34 additions & 0 deletions typescript.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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()