Add line numbers to file content for accurate code review placement#53
Merged
cosmocoder merged 1 commit intomainfrom Mar 4, 2026
Merged
Add line numbers to file content for accurate code review placement#53cosmocoder merged 1 commit intomainfrom
cosmocoder merged 1 commit intomainfrom
Conversation
- Implemented `addLineNumbers` function to prepend line numbers to source code, enhancing clarity during code reviews. - Updated `rag-analyzer.js` and `prompt-cache.js` to utilize line numbers in displayed content for better reference.
|
🎉 This PR is included in version 1.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
PR review comments were being attached to incorrect line numbers in GitHub PRs. The review body correctly identified the code issue, but the
lineNumbersin the JSON output pointed to wrong locations (e.g., closing brackets instead of the actual problematic code).Root Cause
File content was sent to the LLM as raw code blocks without line number annotations. LLMs cannot reliably count lines in large code blocks (>30-50 lines), causing them to drift and report inaccurate
lineNumbersvalues. The GitHub API posting mechanism was verified to be correct — the issue was exclusively in the LLM-generated line numbers.Changes
addLineNumbers()helper tosrc/utils/string-utils.jsthat prefixes each line with its 1-based number (e.g.,42 | const x = 1;)src/rag-analyzer.js:LINE_NUMBERS_RULEinsrc/prompt-cache.jsto instruct the LLM to read line numbers from the annotated content rather than counting linesaddLineNumbers()covering padding, edge cases, and formatting