Skip to content

Commit 408ba51

Browse files
authored
Merge pull request #14776 from github/sabrowning1/queries-panel-language-selector
Add content for the queries panel and language selector
2 parents 4d4ca6b + d443354 commit 408ba51

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

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

+54-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,47 @@ 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 and 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 custom query
60+
------------------------
61+
62+
You can generate a query template for a specific language from the queries panel, then write your own code to quickly create a custom query.
63+
64+
#. Optionally, to create a custom query in an existing directory, in the sidebar, click the **Queries** title bar to expand the queries panel, then select the desired directory.
65+
#. In the sidebar, hover over the **Queries** title bar, then click the **Create query** icon.
66+
67+
.. image:: ../images/codeql-for-visual-studio-code/create-query-icon.png
68+
:width: 350
69+
:alt: Screenshot of the queries panel. The "Create query" icon is outlined in dark orange.
70+
71+
#. In the Command Palette, select the target language for your query. If you've chosen not to create your custom query in an existing directory, selecting a language will autogenerate a directory labeled ``codeql-custom-queries-<language>``, where ``<language>`` is the name of the selected language. A query template labeled ``example.ql`` will then be added to the existing or autogenerated directory.
72+
#. In the template, write your custom query, then save the file. Once your query is finished, you can run it from the queries panel.
73+
4574
Running a query
4675
------------------------
4776

4877
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``.
78+
You can access any existing queries in your workspace through the queries panel.
79+
80+
#. In the sidebar, to expand the queries panel, click the **Queries** title bar.
81+
#. To run a query against the selected database, hover over the desired query, then click the **Run local query** icon.
5082

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.)
83+
.. image:: ../images/codeql-for-visual-studio-code/run-local-query-icon.png
84+
:width: 350
85+
:alt: Screenshot of the mouse pointer hovering over a query in the queries panel. The "Run local query" icon is outlined in dark orange.
5386

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

97+
You can quickly run multiple queries against the database you've selected using the queries panel or a single command.
98+
99+
Running all queries in a directory
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101+
102+
You can easily run every query in a directory using the queries panel.
103+
104+
#. In the sidebar, to expand the queries panel, click the **Queries** title bar.
105+
#. Hover over the desired directory of queries, then click the **Run local queries** icon.
106+
107+
.. image:: ../images/codeql-for-visual-studio-code/run-local-queries-icon.png
108+
:width: 350
109+
: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.
110+
111+
Running a selection of queries
112+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113+
64114
You can run multiple queries with a single command.
65115

66116
#. Go to the File Explorer.
@@ -122,6 +172,7 @@ To see the queries that you have run in the current session, open the Query Hist
122172

123173
The Query History contains information including the date and time when the query was run, the name of the query, the database on which it was run, and how long it took to run the query.
124174
To customize the information that is displayed, right-click an entry and select **Rename**.
175+
You can also filter the Query History view by language using the language selector. For more information, see ":ref:`Filtering databases and queries by language <filtering-databases-and-queries-by-language>`."
125176

126177
Click an entry to display the corresponding results in the Query Results view, and double-click
127178
to display the query itself in the editor (or right-click and select **View Query**).
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)