简体   繁体   English

在vim中使用tsconfig.json进行tsc with syntastic

[英]Use tsconfig.json for tsc with syntastic in vim

I want to use the syntastic plugin for vim to give me live error checking while I'm writing typescript files, using tsc . 我想使用vimsyntastic插件在我使用tsc编写打字稿文件时给我实时错误检查。 I already have tsc activated in vim . 我已经在vim激活了tsc Any suggestions for how I could get tsc to use the closest parent's tsconfig.json file as configuration? 有关如何让tsc使用最近的父级tsconfig.json文件作为配置的任何建议? I find that tsc doesn't do so by default, which makes syntastic configuration difficult. 我发现默认情况下tsc没有这样做,这使得syntastic配置变得困难。 Thanks! 谢谢!

EDIT: The reason I think it's not using tsconfig.json is because options like the module resolution method doesn't seem to be working ("require" not defined), and it also isn't catching my definition files as defined in the files attribute in tsconfig.json . 编辑:我认为它不使用tsconfig.json的原因是因为模块解析方法之类的选项似乎不起作用(“require”未定义),并且它也没有捕获文件中定义的定义files tsconfig.json属性。

My failed attempt to solve this: 我尝试解决这个问题失败了:

let g:syntastic_typescript_checks=['tsc', 'tslint']

" typescript: find tsconfig.json
function! FindTypescriptRoot()
    return fnamemodify(findfile('tsconfig.json', './;'), ':h')
endfunction

let g:syntastic_typescript_tsc_args=['-p', FindTypescriptRoot()]

This results in Syntastic spitting out to me this error: 这导致Syntastic吐出给我这个错误:

app.ts|| TS5042: Option 'project' cannot be mixed with source files on a command line.

This is probably because it's running a command like tsc -p /path/to/project/ app.ts , which is an illegal use of that flag... But I don't understand why my settings in tsconfig.json are being ignored by syntastic :( 这可能是因为它正在运行像tsc -p /path/to/project/ app.ts这样的tsc -p /path/to/project/ app.ts ,这是对该标志的非法使用......但是我不明白为什么我的tsconfig.json中的设置被忽略了通过syntastic :(

Summary 摘要

Add let g:syntastic_typescript_tsc_fname = '' to .vimrc . let g:syntastic_typescript_tsc_fname = ''.vimrc

Details 细节

As romainl mentioned in his answer , the "Using tsconfig.json" section of the Typescript wiki states: 正如romainl他的回答中提到的,Typescript wiki的“Using tsconfig.json”部分说明:

By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain. 通过在没有输入文件的情况下调用tsc,在这种情况下,编译器将从当前目录开始搜索tsconfig.json文件并继续向上运行父目录链。

You can do this in Vim using Syntastic by adding the following to your .vimrc , or .vimrc.after if you use Janus , as found in LCD 047 's answer to your Syntastic issue #1628 : 您可以在Vim中使用Syntastic执行此操作,方法是将以下内容添加到.vimrc.vimrc.after如果您使用Janus ,如LCD 047对您的Syntastic问题#1628的回答中所示

let g:syntastic_typescript_tsc_fname = ''

The wiki says: 维基说:

Using tsconfig.json 使用tsconfig.json

  • By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain. 通过在没有输入文件的情况下调用tsc ,在这种情况下,编译器将从当前目录开始搜索tsconfig.json文件并继续向上运行父目录链。

  • By invoking tsc with no input files and a -project (or just -p ) command line option that specifies the path of a directory containing a tsconfig.json file. 通过调用没有输入文件的tsc-project (或只是-p )命令行选项来指定包含tsconfig.json文件的目录的路径。

When input files are specified on the command line, tsconfig.json files are ignored. 在命令行中指定输入文件时,将忽略tsconfig.json文件。

So, basically, you need to find a way to tell Syntastic to not pass the filename to tsc . 所以,基本上,你需要找到一种方法来告诉Syntastic 不要将文件名传递给tsc

I'd suggest using their issue tracker from now on. 我建议从现在开始使用他们的问题跟踪器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM