Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed get_code_region_around_line() boundary issue #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mou23
Copy link

@mou23 mou23 commented Feb 8, 2025

In the get_code_region_around_line() function, line_no is 1-based, so we need to ensure that the last valid line is included in the output.
If line_no + window_size exceeds len(file_content), the current implementation excludes the last line due to the exclusive nature of range(start, end).
To fix this issue, I added 1 to len(file_content), ensuring that the last line is included.

Additionally, i in range(start, end) is 1-based because start and end are derived from line_no, which follows 1-based indexing.
Without adjusting the index in the else block, using file_content[i] would be off by one, potentially leading to an IndexError or retrieving the wrong lines.
To fix this, I replaced file_content[i] with file_content[i - 1]

@mou23 mou23 force-pushed the fix-code-region-around-line branch from 5caf864 to 478b786 Compare February 8, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant