Skip to content

Unified: Implement simple LOC counting - #22456

Merged
hvitved merged 1 commit into
github:mainfrom
hvitved:unified/loc-count
Aug 28, 2026
Merged

Unified: Implement simple LOC counting#22456
hvitved merged 1 commit into
github:mainfrom
hvitved:unified/loc-count

Conversation

@hvitved

@hvitved hvitved commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Copied more or less directly from Rust.

@hvitved
hvitved marked this pull request as ready for review August 28, 2026 07:36
@hvitved
hvitved requested a review from a team as a code owner August 28, 2026 07:36
@hvitved
hvitved requested review from asgerf and a balanced review from Copilot August 28, 2026 07:36

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.

Copilot review overview

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity unified/​ql/​lib/​codeql/​files/​FileSystem.qll — This new counting behavior has no LOC-specific query test. Please add coverage for ordinary code,…
What changed in this PR

Adds LOC and file-count telemetry for unified-language databases.

Changes:

  • Adds total and extension-specific file/LOC metrics.
  • Implements approximate AST-based LOC counting.
File Description
unified/​ql/​src/​diagnostic/​ExtractorInformation.ql Emits file and LOC telemetry.
unified/​ql/​lib/​codeql/​files/​FileSystem.qll Adds per-file LOC calculation.
Suppressed comments (2)

unified/ql/lib/codeql/files/FileSystem.qll:52

  • The synthetic root Block also needs to be excluded. When a source file has no statements (for example, an empty or comment-only file), this block has no child range and inherits the sourceFile range, so it contributes one line even though there is no code. Exclude TopLevel.getBody() as well as TopLevel itself.
          not node instanceof TopLevel and

unified/ql/lib/codeql/files/FileSystem.qll:55

  • Counting only start lines systematically misses code-only closing-delimiter lines. For example, in a multi-line function or call, no unified AST node starts on the final } or ) line because those punctuation tokens are not represented, while the enclosing node ends there. Use the end line, as the analogous Rust implementation does, so these lines contribute to LOC.
          line = loc.getStartLine() and

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

* is approximate.
*/
overlay[local?]
int getNumberOfLinesOfCode() {
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 28, 2026
@hvitved
hvitved merged commit 3ee0030 into github:main Aug 28, 2026
16 of 17 checks passed
@hvitved
hvitved deleted the unified/loc-count branch August 28, 2026 07:45
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants