Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio Code check entire project for errors?

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.

How can I make VS Code scan the whole project for errors without having to open each file one by one manually?

like image 936
WillyC Avatar asked Jan 17 '17 16:01

WillyC


People also ask

How do you check for errors in Visual Studio Code?

For a cleaner view of the issues, navigate to the bottom of the build Output window, and click the Error List tab. This takes you to a more organized view of the errors and warnings for your project, and gives you some extra options as well.

How do you search in complete project in VS Code?

VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.

Does VS Code have auto complete?

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

How do I find all the TypeScript errors?

You can add a type-check command in the NPM scripts: "scripts": { "type-check": "tsc", ... }, This runs only the type-checking and will report all errors.


4 Answers

VS Code (v1.44) has an experimental feature, that allows project wide error reporting in TS. Try it out:

// put this line in settings.json
"typescript.tsserver.experimental.enableProjectDiagnostics": true
like image 54
ford04 Avatar answered Oct 16 '22 09:10

ford04


Figured it out. Note this answer is specific to TypeScript, which is what I am using. Here it is:

Make sure typescript is installed globally (I just had mine installed locally apparently): 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:

{
    "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.

like image 25
WillyC Avatar answered Oct 16 '22 09:10

WillyC


For the most recent version of tasks.json this is the correct json, following deprecations in version 1.14. Create this as /.vscode/tasks.json

{
    "version": "2.0.0",
    "command": "tsc",
    "type": "shell",
    "args": [
        "-p",
        "."
    ],
    "presentation": {
        "reveal": "silent"
    },
    "problemMatcher": "$tsc"
}
like image 17
manoftheyear Avatar answered Oct 16 '22 08:10

manoftheyear


If you don't want to install TypeScript globally, you can do the following:

  1. Install TypeScript locally on the project, that is yarn add --dev typescript or npm install --save-dev typescript.

  2. Add a check-types run script to ./package.json. --noEmit means that the compiler will won't generate any JavaScript files.

{
  "scripts": {
    "check-types": "tsc --noEmit"
  }
}
  1. Let VSCode know about the run script in /.vscode/tasks.json.
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "npm",
      "script": "check-types",
      "problemMatcher": [
        "$tsc"
      ]
    }
  ]
}
  1. To run the tasks hit the F1 key and select 'Run Task', and then 'npm: check-types'.

  2. If you add the following lines to the task, pressing Ctrl+B will run it.

    "group": { "kind": "build", "isDefault": true }

like image 15
3 revs Avatar answered Oct 16 '22 08:10

3 revs