Unified: Implement simple LOC counting - #22456
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Balanced
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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
Blockalso 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 thesourceFilerange, so it contributes one line even though there is no code. ExcludeTopLevel.getBody()as well asTopLevelitself.
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() { |
asgerf
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Copied more or less directly from Rust.