Skip to content

Unified: Generate PrintAst helper and implement PrintAst query#22067

Merged
asgerf merged 7 commits into
github:mainfrom
asgerf:unified/printast
Jun 26, 2026
Merged

Unified: Generate PrintAst helper and implement PrintAst query#22067
asgerf merged 7 commits into
github:mainfrom
asgerf:unified/printast

Conversation

@asgerf

@asgerf asgerf commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This changes the tree-sitter extractor to generate a helper predicate for implementing PrintAst for the generated AST.

In unified we then use this to implement PrintAst. The code is deliberately made to follow the conventions from order languages, e.g. it uses the PrintAstConfiguration so the query can be used outside the ide-contextual-query as well.

For Ruby and QL4QL the generated helpers exist aren't currently used because a separate PrintAst implementation exists for the facade AST. I considered disabling the code generation for these languages, but I think a separate PrintAST query for the raw AST could be useful for debugging the desugaring layer, so I decided to just leave it in.

Copilot AI review requested due to automatic review settings June 26, 2026 08:37
@asgerf asgerf requested review from a team as code owners June 26, 2026 08:37
@asgerf asgerf added the no-change-note-required This PR does not need a change note label Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a generated PrintAst “child enumeration” helper for tree-sitter–generated AST libraries and wires it up to a new Unified PrintAst query intended for IDE contextual use (and reuse outside the IDE) via a PrintAstConfiguration.

Changes:

  • Extend the tree-sitter QL generator to emit a PrintAst::getChild(node, name, i) predicate and add QL AST casting support in the generator’s expression model.
  • Add a configurable Unified codeql/unified/printAst library that exposes nodes/edges/graphProperties for a tree graph view.
  • Add an IDE contextual query unified/print-ast that restricts output to the selected source file via a shared getFileBySourceArchiveName helper.
Show a summary per file
File Description
unified/ql/lib/ide-contextual-queries/printAst.ql New IDE contextual query entry point for printing a selected file’s Unified AST.
unified/ql/lib/codeql/unified/printAst.qll New configurable PrintAst “graph” query predicates (nodes, edges, graphProperties) for Unified ASTs.
unified/ql/lib/codeql/unified/Ast.qll Adds generated Unified::PrintAst::getChild mapping AST nodes to named children.
unified/ql/lib/codeql/IDEContextual.qll Adds a shared helper to map VS Code source-archive names to File.
shared/tree-sitter-extractor/src/generator/ql.rs Extends generator AST for QL emission (integer type widened; adds cast expression rendering).
shared/tree-sitter-extractor/src/generator/ql_gen.rs Generates the new PrintAst module and updates integer literal construction.
shared/tree-sitter-extractor/src/generator/mod.rs Ensures the generated QL output includes the new PrintAst module.
ruby/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll Adds generated PrintAst::getChild for Ruby/ERB raw tree-sitter AST.
ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll Adds generated PrintAst::getChild for QL/related raw tree-sitter ASTs.

Review details

  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Low

Comment thread unified/ql/lib/codeql/IDEContextual.qll Dismissed
Comment on lines +14 to +16
/**
* The source file to generate an AST from.
*/
asgerf added 2 commits June 26, 2026 10:48
The previous commit was generated from a wrong checkout

@tausbn tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👍

@asgerf asgerf merged commit b1f60ac into github:main Jun 26, 2026
122 of 124 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note QL-for-QL Ruby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants