Skip to content

Commit 458baef

Browse files
committed
Add content on queries panel and language selector
1 parent ed9a0ea commit 458baef

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

docs/codeql/codeql-for-visual-studio-code/analyzing-your-projects.rst

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,46 @@ Downloading a database from GitHub
4242

4343
.. include:: ../reusables/download-github-database.rst
4444

45+
.. _filtering-databases-and-queries-by-language:
46+
47+
Filtering databases and queries by language
48+
-------------------------------------------
49+
50+
Optionally, to see databases containing a specific language, as well as queries written for that language, you can apply a language filter using the language selector.
51+
52+
#. To see available language filters, in the sidebar, click the **Language** title bar.
53+
#. Hover over the language filter you would like to apply, then click **Select**.
54+
55+
.. image:: ../images/codeql-for-visual-studio-code/choose-language-filter.png
56+
:width: 350
57+
:alt: Screenshot of the language selector. The "Select" button for a language filter is outlined in dark orange.
58+
59+
Creating a query
60+
------------------------
61+
62+
You can generate a query template for a specific language from the queries panel, helping you quickly create a custom query.
63+
64+
#. In the sidebar, hover over the **Queries** title bar, then click the **Create query** icon.
65+
66+
.. image:: ../images/codeql-for-visual-studio-code/create-query-icon.png
67+
:width: 350
68+
:alt: Screenshot of the queries panel. The "Create query" icon is outlined in dark orange.
69+
70+
#. In the Command Palette, select the target language for your query. Selecting a language will autogenerate a folder labeled "codeql-custom-queries-LANGUAGE", which will contain a query template labeled "example.ql".
71+
#. In the template file, write your custom query, then save the file. Once your query is finished, you can run it from the queries panel.
72+
4573
Running a query
4674
------------------------
4775

4876
The `CodeQL repository <https://github.com/github/codeql>`__ on GitHub contains lots of example queries.
49-
If you have that folder (or a different CodeQL pack) available in your workspace, you can access existing queries under ``<language>/ql/src/<category>``, for example ``java/ql/src/Likely Bugs``.
77+
You can access any existing queries in your workspace through the queries panel.
78+
79+
#. In the sidebar, to expand the queries panel, click the **Queries** title bar.
80+
#. Hover over the desired query, then click the **Run local query** icon.
5081

51-
#. Open a query (``.ql``) file. It is displayed in the editor, with IntelliSense features such as syntax highlighting and autocomplete suggestions.
52-
#. Right-click in the query window and select **CodeQL: Run Query on Selected Database**. (Alternatively, run the command from the Command Palette.)
82+
.. image:: ../images/codeql-for-visual-studio-code/run-local-query-icon.png
83+
:width: 350
84+
:alt: Screenshot of the mouse pointer hovering over a query in the queries panel. The "Run local query" icon is outlined in dark orange.
5385

5486
The CodeQL extension runs the query on the current database and reports progress in the bottom right corner of the application.
5587
When the results are ready, they're displayed in the Results view.
@@ -61,6 +93,23 @@ For more information, see ":doc:`Troubleshooting CodeQL for Visual Studio Code <
6193
Running multiple queries
6294
--------------------------
6395

96+
Using a couple different methods, you can quickly run multiple queries against your code.
97+
98+
Running all queries in a directory
99+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
101+
You can easily run a directory of queries using the query selector.
102+
103+
#. In the sidebar, to expand the queries panel, click the **Queries** title bar.
104+
#. Hover over the desired directory of queries, then click the **Run local queries** icon.
105+
106+
.. image:: ../images/codeql-for-visual-studio-code/run-local-queries-icon.png
107+
:width: 350
108+
:alt: Screenshot of the mouse pointer hovering over a directory of queries in the queries panel. The "Run local queries" icon is outlined in dark orange.
109+
110+
Running a selection of queries
111+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112+
64113
You can run multiple queries with a single command.
65114

66115
#. Go to the File Explorer.
@@ -114,7 +163,7 @@ This is helpful if you want to test your query on multiple codebases, or find a
114163
Viewing previous queries
115164
--------------------------
116165

117-
To see the queries that you have run in the current session, open the Query History view.
166+
To see the queries that you have run in the current session, open the Query History view. You can filter the Query History view by language. For more information, see ":ref:`Filtering databases and queries by language <filtering-databases-and-queries-by-language>`."
118167

119168
.. image:: ../images/codeql-for-visual-studio-code/query-history.png
120169
:width: 350
60.3 KB
Loading
41 KB
Loading
46.8 KB
Loading
69.2 KB
Loading

0 commit comments

Comments
 (0)