diff --git a/docs/codeql/codeql-language-guides/basic-query-for-cpp-code.rst b/docs/codeql/codeql-language-guides/basic-query-for-cpp-code.rst index b49ebf385b1..47a762b4d3e 100644 --- a/docs/codeql/codeql-language-guides/basic-query-for-cpp-code.rst +++ b/docs/codeql/codeql-language-guides/basic-query-for-cpp-code.rst @@ -127,4 +127,4 @@ Further reading .. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-cpp.png -.. |expression| replace:: ``ifstmt`` +.. |result-col-1| replace:: The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs. diff --git a/docs/codeql/codeql-language-guides/basic-query-for-csharp-code.rst b/docs/codeql/codeql-language-guides/basic-query-for-csharp-code.rst index e9a062d9e0f..b8749d1c3f8 100644 --- a/docs/codeql/codeql-language-guides/basic-query-for-csharp-code.rst +++ b/docs/codeql/codeql-language-guides/basic-query-for-csharp-code.rst @@ -131,4 +131,4 @@ Further reading .. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-csharp.png -.. |expression| replace:: ``ifstmt`` \ No newline at end of file +.. |result-col-1| replace:: The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs. diff --git a/docs/codeql/codeql-language-guides/basic-query-for-go-code.rst b/docs/codeql/codeql-language-guides/basic-query-for-go-code.rst index 15ae9caee7d..6280cec234f 100644 --- a/docs/codeql/codeql-language-guides/basic-query-for-go-code.rst +++ b/docs/codeql/codeql-language-guides/basic-query-for-go-code.rst @@ -3,7 +3,9 @@ Basic query for Go code ======================= -Learn to write and run a simple CodeQL query using LGTM. +Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension. + +.. include:: ../reusables/vs-code-basic-instructions/setup-to-run-queries.rst About the query --------------- @@ -22,29 +24,17 @@ This is problematic because the receiver argument is passed by value, not by ref For further information on using methods on values or pointers in Go, see the `Go FAQ `__. -Running the query ------------------ +.. include:: ../reusables/vs-code-basic-instructions/find-database.rst -#. In the main search box on LGTM.com, search for the project you want to query. For tips, see `Searching `__. +Running a quick query +--------------------- -#. Click the project in the search results. +.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst -#. Click **Query this project**. - - This opens the query console. (For information about using this, see `Using the query console `__.) - - .. pull-quote:: - - Note - - Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **Go** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list. - -#. Copy the following query into the text box in the query console: +#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import go``. .. code-block:: ql - import go - from Method m, Variable recv, Write w, Field f where recv = m.getReceiver() and @@ -52,34 +42,17 @@ Running the query not recv.getType() instanceof PointerType select w, "This update to " + f + " has no effect, because " + recv + " is not a pointer." - LGTM checks whether your query compiles and, if all is well, the **Run** button changes to green to indicate that you can go ahead and run the query. +.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst -#. Click **Run**. +.. image:: ../images/codeql-for-visual-studio-code/basic-go-query-results-1.png + :align: center - The name of the project you are querying, and the ID of the most recently analyzed commit to the project, are listed below the query box. To the right of this is an icon that indicates the progress of the query operation: +If any matching code is found, click a link in the ``w`` column to view it in the code viewer. - .. image:: ../images/query-progress.png - :align: center +.. image:: ../images/codeql-for-visual-studio-code/basic-go-query-results-2.png + :align: center - .. pull-quote:: - - Note - - Your query is always run against the most recently analyzed commit to the selected project. - - The query will take a few moments to return results. When the query completes, the results are displayed below the project name. The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to ``w``, which is the location in the source code where the receiver ``recv`` is modified. The second column is the alert message. - - ➤ `Example query results `__ - - .. pull-quote:: - - Note - - An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results. - -#. If any matching code is found, click a link in the ``w`` column to view it in the code viewer. - - The matching ``w`` is highlighted with a yellow background in the code viewer. If any code in the file also matches a query from the standard query library for that language, you will see a red alert message at the appropriate point within the code. +.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst About the query structure ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -144,10 +117,20 @@ To exclude these values: There are now fewer results because value methods that return their receiver variable are no longer reported. -➤ `See this in the query console `__ - Further reading --------------- .. include:: ../reusables/go-further-reading.rst .. include:: ../reusables/codeql-ref-tools-further-reading.rst + +.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions + +.. |language-text| replace:: Go + +.. |language-code| replace:: ``go`` + +.. |example-url| replace:: https://github.com/go-gorm/gorm + +.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-go.png + +.. |result-col-1| replace:: The first column corresponds to ``w``, which is the location in the source code where the receiver ``recv`` is modified. diff --git a/docs/codeql/codeql-language-guides/basic-query-for-java-code.rst b/docs/codeql/codeql-language-guides/basic-query-for-java-code.rst index 90954ad0e2c..a6b0f9ac9fb 100644 --- a/docs/codeql/codeql-language-guides/basic-query-for-java-code.rst +++ b/docs/codeql/codeql-language-guides/basic-query-for-java-code.rst @@ -3,7 +3,9 @@ Basic query for Java and Kotlin code ==================================== -Learn to write and run a simple CodeQL query using LGTM. +Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension. + +.. include:: ../reusables/vs-code-basic-instructions/setup-to-run-queries.rst About the query --------------- diff --git a/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-1.png b/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-1.png new file mode 100644 index 00000000000..65a527b7d44 Binary files /dev/null and b/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-1.png differ diff --git a/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-2.png b/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-2.png new file mode 100644 index 00000000000..619408cf0f0 Binary files /dev/null and b/docs/codeql/images/codeql-for-visual-studio-code/basic-go-query-results-2.png differ diff --git a/docs/codeql/images/codeql-for-visual-studio-code/quick-query-tab-go.png b/docs/codeql/images/codeql-for-visual-studio-code/quick-query-tab-go.png new file mode 100644 index 00000000000..8ea90090ba9 Binary files /dev/null and b/docs/codeql/images/codeql-for-visual-studio-code/quick-query-tab-go.png differ diff --git a/docs/codeql/reusables/vs-code-basic-instructions/run-quick-query-2.rst b/docs/codeql/reusables/vs-code-basic-instructions/run-quick-query-2.rst index 0210c84b156..030fb7b9ef4 100644 --- a/docs/codeql/reusables/vs-code-basic-instructions/run-quick-query-2.rst +++ b/docs/codeql/reusables/vs-code-basic-instructions/run-quick-query-2.rst @@ -4,4 +4,4 @@ The query will take a few moments to return results. When the query completes, the results are displayed in a CodeQL Query Results window, alongside the query window. - The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to the expression |expression| and is linked to the location in the source code of the project where |expression| occurs. The second column is the alert message. \ No newline at end of file + The query results are listed in two columns, corresponding to the expressions in the ``select`` clause of the query. |result-col-1| The second column is the alert message. \ No newline at end of file