vscode-codeql/extensions/ql-vscode
Henry Mercer 034d8b7c68 Use semver package for version comparison and precedence checking 2020-06-01 22:18:08 +01:00
..
gulpfile.js Use inline-source-map 2020-05-08 11:49:46 -07:00
media Allow download from lgtm 2020-05-28 11:53:41 -07:00
src Use semver package for version comparison and precedence checking 2020-06-01 22:18:08 +01:00
syntaxes Highlight `unique` as a keyword 2020-04-14 12:48:18 -04:00
test Fix syntax error in ql library 2020-05-26 12:01:22 -07:00
.eslintrc.js Add semi-colon linting 2020-05-13 12:06:53 -07:00
.vscodeignore CodeQL for VS Code: Initial commit. 2019-11-13 12:23:53 -08:00
CHANGELOG.md Update CHANGELOG for release 2020-05-29 13:32:29 -04:00
README.md Update link to lgtm to go to the explore section 2020-05-29 10:29:04 -07:00
language-configuration.json Add onEnterRules for language config 2020-05-26 11:39:57 -07:00
package.json Use semver package for version comparison and precedence checking 2020-06-01 22:18:08 +01:00
tsconfig.json chore: Introduce eslint 2020-03-17 09:14:02 -07:00

README.md

CodeQL extension for Visual Studio Code

This project is an extension for Visual Studio Code that adds rich language support for CodeQL and allows you to easily find problems in codebases. In particular, the extension:

  • Enables you to use CodeQL to query databases generated from source code.
  • Shows the flow of data through the results of path queries, which is essential for triaging security results.
  • Provides an easy way to run queries from the large, open source repository of CodeQL security queries.
  • Adds IntelliSense to support you writing and editing your own CodeQL query and library files.

To see what has changed in the last few versions of the extension, see the Changelog.

Quick start overview

The information in this README file describes the quickest way to start using CodeQL. For information about other configurations, see the separate CodeQL help.

Quick start: Installing and configuring the extension

  1. Install the extension.
  2. Check access to the CodeQL CLI.
  3. Clone the CodeQL starter workspace.

Quick start: Using CodeQL

  1. Import a database from LGTM.
  2. Run a query.

Quick start: Installing and configuring the extension

Installing the extension

The CodeQL extension requires a minimum of Visual Studio Code 1.39. Older versions are not supported.

  1. Install and open Visual Studio Code.
  2. Open the Extensions view (press Ctrl+Shift+X or Cmd+Shift+X).
  3. At the top of the Extensions view, type CodeQL in the box labeled Search Extensions in Marketplace.
  4. Locate the CodeQL extension and select Install. This will install the extension from the Visual Studio Marketplace.

Checking access to the CodeQL CLI

The extension uses the CodeQL CLI to compile and run queries. The extension automatically manages access to the CLI for you by default (recommended). To check for updates to the CodeQL CLI, you can use the CodeQL: Check for CLI Updates command.

If you want to override the default behavior and use a CodeQL CLI that's already on your machine, see Configuring access to the CodeQL CLI.

If you have any difficulty with CodeQL CLI access, see the CodeQL Extension Log in the Output view for any error messages.

Cloning the CodeQL starter workspace

When you're working with CodeQL, you need access to the standard CodeQL libraries and queries. Initially, we recommend that you clone and use the ready-to-use starter workspace. This includes libraries and queries for the main supported languages, with folders set up ready for your custom queries. After cloning the workspace (use git clone --recursive), you can use it in the same way as any other VS Code workspace—with the added advantage that you can easily update the CodeQL libraries.

For information about configuring an existing workspace for CodeQL, see the documentation.

Upgrading CodeQL standard libraries

You can easily keep up-to-date with the latest changes to the CodeQL standard libraries.

If you're using the CodeQL starter workspace, you can pull in the latest standard libraries by running:

git pull
git submodule update --recursive

in the starter workspace directory.

If you're using your own clone of the CodeQL standard libraries, you can do a git pull from where you have the libraries checked out.

Quick start: Using CodeQL

You can find all the commands contributed by the extension in the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) by typing CodeQL, many of them are also accessible through the interface, and via keyboard shortcuts.

Importing a database from LGTM

While you can use the CodeQL CLI to create your own databases, the simplest way to start is by downloading a database from LGTM.com.

  1. Open LGTM.com in your browser.
  2. Search for a project you're interested in, for example Apache Kafka.
  3. Copy the link to that project, for example https://lgtm.com/projects/g/apache/kafka.
  4. In VS Code, open the Command Palette and choose the CodeQL: Download Database from LGTM command.
  5. Paste the link you copied earlier.
  6. Select the language for the database you want to download (only required if the project has databases for multiple languages).
  7. Once the CodeQL database has been imported, it is displayed in the Databases view.

Running a query

The instructions below assume that you're using the CodeQL starter workspace, or that you've added the CodeQL libraries and queries repository to your workspace.

  1. Expand the ql folder and locate a query to run. The standard queries are grouped by target language and then type, for example: ql/java/ql/src/Likely Bugs.
  2. Open a query (.ql) file.
  3. Right-click in the query window and select CodeQL: Run Query. Alternatively, open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P), type Run Query, then select CodeQL: Run Query.

The CodeQL extension runs the query on the current database using the CLI and reports progress in the bottom right corner of the application. When the results are ready, they're displayed in the CodeQL Query Results view. Use the dropdown menu to choose between different forms of result output.

If there are any problems running a query, a notification is displayed in the bottom right corner of the application. In addition to the error message, the notification includes details of how to fix the problem.

What next?

For more information about the CodeQL extension, see the documentation. Otherwise, you could:

License

The CodeQL extension for Visual Studio Code is licensed under the MIT License. The version of CodeQL used by the CodeQL extension is subject to the GitHub CodeQL Terms & Conditions.