I'm using VS Code for TypeScript/JavaScript development. When I open a file it will check that file for errors. The problem is if I'm refactoring (like I move some shared code to a new location or change a name) it won't show me the errors this caused until I open the file with the problem. ...so if I want to do extensive refactoring I have to open every file just to make it scan the file for errors.
我正在使用VS Code进行TypeScript / JavaScript开发。当我打开文件时,它会检查该文件是否有错误。问题是,如果我正在重构(就像我将一些共享代码移动到新位置或更改名称),它将不会显示我导致的错误,直到我打开带有问题的文件。 ...所以如果我想进行大量的重构,我必须打开每个文件只是为了让它扫描文件是否有错误。
How can I make VS Code scan the whole project for errors without having to open each file one by one manually?
如何让VS Code扫描整个项目的错误,而无需手动逐个打开每个文件?
2 个解决方案
#1
7
Figured it out. Note this answer is specific to TypeScript, which is what I am using. Here it is:
弄清楚了。请注意,此答案特定于TypeScript,这是我正在使用的。这里是:
Make sure typescript is installed globally (I just had mine installed locally apparently): npm install -g typescript
确保打字稿全局安装(我刚刚在本地安装了):npm install -g typescript
Then in VS Code press Shift+Ctrl+B. If you don't have a task runner set up it will ask what you want. I selected typescript and the tasks.json file will look like this:
然后在VS Code中按Shift + Ctrl + B.如果您没有设置任务运行器,它将询问您想要什么。我选择了typescript,tasks.json文件将如下所示:
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
Then pressing Shift+Ctrl+B (or Shift+Command+B in macOS) will check the entire project for problems and they will be reported in your "problems" panel.
然后按Shift + Ctrl + B(或macOS中的Shift + Command + B)将检查整个项目是否存在问题,它们将在“问题”面板中报告。
#2
0
If you don't want to install TypeScript globally, you can do the following:
如果您不想全局安装TypeScript,可以执行以下操作:
- Add a validate-typescript run script to
./package.json
.--noEmit
means that the compiler will won't generate any JavaScript files.
将validate-typescript运行脚本添加到./package.json。 --noEmit表示编译器不会生成任何JavaScript文件。
{
"scripts": {
"validate-typescript": "tsc --noEmit"
}
}
- Let VSCode know about the run script in
/.vscode/tasks.json
.
让VSCode知道/.vscode/tasks.json中的运行脚本。
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "validate-typescript",
"problemMatcher": [
"$tsc"
]
}
]
}
- To run the tasks hit the F1 key and select 'Run Task', and then 'npm: validate-typescript'.
要运行任务,请按F1键并选择“运行任务”,然后选择“npm:validate-typescript”。
#1
7
Figured it out. Note this answer is specific to TypeScript, which is what I am using. Here it is:
弄清楚了。请注意,此答案特定于TypeScript,这是我正在使用的。这里是:
Make sure typescript is installed globally (I just had mine installed locally apparently): npm install -g typescript
确保打字稿全局安装(我刚刚在本地安装了):npm install -g typescript
Then in VS Code press Shift+Ctrl+B. If you don't have a task runner set up it will ask what you want. I selected typescript and the tasks.json file will look like this:
然后在VS Code中按Shift + Ctrl + B.如果您没有设置任务运行器,它将询问您想要什么。我选择了typescript,tasks.json文件将如下所示:
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
Then pressing Shift+Ctrl+B (or Shift+Command+B in macOS) will check the entire project for problems and they will be reported in your "problems" panel.
然后按Shift + Ctrl + B(或macOS中的Shift + Command + B)将检查整个项目是否存在问题,它们将在“问题”面板中报告。
#2
0
If you don't want to install TypeScript globally, you can do the following:
如果您不想全局安装TypeScript,可以执行以下操作:
- Add a validate-typescript run script to
./package.json
.--noEmit
means that the compiler will won't generate any JavaScript files.
将validate-typescript运行脚本添加到./package.json。 --noEmit表示编译器不会生成任何JavaScript文件。
{
"scripts": {
"validate-typescript": "tsc --noEmit"
}
}
- Let VSCode know about the run script in
/.vscode/tasks.json
.
让VSCode知道/.vscode/tasks.json中的运行脚本。
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "validate-typescript",
"problemMatcher": [
"$tsc"
]
}
]
}
- To run the tasks hit the F1 key and select 'Run Task', and then 'npm: validate-typescript'.
要运行任务,请按F1键并选择“运行任务”,然后选择“npm:validate-typescript”。