Skip to content

Create AST Viewer for Code QL snippets #476

Closed
@aeisenberg

Description

@aeisenberg

Issue #384 is about a general graph viewer for QL results. This issue is about a specific graph visualization use case for viewing ASTs. The C/C++ PrintAST query returns results as @kind graph. This query will take a root node and return the AST from that root. This is currently only available for C/C++ and a variant is available for Go.

How this feature will be used

  1. Select a file (potentially we will also allow a user to select a function instead)
  2. Invoke the Code QL: View AST command
  3. The extension will run a contextual query and invoke PrintAST for the language of the current database.
  4. In a tree viewer in the QL view, the extension will display the results of this query as a tree. All elements should link back to the source code, as well as link to the QL class that gave rise to it.

Implementation

Building off of the current contextual query implementation, we will build a new contextual query that invokes PrintAST.ql on the selected file. Before this can be implemented, we will need to do the following:

  1. Create a templatized version of the PrintAST.ql so that the selected file can be passed in. See the various implementations of localDefinitions.ql (for example https://github.com/github/codeql/blob/master/javascript/ql/src/localDefinitions.ql).
  2. Refactor definitions.ts so that it can handle contextual queries more generically.
  3. Build the TreeViewer itself
  4. Work with the languages teams so that each language produces its own version of print AST.

Release checklist

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions